Browse Source

implement separated mod for window widget, rename getters

master
yggverse 2 months ago
parent
commit
1e00c5930c
  1. 4
      src/app.rs
  2. 57
      src/app/browser.rs
  3. 23
      src/app/browser/widget.rs
  4. 18
      src/app/browser/window.rs
  5. 20
      src/app/browser/window/widget.rs

4
src/app.rs

@ -159,10 +159,10 @@ impl App {
} }
// Assign browser window to this application // Assign browser window to this application
browser.widget().set_application(Some(this)); browser.widget_gobject().set_application(Some(this));
// Show main widget // Show main widget
browser.widget().present(); browser.widget_gobject().present();
} }
}); });

57
src/app/browser.rs

@ -99,61 +99,38 @@ impl Browser {
let widget = Arc::new(Widget::new( let widget = Arc::new(Widget::new(
profile_database_connection.clone(), profile_database_connection.clone(),
header.widget(), header.widget(),
window.widget(), window.widget_gobject(),
)); ));
// Assign actions // Assign actions
widget.gobject().add_action(action_tool_debug.as_ref());
widget widget
.application_window() .gobject()
.add_action(action_tool_debug.as_ref());
widget
.application_window()
.add_action(action_tool_profile_directory.as_ref()); .add_action(action_tool_profile_directory.as_ref());
widget.gobject().add_action(action_quit.as_ref());
widget.application_window().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 widget
.application_window() .gobject()
.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()
.add_action(action_tab_page_navigation_base.as_ref()); .add_action(action_tab_page_navigation_base.as_ref());
widget widget
.application_window() .gobject()
.add_action(action_tab_page_navigation_history_back.as_ref()); .add_action(action_tab_page_navigation_history_back.as_ref());
widget widget
.application_window() .gobject()
.add_action(action_tab_page_navigation_history_forward.as_ref()); .add_action(action_tab_page_navigation_history_forward.as_ref());
widget widget
.application_window() .gobject()
.add_action(action_tab_page_navigation_reload.as_ref()); .add_action(action_tab_page_navigation_reload.as_ref());
widget.gobject().add_action(action_tab_pin.as_ref());
widget
.application_window()
.add_action(action_tab_pin.as_ref());
// Init events // Init events
action_tool_debug.connect_activate({ action_tool_debug.connect_activate({
let widget = widget.clone(); let widget = widget.clone();
move |_, _| { move |_, _| {
widget.application_window().emit_enable_debugging(true); widget.gobject().emit_enable_debugging(true);
} }
}); });
@ -170,7 +147,7 @@ impl Browser {
action_quit.connect_activate({ action_quit.connect_activate({
let widget = widget.clone(); let widget = widget.clone();
move |_, _| { move |_, _| {
widget.application_window().close(); widget.gobject().close();
} }
}); });
@ -303,7 +280,7 @@ impl Browser {
} }
// Getters // Getters
pub fn widget(&self) -> &ApplicationWindow { pub fn widget_gobject(&self) -> &ApplicationWindow {
&self.widget.application_window() &self.widget.gobject()
} }
} }

23
src/app/browser/widget.rs

@ -13,7 +13,7 @@ const MAXIMIZED: bool = false;
pub struct Widget { pub struct Widget {
database: Arc<Database>, database: Arc<Database>,
application_window: ApplicationWindow, gobject: ApplicationWindow,
} }
impl Widget { impl Widget {
@ -48,7 +48,7 @@ impl Widget {
}; };
// Init GTK // Init GTK
let application_window = ApplicationWindow::builder() let gobject = ApplicationWindow::builder()
.titlebar(titlebar) .titlebar(titlebar)
.child(child) .child(child)
.default_height(DEFAULT_HEIGHT) .default_height(DEFAULT_HEIGHT)
@ -57,10 +57,7 @@ impl Widget {
.build(); .build();
// Return new struct // Return new struct
Self { Self { database, gobject }
database,
application_window,
}
} }
// Actions // Actions
@ -86,8 +83,8 @@ impl Widget {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Restore widget // Restore widget
self.application_window.set_maximized(record.is_maximized); self.gobject.set_maximized(record.is_maximized);
self.application_window self.gobject
.set_default_size(record.default_width, record.default_height); .set_default_size(record.default_width, record.default_height);
// Delegate restore action to childs // Delegate restore action to childs
@ -102,9 +99,9 @@ impl Widget {
match self.database.add( match self.database.add(
tx, tx,
app_browser_id, app_browser_id,
&self.application_window.default_width(), &self.gobject.default_width(),
&self.application_window.default_height(), &self.gobject.default_height(),
&self.application_window.is_maximized(), &self.gobject.is_maximized(),
) { ) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
@ -116,7 +113,7 @@ impl Widget {
} }
// Getters // Getters
pub fn application_window(&self) -> &ApplicationWindow { pub fn gobject(&self) -> &ApplicationWindow {
&self.application_window &self.gobject
} }
} }

18
src/app/browser/window.rs

@ -1,14 +1,16 @@
mod tab; mod tab;
mod widget;
use std::sync::Arc;
use tab::Tab; 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 { pub struct Window {
tab: Arc<Tab>, tab: Arc<Tab>,
widget: Box, widget: Arc<Widget>,
} }
impl Window { 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 tab.append(Some(GString::from("gemini://geminiprotocol.net/")), true); // demo tab @TODO replace with session restore feature
// GTK // GTK
let widget = Box::builder().orientation(Orientation::Vertical).build(); let widget = Arc::new(Widget::new(tab.widget()));
widget.append(tab.widget());
// Init struct // Init struct
Self { tab, widget } Self { tab, widget }
@ -86,7 +86,7 @@ impl Window {
self.tab.page_description() self.tab.page_description()
} }
pub fn widget(&self) -> &Box { pub fn widget_gobject(&self) -> &Box {
&self.widget &self.widget.gobject()
} }
} }

20
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
}
}
Loading…
Cancel
Save