Browse Source

replace static action names with objects

master
yggverse 2 months ago
parent
commit
12f5146468
  1. 105
      src/browser.rs
  2. 20
      src/browser/header.rs
  3. 20
      src/browser/header/tray.rs
  4. 42
      src/browser/header/tray/menu.rs

105
src/browser.rs

@ -34,9 +34,23 @@ impl Browser { @@ -34,9 +34,23 @@ impl Browser {
let action_quit = SimpleAction::new("quit", None);
let action_update = SimpleAction::new("update", None);
let action_tab_append = SimpleAction::new("tab_append", None);
let action_tab_close = SimpleAction::new("tab_close", None);
let action_tab_close_all = SimpleAction::new("tab_close_all", None);
let action_tab_page_reload = SimpleAction::new("tab_page_reload", None);
let action_tab_pin = SimpleAction::new("tab_pin", None);
// Init components
// let db = db::Browser::new(connection);
let header = Arc::new(Header::new(&action_debug, &action_quit));
let header = Arc::new(Header::new(
&action_debug,
&action_quit,
&action_tab_append,
&action_tab_close,
&action_tab_close_all,
&action_tab_page_reload,
&action_tab_pin,
));
let main = Arc::new(Main::new(&action_debug, &action_quit, &action_update));
@ -55,16 +69,16 @@ impl Browser { @@ -55,16 +69,16 @@ impl Browser {
// Init events
action_debug.connect_activate({
let target = widget.clone();
let widget = widget.clone();
move |_, _| {
target.emit_enable_debugging(true);
widget.emit_enable_debugging(true);
}
});
action_quit.connect_activate({
let target = widget.clone();
let widget = widget.clone();
move |_, _| {
target.close();
widget.close();
}
});
@ -77,51 +91,42 @@ impl Browser { @@ -77,51 +91,42 @@ impl Browser {
}
});
// Init actions @TODO
widget.add_action_entries([
ActionEntry::builder("tab_append")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_append(None);
}
})
.build(),
ActionEntry::builder("tab_page_reload")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_page_reload();
}
})
.build(),
ActionEntry::builder("tab_close")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_close();
}
})
.build(),
ActionEntry::builder("tab_close_all")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_close_all();
}
})
.build(),
ActionEntry::builder("tab_pin")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_pin();
}
})
.build(),
]);
// Return
action_tab_append.connect_activate({
let main = main.clone();
move |_, _| {
main.tab_append(None);
}
});
action_tab_close.connect_activate({
let main = main.clone();
move |_, _| {
main.tab_close();
}
});
action_tab_close_all.connect_activate({
let main = main.clone();
move |_, _| {
main.tab_close_all();
}
});
action_tab_page_reload.connect_activate({
let main = main.clone();
move |_, _| {
main.tab_page_reload();
}
});
action_tab_pin.connect_activate({
let main = main.clone();
move |_, _| {
main.tab_pin();
}
});
// Return activated browser struct
Self {
// db,
widget,

20
src/browser/header.rs

@ -13,9 +13,25 @@ pub struct Header { @@ -13,9 +13,25 @@ pub struct Header {
impl Header {
// Construct
pub fn new(action_debug: &SimpleAction, action_quit: &SimpleAction) -> Self {
pub fn new(
action_debug: &SimpleAction,
action_quit: &SimpleAction,
action_tab_append: &SimpleAction,
action_tab_close: &SimpleAction,
action_tab_close_all: &SimpleAction,
action_tab_page_reload: &SimpleAction,
action_tab_pin: &SimpleAction,
) -> Self {
// Init components
let tray = Tray::new(action_debug, action_quit);
let tray = Tray::new(
action_debug,
action_quit,
action_tab_append,
action_tab_close,
action_tab_close_all,
action_tab_page_reload,
action_tab_pin,
);
let subject = Subject::new();

20
src/browser/header/tray.rs

@ -12,9 +12,25 @@ pub struct Tray { @@ -12,9 +12,25 @@ pub struct Tray {
}
impl Tray {
pub fn new(action_debug: &SimpleAction, action_quit: &SimpleAction) -> Self {
pub fn new(
action_debug: &SimpleAction,
action_quit: &SimpleAction,
action_tab_append: &SimpleAction,
action_tab_close: &SimpleAction,
action_tab_close_all: &SimpleAction,
action_tab_page_reload: &SimpleAction,
action_tab_pin: &SimpleAction,
) -> Self {
// Init components
let menu = Menu::new(action_debug, action_quit);
let menu = Menu::new(
action_debug,
action_quit,
action_tab_append,
action_tab_close,
action_tab_close_all,
action_tab_page_reload,
action_tab_pin,
);
let tab = Tab::new();
// Init widget

42
src/browser/header/tray/menu.rs

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
use gtk::{
gio::{self, MenuItem, SimpleAction},
gio::{self, SimpleAction},
glib::{gformat, GString},
prelude::ActionExt,
MenuButton,
@ -10,28 +10,45 @@ pub struct Menu { @@ -10,28 +10,45 @@ pub struct Menu {
}
impl Menu {
pub fn new(action_debug: &SimpleAction, action_quit: &SimpleAction) -> Self {
pub fn new(
action_debug: &SimpleAction,
action_quit: &SimpleAction,
action_tab_append: &SimpleAction,
action_tab_close: &SimpleAction,
action_tab_close_all: &SimpleAction,
action_tab_page_reload: &SimpleAction,
action_tab_pin: &SimpleAction,
) -> Self {
// Init model
let model_tab = gio::Menu::new();
model_tab.append(Some("New"), Some("win.tab_append"));
model_tab.append(Some("Pin"), Some("win.tab_pin"));
model_tab.append(Some("New"), Some(&detailed_action_name(action_tab_append)));
model_tab.append(Some("Pin"), Some(&detailed_action_name(action_tab_pin)));
let model_tab_page = gio::Menu::new();
model_tab_page.append(Some("Base"), Some("win.tab_page_base"));
model_tab_page.append(Some("Base"), Some("win.tab_page_base")); // @TODO
let model_tab_page_history = gio::Menu::new();
model_tab_page_history.append(Some("Back"), Some("win.tab_page_history_back"));
model_tab_page_history.append(Some("Forward"), Some("win.tab_page_history_forward"));
model_tab_page_history.append(Some("Back"), Some("win.tab_page_history_back")); // @TODO
model_tab_page_history.append(Some("Forward"), Some("win.tab_page_history_forward")); // @TODO
model_tab_page.append_submenu(Some("History"), &model_tab_page_history);
model_tab_page.append(Some("Reload"), Some("win.tab_page_reload"));
model_tab_page.append(Some("Bookmark"), Some("win.tab_page_bookmark"));
model_tab_page.append(
Some("Reload"),
Some(&detailed_action_name(action_tab_page_reload)),
);
model_tab_page.append(Some("Bookmark"), Some("win.tab_page_bookmark")); // @TODO
model_tab.append_submenu(Some("Page"), &model_tab_page);
let model_tab_close = gio::Menu::new();
model_tab_close.append(Some("Current"), Some("win.tab_close"));
model_tab_close.append(Some("All"), Some("win.tab_close_all"));
model_tab_close.append(
Some("Current"),
Some(&detailed_action_name(action_tab_close)),
);
model_tab_close.append(
Some("All"),
Some(&detailed_action_name(action_tab_close_all)),
);
model_tab.append_submenu(Some("Close"), &model_tab_close);
let model = gio::Menu::new();
@ -56,5 +73,6 @@ impl Menu { @@ -56,5 +73,6 @@ impl Menu {
// Private helpers
fn detailed_action_name(action: &SimpleAction) -> GString {
gformat!("win.{}", action.name()) // @TODO
gformat!("win.{}", action.name()) // @TODO find the way to ident parent group
// without application-wide dependencies import
}

Loading…
Cancel
Save