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 { @@ -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();
}
});

57
src/app/browser.rs

@ -99,61 +99,38 @@ impl Browser { @@ -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 { @@ -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 { @@ -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()
}
}

23
src/app/browser/widget.rs

@ -13,7 +13,7 @@ const MAXIMIZED: bool = false; @@ -13,7 +13,7 @@ const MAXIMIZED: bool = false;
pub struct Widget {
database: Arc<Database>,
application_window: ApplicationWindow,
gobject: ApplicationWindow,
}
impl Widget {
@ -48,7 +48,7 @@ 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 { @@ -57,10 +57,7 @@ impl Widget {
.build();
// Return new struct
Self {
database,
application_window,
}
Self { database, gobject }
}
// Actions
@ -86,8 +83,8 @@ impl Widget { @@ -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 { @@ -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 { @@ -116,7 +113,7 @@ impl Widget {
}
// Getters
pub fn application_window(&self) -> &ApplicationWindow {
&self.application_window
pub fn gobject(&self) -> &ApplicationWindow {
&self.gobject
}
}

18
src/app/browser/window.rs

@ -1,14 +1,16 @@ @@ -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<Tab>,
widget: Box,
widget: Arc<Widget>,
}
impl Window {
@ -32,9 +34,7 @@ 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 { @@ -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()
}
}

20
src/app/browser/window/widget.rs

@ -0,0 +1,20 @@ @@ -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