Browse Source

move debug menu item to the tool submenu, draft open profile dir action

master
yggverse 2 months ago
parent
commit
82219c01b9
  1. 22
      src/app.rs
  2. 17
      src/app/browser.rs
  3. 6
      src/app/browser/header.rs
  4. 6
      src/app/browser/header/tray.rs
  5. 11
      src/app/browser/header/tray/menu.rs

22
src/app.rs

@ -34,11 +34,12 @@ impl App {
// Init database model // Init database model
let database = match Database::init(profile_database_connection) { let database = match Database::init(profile_database_connection) {
Ok(database) => Arc::new(database), Ok(database) => Arc::new(database),
Err(e) => panic!("{e}"), // @TODO Err(error) => panic!("{error}"), // @TODO
}; };
// Init actions // 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_quit = Action::new("win", true);
let action_update = Action::new("win", true); let action_update = Action::new("win", true);
let action_tab_append = Action::new("win", true); let action_tab_append = Action::new("win", true);
@ -56,7 +57,7 @@ impl App {
.build(); .build();
// Init accels // Init accels
app.set_accels_for_action(&action_debug.detailed_name(), &["<Primary>i"]); app.set_accels_for_action(&action_tool_debug.detailed_name(), &["<Primary>i"]);
app.set_accels_for_action(&action_update.detailed_name(), &["<Primary>u"]); app.set_accels_for_action(&action_update.detailed_name(), &["<Primary>u"]);
app.set_accels_for_action(&action_quit.detailed_name(), &["<Primary>Escape"]); app.set_accels_for_action(&action_quit.detailed_name(), &["<Primary>Escape"]);
app.set_accels_for_action(&action_tab_append.detailed_name(), &["<Primary>t"]); app.set_accels_for_action(&action_tab_append.detailed_name(), &["<Primary>t"]);
@ -82,7 +83,8 @@ impl App {
// Init components // Init components
let browser = Arc::new(Browser::new( let browser = Arc::new(Browser::new(
/*db.clone(),*/ /*db.clone(),*/
action_debug.simple(), action_tool_debug.simple(),
action_tool_profile_directory.simple(),
action_quit.simple(), action_quit.simple(),
action_update.simple(), action_update.simple(),
action_tab_append.simple(), action_tab_append.simple(),
@ -97,9 +99,9 @@ impl App {
// Init events // Init events
app.connect_activate({ app.connect_activate({
// let database = database.clone();
let action_update = action_update.simple(); let action_update = action_update.simple();
let browser = browser.clone(); let browser = browser.clone();
let database = database.clone();
move |this| { move |this| {
// @TODO restore previous session from DB // @TODO restore previous session from DB
match database.records() { match database.records() {
@ -108,7 +110,7 @@ impl App {
println!("{:?}", record.id) // @TODO println!("{:?}", record.id) // @TODO
} }
} }
Err(e) => panic!("{e}"), Err(error) => panic!("{error}"), // @TODO
} }
// Activate events // Activate events
@ -123,14 +125,12 @@ impl App {
}); });
// Save current session to DB // Save current session to DB
// app.connect_window_added()
/*
app.connect_window_removed({ app.connect_window_removed({
let database = database.clone(); let database = database.clone();
move |_, _| { move |_, _| {
// Cleanup previous record // Cleanup previous record
match database.records() { match database.records() {
Ok(_) => { Ok(records) => {
// Delegate clean action to children components // Delegate clean action to children components
// self.browser.clean(app_id) @TODO // self.browser.clean(app_id) @TODO
// .. // ..
@ -138,7 +138,7 @@ impl App {
// Create new record // Create new record
match database.add() { match database.add() {
Ok(_) => { Ok(_) => {
// let app_id = self.database.last_insert_id(); // let app_id = database.last_insert_id();
// Delegate save action to children components // Delegate save action to children components
// self.browser.save(app_id) @TODO // self.browser.save(app_id) @TODO
@ -150,7 +150,7 @@ impl App {
Err(error) => panic!("{error}"), // @TODO Err(error) => panic!("{error}"), // @TODO
} }
} }
});*/ });
// Return activated App struct // Return activated App struct
Self { Self {

17
src/app/browser.rs

@ -29,7 +29,8 @@ impl Browser {
// Extras // Extras
// connection: Arc<sqlite::Connection>, // connection: Arc<sqlite::Connection>,
// Actions // Actions
action_debug: Arc<SimpleAction>, action_tool_debug: Arc<SimpleAction>,
action_tool_profile_directory: Arc<SimpleAction>,
action_quit: Arc<SimpleAction>, action_quit: Arc<SimpleAction>,
action_update: Arc<SimpleAction>, action_update: Arc<SimpleAction>,
action_tab_append: Arc<SimpleAction>, action_tab_append: Arc<SimpleAction>,
@ -46,7 +47,8 @@ impl Browser {
// Init components // Init components
let header = Arc::new(Header::new( let header = Arc::new(Header::new(
action_debug.clone(), action_tool_debug.clone(),
action_tool_profile_directory.clone(),
action_quit.clone(), action_quit.clone(),
action_tab_append.clone(), action_tab_append.clone(),
action_tab_close.clone(), action_tab_close.clone(),
@ -75,7 +77,8 @@ impl Browser {
.build(); .build();
// Assign actions // 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_quit.as_ref());
widget.add_action(action_update.as_ref()); widget.add_action(action_update.as_ref());
widget.add_action(action_tab_append.as_ref()); widget.add_action(action_tab_append.as_ref());
@ -88,13 +91,19 @@ impl Browser {
widget.add_action(action_tab_pin.as_ref()); widget.add_action(action_tab_pin.as_ref());
// Init events // Init events
action_debug.connect_activate({ action_tool_debug.connect_activate({
let widget = widget.clone(); let widget = widget.clone();
move |_, _| { move |_, _| {
widget.emit_enable_debugging(true); widget.emit_enable_debugging(true);
} }
}); });
action_tool_profile_directory.connect_activate({
move |_, _| {
// @TODO
}
});
action_quit.connect_activate({ action_quit.connect_activate({
let widget = widget.clone(); let widget = widget.clone();
move |_, _| { move |_, _| {

6
src/app/browser/header.rs

@ -16,7 +16,8 @@ pub struct Header {
impl Header { impl Header {
// Construct // Construct
pub fn new( pub fn new(
action_debug: Arc<SimpleAction>, action_tool_debug: Arc<SimpleAction>,
action_tool_profile_directory: Arc<SimpleAction>,
action_quit: Arc<SimpleAction>, action_quit: Arc<SimpleAction>,
action_tab_append: Arc<SimpleAction>, action_tab_append: Arc<SimpleAction>,
action_tab_close: Arc<SimpleAction>, action_tab_close: Arc<SimpleAction>,
@ -29,7 +30,8 @@ impl Header {
) -> Self { ) -> Self {
// Init components // Init components
let tray = Tray::new( let tray = Tray::new(
action_debug, action_tool_debug,
action_tool_profile_directory,
action_quit, action_quit,
action_tab_append, action_tab_append,
action_tab_close, action_tab_close,

6
src/app/browser/header/tray.rs

@ -18,7 +18,8 @@ pub struct Tray {
impl Tray { impl Tray {
pub fn new( pub fn new(
action_debug: Arc<SimpleAction>, action_tool_debug: Arc<SimpleAction>,
action_tool_profile_directory: Arc<SimpleAction>,
action_quit: Arc<SimpleAction>, action_quit: Arc<SimpleAction>,
action_tab_append: Arc<SimpleAction>, action_tab_append: Arc<SimpleAction>,
action_tab_close: Arc<SimpleAction>, action_tab_close: Arc<SimpleAction>,
@ -33,7 +34,8 @@ impl Tray {
let tab = Tab::new(action_tab_append.clone()); let tab = Tab::new(action_tab_append.clone());
let menu = Menu::new( let menu = Menu::new(
action_debug, action_tool_debug,
action_tool_profile_directory,
action_quit, action_quit,
action_tab_append, action_tab_append,
action_tab_close, action_tab_close,

11
src/app/browser/header/tray/menu.rs

@ -13,7 +13,8 @@ pub struct Menu {
#[rustfmt::skip] // @TODO template builder? #[rustfmt::skip] // @TODO template builder?
impl Menu { impl Menu {
pub fn new( pub fn new(
action_debug: Arc<SimpleAction>, action_tool_debug: Arc<SimpleAction>,
action_tool_profile_directory: Arc<SimpleAction>,
action_quit: Arc<SimpleAction>, action_quit: Arc<SimpleAction>,
action_tab_append: Arc<SimpleAction>, action_tab_append: Arc<SimpleAction>,
action_tab_close: Arc<SimpleAction>, action_tab_close: Arc<SimpleAction>,
@ -55,7 +56,13 @@ impl Menu {
model_tab.append_submenu(Some("Close"), &model_tab_close); model_tab.append_submenu(Some("Close"), &model_tab_close);
model.append_submenu(Some("Tab"), &model_tab); 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))); model.append(Some("Quit"), Some(&detailed_action_name(action_quit)));
// Init widget // Init widget

Loading…
Cancel
Save