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

20
src/browser/header.rs

@ -13,9 +13,25 @@ pub struct Header {
impl Header { impl Header {
// Construct // 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 // 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(); let subject = Subject::new();

20
src/browser/header/tray.rs

@ -12,9 +12,25 @@ pub struct Tray {
} }
impl 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 // 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(); let tab = Tab::new();
// Init widget // Init widget

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

@ -1,5 +1,5 @@
use gtk::{ use gtk::{
gio::{self, MenuItem, SimpleAction}, gio::{self, SimpleAction},
glib::{gformat, GString}, glib::{gformat, GString},
prelude::ActionExt, prelude::ActionExt,
MenuButton, MenuButton,
@ -10,28 +10,45 @@ pub struct Menu {
} }
impl 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 // Init model
let model_tab = gio::Menu::new(); let model_tab = gio::Menu::new();
model_tab.append(Some("New"), Some("win.tab_append")); model_tab.append(Some("New"), Some(&detailed_action_name(action_tab_append)));
model_tab.append(Some("Pin"), Some("win.tab_pin")); model_tab.append(Some("Pin"), Some(&detailed_action_name(action_tab_pin)));
let model_tab_page = gio::Menu::new(); 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(); 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("Back"), Some("win.tab_page_history_back")); // @TODO
model_tab_page_history.append(Some("Forward"), Some("win.tab_page_history_forward")); 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_submenu(Some("History"), &model_tab_page_history);
model_tab_page.append(Some("Reload"), Some("win.tab_page_reload")); model_tab_page.append(
model_tab_page.append(Some("Bookmark"), Some("win.tab_page_bookmark")); 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); model_tab.append_submenu(Some("Page"), &model_tab_page);
let model_tab_close = gio::Menu::new(); let model_tab_close = gio::Menu::new();
model_tab_close.append(Some("Current"), Some("win.tab_close")); model_tab_close.append(
model_tab_close.append(Some("All"), Some("win.tab_close_all")); 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); model_tab.append_submenu(Some("Close"), &model_tab_close);
let model = gio::Menu::new(); let model = gio::Menu::new();
@ -56,5 +73,6 @@ impl Menu {
// Private helpers // Private helpers
fn detailed_action_name(action: &SimpleAction) -> GString { 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