From 82219c01b9d4f90b8a15a9745d86ef20f6d7c564 Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 4 Oct 2024 16:19:26 +0300 Subject: [PATCH] move debug menu item to the tool submenu, draft open profile dir action --- src/app.rs | 22 +++++++++++----------- src/app/browser.rs | 17 +++++++++++++---- src/app/browser/header.rs | 6 ++++-- src/app/browser/header/tray.rs | 6 ++++-- src/app/browser/header/tray/menu.rs | 11 +++++++++-- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/app.rs b/src/app.rs index 5dc859c2..b8bc5afd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -34,11 +34,12 @@ impl App { // Init database model let database = match Database::init(profile_database_connection) { Ok(database) => Arc::new(database), - Err(e) => panic!("{e}"), // @TODO + Err(error) => panic!("{error}"), // @TODO }; // Init actions - let action_debug = Action::new("win", true); + let action_tool_debug = Action::new("win", true); + let action_tool_profile_directory = Action::new("win", true); let action_quit = Action::new("win", true); let action_update = Action::new("win", true); let action_tab_append = Action::new("win", true); @@ -56,7 +57,7 @@ impl App { .build(); // Init accels - app.set_accels_for_action(&action_debug.detailed_name(), &["i"]); + app.set_accels_for_action(&action_tool_debug.detailed_name(), &["i"]); app.set_accels_for_action(&action_update.detailed_name(), &["u"]); app.set_accels_for_action(&action_quit.detailed_name(), &["Escape"]); app.set_accels_for_action(&action_tab_append.detailed_name(), &["t"]); @@ -82,7 +83,8 @@ impl App { // Init components let browser = Arc::new(Browser::new( /*db.clone(),*/ - action_debug.simple(), + action_tool_debug.simple(), + action_tool_profile_directory.simple(), action_quit.simple(), action_update.simple(), action_tab_append.simple(), @@ -97,9 +99,9 @@ impl App { // Init events app.connect_activate({ - // let database = database.clone(); let action_update = action_update.simple(); let browser = browser.clone(); + let database = database.clone(); move |this| { // @TODO restore previous session from DB match database.records() { @@ -108,7 +110,7 @@ impl App { println!("{:?}", record.id) // @TODO } } - Err(e) => panic!("{e}"), + Err(error) => panic!("{error}"), // @TODO } // Activate events @@ -123,14 +125,12 @@ impl App { }); // Save current session to DB - // app.connect_window_added() - /* app.connect_window_removed({ let database = database.clone(); move |_, _| { // Cleanup previous record match database.records() { - Ok(_) => { + Ok(records) => { // Delegate clean action to children components // self.browser.clean(app_id) @TODO // .. @@ -138,7 +138,7 @@ impl App { // Create new record match database.add() { Ok(_) => { - // let app_id = self.database.last_insert_id(); + // let app_id = database.last_insert_id(); // Delegate save action to children components // self.browser.save(app_id) @TODO @@ -150,7 +150,7 @@ impl App { Err(error) => panic!("{error}"), // @TODO } } - });*/ + }); // Return activated App struct Self { diff --git a/src/app/browser.rs b/src/app/browser.rs index a041dbe5..eea22e41 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -29,7 +29,8 @@ impl Browser { // Extras // connection: Arc, // Actions - action_debug: Arc, + action_tool_debug: Arc, + action_tool_profile_directory: Arc, action_quit: Arc, action_update: Arc, action_tab_append: Arc, @@ -46,7 +47,8 @@ impl Browser { // Init components let header = Arc::new(Header::new( - action_debug.clone(), + action_tool_debug.clone(), + action_tool_profile_directory.clone(), action_quit.clone(), action_tab_append.clone(), action_tab_close.clone(), @@ -75,7 +77,8 @@ impl Browser { .build(); // Assign actions - widget.add_action(action_debug.as_ref()); + widget.add_action(action_tool_debug.as_ref()); + widget.add_action(action_tool_profile_directory.as_ref()); widget.add_action(action_quit.as_ref()); widget.add_action(action_update.as_ref()); widget.add_action(action_tab_append.as_ref()); @@ -88,13 +91,19 @@ impl Browser { widget.add_action(action_tab_pin.as_ref()); // Init events - action_debug.connect_activate({ + action_tool_debug.connect_activate({ let widget = widget.clone(); move |_, _| { widget.emit_enable_debugging(true); } }); + action_tool_profile_directory.connect_activate({ + move |_, _| { + // @TODO + } + }); + action_quit.connect_activate({ let widget = widget.clone(); move |_, _| { diff --git a/src/app/browser/header.rs b/src/app/browser/header.rs index 20917a5c..e298b782 100644 --- a/src/app/browser/header.rs +++ b/src/app/browser/header.rs @@ -16,7 +16,8 @@ pub struct Header { impl Header { // Construct pub fn new( - action_debug: Arc, + action_tool_debug: Arc, + action_tool_profile_directory: Arc, action_quit: Arc, action_tab_append: Arc, action_tab_close: Arc, @@ -29,7 +30,8 @@ impl Header { ) -> Self { // Init components let tray = Tray::new( - action_debug, + action_tool_debug, + action_tool_profile_directory, action_quit, action_tab_append, action_tab_close, diff --git a/src/app/browser/header/tray.rs b/src/app/browser/header/tray.rs index 8fab490b..60007f32 100644 --- a/src/app/browser/header/tray.rs +++ b/src/app/browser/header/tray.rs @@ -18,7 +18,8 @@ pub struct Tray { impl Tray { pub fn new( - action_debug: Arc, + action_tool_debug: Arc, + action_tool_profile_directory: Arc, action_quit: Arc, action_tab_append: Arc, action_tab_close: Arc, @@ -33,7 +34,8 @@ impl Tray { let tab = Tab::new(action_tab_append.clone()); let menu = Menu::new( - action_debug, + action_tool_debug, + action_tool_profile_directory, action_quit, action_tab_append, action_tab_close, diff --git a/src/app/browser/header/tray/menu.rs b/src/app/browser/header/tray/menu.rs index 1062ba9b..ef7a0666 100644 --- a/src/app/browser/header/tray/menu.rs +++ b/src/app/browser/header/tray/menu.rs @@ -13,7 +13,8 @@ pub struct Menu { #[rustfmt::skip] // @TODO template builder? impl Menu { pub fn new( - action_debug: Arc, + action_tool_debug: Arc, + action_tool_profile_directory: Arc, action_quit: Arc, action_tab_append: Arc, action_tab_close: Arc, @@ -55,7 +56,13 @@ impl Menu { model_tab.append_submenu(Some("Close"), &model_tab_close); model.append_submenu(Some("Tab"), &model_tab); - model.append(Some("Debug"), Some(&detailed_action_name(action_debug))); + + let model_tool = gio::Menu::new(); + model_tool.append(Some("Debug"), Some(&detailed_action_name(action_tool_debug))); + model_tool.append(Some("Profile directory"), Some(&detailed_action_name(action_tool_profile_directory))); + + model.append_submenu(Some("Tool"), &model_tool); + model.append(Some("Quit"), Some(&detailed_action_name(action_quit))); // Init widget