From 1e00c5930c5ebd6741801a1c0c879512daff38f5 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 6 Oct 2024 05:03:45 +0300 Subject: [PATCH] implement separated mod for window widget, rename getters --- src/app.rs | 4 +-- src/app/browser.rs | 57 ++++++++++---------------------- src/app/browser/widget.rs | 23 ++++++------- src/app/browser/window.rs | 18 +++++----- src/app/browser/window/widget.rs | 20 +++++++++++ 5 files changed, 58 insertions(+), 64 deletions(-) create mode 100644 src/app/browser/window/widget.rs diff --git a/src/app.rs b/src/app.rs index 1798fb5f..fb225709 100644 --- a/src/app.rs +++ b/src/app.rs @@ -159,10 +159,10 @@ impl App { } // Assign browser window to this application - browser.widget().set_application(Some(this)); + browser.widget_gobject().set_application(Some(this)); // Show main widget - browser.widget().present(); + browser.widget_gobject().present(); } }); diff --git a/src/app/browser.rs b/src/app/browser.rs index af1dcb46..627ab58e 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -99,61 +99,38 @@ impl Browser { let widget = Arc::new(Widget::new( profile_database_connection.clone(), header.widget(), - window.widget(), + window.widget_gobject(), )); // Assign actions + widget.gobject().add_action(action_tool_debug.as_ref()); widget - .application_window() - .add_action(action_tool_debug.as_ref()); - - widget - .application_window() + .gobject() .add_action(action_tool_profile_directory.as_ref()); - - widget.application_window().add_action(action_quit.as_ref()); - + widget.gobject().add_action(action_quit.as_ref()); + widget.gobject().add_action(action_update.as_ref()); + widget.gobject().add_action(action_tab_append.as_ref()); + widget.gobject().add_action(action_tab_close.as_ref()); + widget.gobject().add_action(action_tab_close_all.as_ref()); widget - .application_window() - .add_action(action_update.as_ref()); - - widget - .application_window() - .add_action(action_tab_append.as_ref()); - - widget - .application_window() - .add_action(action_tab_close.as_ref()); - - widget - .application_window() - .add_action(action_tab_close_all.as_ref()); - - widget - .application_window() + .gobject() .add_action(action_tab_page_navigation_base.as_ref()); - widget - .application_window() + .gobject() .add_action(action_tab_page_navigation_history_back.as_ref()); - widget - .application_window() + .gobject() .add_action(action_tab_page_navigation_history_forward.as_ref()); - widget - .application_window() + .gobject() .add_action(action_tab_page_navigation_reload.as_ref()); - - widget - .application_window() - .add_action(action_tab_pin.as_ref()); + widget.gobject().add_action(action_tab_pin.as_ref()); // Init events action_tool_debug.connect_activate({ let widget = widget.clone(); move |_, _| { - widget.application_window().emit_enable_debugging(true); + widget.gobject().emit_enable_debugging(true); } }); @@ -170,7 +147,7 @@ impl Browser { action_quit.connect_activate({ let widget = widget.clone(); move |_, _| { - widget.application_window().close(); + widget.gobject().close(); } }); @@ -303,7 +280,7 @@ impl Browser { } // Getters - pub fn widget(&self) -> &ApplicationWindow { - &self.widget.application_window() + pub fn widget_gobject(&self) -> &ApplicationWindow { + &self.widget.gobject() } } diff --git a/src/app/browser/widget.rs b/src/app/browser/widget.rs index 69b6df5d..3e8f6754 100644 --- a/src/app/browser/widget.rs +++ b/src/app/browser/widget.rs @@ -13,7 +13,7 @@ const MAXIMIZED: bool = false; pub struct Widget { database: Arc, - application_window: ApplicationWindow, + gobject: ApplicationWindow, } impl Widget { @@ -48,7 +48,7 @@ impl Widget { }; // Init GTK - let application_window = ApplicationWindow::builder() + let gobject = ApplicationWindow::builder() .titlebar(titlebar) .child(child) .default_height(DEFAULT_HEIGHT) @@ -57,10 +57,7 @@ impl Widget { .build(); // Return new struct - Self { - database, - application_window, - } + Self { database, gobject } } // Actions @@ -86,8 +83,8 @@ impl Widget { Ok(records) => { for record in records { // Restore widget - self.application_window.set_maximized(record.is_maximized); - self.application_window + self.gobject.set_maximized(record.is_maximized); + self.gobject .set_default_size(record.default_width, record.default_height); // Delegate restore action to childs @@ -102,9 +99,9 @@ impl Widget { match self.database.add( tx, app_browser_id, - &self.application_window.default_width(), - &self.application_window.default_height(), - &self.application_window.is_maximized(), + &self.gobject.default_width(), + &self.gobject.default_height(), + &self.gobject.is_maximized(), ) { Ok(_) => { // Delegate save action to childs @@ -116,7 +113,7 @@ impl Widget { } // Getters - pub fn application_window(&self) -> &ApplicationWindow { - &self.application_window + pub fn gobject(&self) -> &ApplicationWindow { + &self.gobject } } diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 31ce31c3..7d8117ff 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -1,14 +1,16 @@ mod tab; - -use std::sync::Arc; +mod widget; use tab::Tab; +use widget::Widget; -use gtk::{gio::SimpleAction, glib::GString, prelude::BoxExt, Box, Orientation}; +use std::sync::Arc; + +use gtk::{gio::SimpleAction, glib::GString, Box}; pub struct Window { tab: Arc, - widget: Box, + widget: Arc, } impl Window { @@ -32,9 +34,7 @@ impl Window { tab.append(Some(GString::from("gemini://geminiprotocol.net/")), true); // demo tab @TODO replace with session restore feature // GTK - let widget = Box::builder().orientation(Orientation::Vertical).build(); - - widget.append(tab.widget()); + let widget = Arc::new(Widget::new(tab.widget())); // Init struct Self { tab, widget } @@ -86,7 +86,7 @@ impl Window { self.tab.page_description() } - pub fn widget(&self) -> &Box { - &self.widget + pub fn widget_gobject(&self) -> &Box { + &self.widget.gobject() } } diff --git a/src/app/browser/window/widget.rs b/src/app/browser/window/widget.rs new file mode 100644 index 00000000..6cc82eb3 --- /dev/null +++ b/src/app/browser/window/widget.rs @@ -0,0 +1,20 @@ +use gtk::{prelude::BoxExt, Box, Notebook, Orientation}; + +pub struct Widget { + gobject: Box, +} + +impl Widget { + // Construct + pub fn new(tab: &Notebook) -> Self { + let gobject = Box::builder().orientation(Orientation::Vertical).build(); + gobject.append(tab); + + Self { gobject } + } + + // Getters + pub fn gobject(&self) -> &Box { + &self.gobject + } +}