From a6ef61486d7ad2e13b9e19f5a0199608b51a7651 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 11 Nov 2024 05:11:48 +0200 Subject: [PATCH] update actions --- src/app/browser.rs | 9 +- src/app/browser/window.rs | 20 ++-- src/app/browser/window/tab.rs | 73 +++++---------- src/app/browser/window/tab/item.rs | 87 +++++++++--------- .../browser/window/tab/{ => item}/action.rs | 19 ++-- .../{action/open.rs => item/action/load.rs} | 24 ++--- src/app/browser/window/tab/item/page.rs | 92 +++++-------------- .../browser/window/tab/item/page/content.rs | 15 ++- .../window/tab/item/page/content/text.rs | 7 +- .../tab/item/page/content/text/gemini.rs | 11 +-- .../item/page/content/text/gemini/reader.rs | 20 ++-- src/app/browser/window/tab/item/page/input.rs | 2 +- .../window/tab/item/page/input/response.rs | 4 +- .../window/tab/item/page/input/sensitive.rs | 4 +- .../window/tab/item/page/navigation.rs | 19 ++-- .../tab/item/page/navigation/bookmark.rs | 6 +- .../tab/item/page/navigation/history.rs | 12 ++- .../tab/item/page/navigation/history/back.rs | 10 +- .../item/page/navigation/history/forward.rs | 6 +- .../window/tab/item/page/navigation/home.rs | 9 +- .../window/tab/item/page/navigation/reload.rs | 7 +- .../tab/item/page/navigation/request.rs | 7 +- .../item/page/navigation/request/widget.rs | 9 +- .../browser/window/tab/item/page/widget.rs | 12 +-- 24 files changed, 190 insertions(+), 294 deletions(-) rename src/app/browser/window/tab/{ => item}/action.rs (82%) rename src/app/browser/window/tab/{action/open.rs => item/action/load.rs} (72%) diff --git a/src/app/browser.rs b/src/app/browser.rs index 0263de6a..f195414f 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -35,7 +35,7 @@ impl Browser { // Init widget let widget = Rc::new(Widget::new( - window.gobject(), + window.widget().gobject(), &[ // Connect action groups (to apply accels) ( @@ -48,11 +48,6 @@ impl Browser { window.action().id(), window.action().gobject().clone(), ), - ( - // Tab - window.tab().action().id(), - window.tab().action().gobject().clone(), - ), ], )); @@ -60,7 +55,7 @@ impl Browser { action.about().connect_activate({ let window = window.clone(); move || { - About::new().present(Some(window.gobject())); + About::new().present(Some(window.widget().gobject())); } }); diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 98ca7662..3e7c6a50 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -12,13 +12,12 @@ use tab::Tab; use widget::Widget; use crate::app::browser::action::Action as BrowserAction; -use gtk::{glib::GString, Box}; +use gtk::glib::GString; use std::rc::Rc; pub struct Window { - //header: Rc
, - tab: Rc, action: Rc, + tab: Rc, widget: Rc, } @@ -33,10 +32,10 @@ impl Window { // Init components let tab = Rc::new(Tab::new(browser_action.clone(), action.clone())); - let header = Header::new(browser_action, action.clone(), tab.gobject()); + let header = Header::new(browser_action, action.clone(), tab.widget().gobject()); // GTK - let widget = Rc::new(Widget::new(header.gobject(), tab.gobject())); + let widget = Rc::new(Widget::new(header.gobject(), tab.widget().gobject())); // Init events action.append().connect_activate({ @@ -91,9 +90,8 @@ impl Window { // Init struct Self { - //header, - tab, action, + tab, widget, } } @@ -163,12 +161,8 @@ impl Window { &self.action } - pub fn tab(&self) -> &Rc { - &self.tab - } - - pub fn gobject(&self) -> &Box { - self.widget.gobject() + pub fn widget(&self) -> &Rc { + &self.widget } } diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 6f8e7bd3..c54a081c 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -1,10 +1,8 @@ -mod action; mod database; mod item; mod menu; mod widget; -use action::Action; use database::Database; use item::Item; use menu::Menu; @@ -12,7 +10,6 @@ use widget::Widget; use crate::app::browser::action::Action as BrowserAction; use crate::app::browser::window::action::Action as WindowAction; -use adw::TabView; use gtk::{ glib::{GString, Propagation}, prelude::WidgetExt, @@ -22,22 +19,16 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc}; // Main pub struct Tab { - // Actions browser_action: Rc, window_action: Rc, - // Dynamically allocated reference index index: Rc>>>, - action: Rc, widget: Rc, } impl Tab { // Construct pub fn new(browser_action: Rc, window_action: Rc) -> Self { - // Init local actions - let action = Rc::new(Action::new()); - - // Init empty HashMap index as no tabs appended yet + // Init empty HashMap index let index: Rc>>> = Rc::new(RefCell::new(HashMap::new())); // Init context menu @@ -98,29 +89,11 @@ impl Tab { } }); - action.open().connect_activate({ - let index = index.clone(); - let widget = widget.clone(); - move |request| { - if let Some(value) = request { - if let Some(page) = widget.page(None) { - if let Some(id) = page.keyword() { - if let Some(item) = index.borrow().get(&id) { - item.set_page_navigation_request_text(value.as_str()); - item.page().reload(); - } - } - } - } - } - }); // @TODO fix new item on middle click - // Return activated `Self` Self { browser_action, window_action, index, - action, widget, } } @@ -128,19 +101,20 @@ impl Tab { // Actions pub fn append(&self, position: Option) -> Rc { // Init new tab item - let item = Item::new_rc( - self.gobject(), + let item = Rc::new(Item::new( + self.widget.gobject(), self.browser_action.clone(), self.window_action.clone(), - self.action.clone(), // Options position, false, true, - ); + )); // Register dynamically created tab components in the HashMap index - self.index.borrow_mut().insert(item.id(), item.clone()); + self.index + .borrow_mut() + .insert(item.id().clone(), item.clone()); item.page() .navigation() @@ -220,8 +194,10 @@ impl Tab { item.update(); // Update tab title on loading indicator inactive - if !item.page_is_loading() { - item.gobject().set_title(item.page_meta_title().as_str()) + if !item.page().is_loading() { + item.widget() + .gobject() + .set_title(item.page().meta().title().as_str()) } } // Update all tabs on ID not found @TODO change initial update method @@ -231,8 +207,10 @@ impl Tab { item.update(); // Update tab title on loading indicator inactive - if !item.page_is_loading() { - item.gobject().set_title(item.page_meta_title().as_str()) + if !item.page().is_loading() { + item.widget() + .gobject() + .set_title(item.page().meta().title().as_str()) } } } @@ -273,17 +251,18 @@ impl Tab { Ok(records) => { for record in records { match Item::restore( - self.gobject(), + self.widget.gobject(), transaction, &record.id, self.browser_action.clone(), self.window_action.clone(), - self.action.clone(), ) { Ok(items) => { for item in items { // Register dynamically created tab item in the HashMap index - self.index.borrow_mut().insert(item.id(), item.clone()); + self.index + .borrow_mut() + .insert(item.id().clone(), item.clone()); } } Err(e) => return Err(e.to_string()), @@ -311,9 +290,9 @@ impl Tab { item.save( transaction, &id, - &self.widget.gobject().page_position(item.gobject()), - &item.gobject().is_pinned(), - &item.gobject().is_selected(), + &self.widget.gobject().page_position(item.widget().gobject()), + &item.widget().gobject().is_pinned(), + &item.widget().gobject().is_selected(), )?; } } @@ -334,12 +313,8 @@ impl Tab { // Getters - pub fn action(&self) -> &Rc { - &self.action - } - - pub fn gobject(&self) -> &TabView { - self.widget.gobject() + pub fn widget(&self) -> &Rc { + &self.widget } } diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index fc296b66..1b0637a3 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -1,15 +1,15 @@ +mod action; mod database; mod page; mod widget; +use action::Action; use database::Database; use page::Page; use widget::Widget; -use crate::app::browser::action::Action as BrowserAction; -use crate::app::browser::window::action::Action as WindowAction; -use crate::app::browser::window::tab::action::Action as TabAction; -use adw::{TabPage, TabView}; +use crate::app::browser::{window::Action as WindowAction, Action as BrowserAction}; +use adw::TabView; use gtk::{ glib::{uuid_string_random, GString}, prelude::EditableExt, @@ -22,47 +22,70 @@ pub struct Item { // useful as widget name in GTK actions callback id: GString, // Components + action: Rc, page: Rc, widget: Rc, } impl Item { // Construct - pub fn new_rc( + pub fn new( tab_view: &TabView, // Actions browser_action: Rc, window_action: Rc, - tab_action: Rc, // Options position: Option, is_pinned: bool, is_selected: bool, - ) -> Rc { + ) -> Self { // Generate unique ID for new page components let id = uuid_string_random(); // Init components - let page = Page::new_rc( + + let action = Rc::new(Action::new()); + + let page = Rc::new(Page::new( id.clone(), - // Actions browser_action, window_action, - tab_action, - ); + action.clone(), + )); let widget = Rc::new(Widget::new( id.as_str(), tab_view, - page.gobject(), + page.widget().gobject(), None, position, is_pinned, is_selected, - )); // @TODO + )); - // Return struct - Rc::new(Self { id, page, widget }) + // Init events + + action.load().connect_activate({ + let page = page.clone(); + move |request| { + if let Some(text) = request { + page.navigation() + .request() + .widget() + .gobject() + .set_text(&text); + } + page.load(true); + } + }); + + // Done + Self { + id, + action, + page, + widget, + } } // Actions @@ -71,7 +94,7 @@ impl Item { self.page.update(); // Update tab loading indicator - self.widget.gobject().set_loading(self.page_is_loading()); + self.widget.gobject().set_loading(self.page().is_loading()); } pub fn clean( @@ -107,7 +130,6 @@ impl Item { // Actions browser_action: Rc, window_action: Rc, - tab_action: Rc, ) -> Result>, String> { let mut items = Vec::new(); @@ -115,17 +137,16 @@ impl Item { Ok(records) => { for record in records { // Construct new item object - let item = Item::new_rc( + let item = Rc::new(Item::new( tab_view, // Actions browser_action.clone(), window_action.clone(), - tab_action.clone(), // Options None, record.is_pinned, record.is_selected, - ); + )); // Delegate restore action to the item childs item.page.restore(transaction, &record.id)?; @@ -169,36 +190,18 @@ impl Item { Ok(()) } - // Setters - pub fn set_page_navigation_request_text(&self, value: &str) { - self.page - .navigation() - .request() - .widget() - .gobject() - .set_text(value); - } - // Getters - pub fn id(&self) -> GString { - self.id.clone() + pub fn id(&self) -> &GString { + &self.id } pub fn page(&self) -> &Rc { &self.page } - pub fn page_is_loading(&self) -> bool { - self.page.is_loading() - } - - pub fn page_meta_title(&self) -> GString { - self.page.meta_title() - } - - pub fn gobject(&self) -> &TabPage { - self.widget.gobject() + pub fn widget(&self) -> &Rc { + &self.widget } } diff --git a/src/app/browser/window/tab/action.rs b/src/app/browser/window/tab/item/action.rs similarity index 82% rename from src/app/browser/window/tab/action.rs rename to src/app/browser/window/tab/item/action.rs index 6cd4d8af..aa577b5a 100644 --- a/src/app/browser/window/tab/action.rs +++ b/src/app/browser/window/tab/item/action.rs @@ -1,6 +1,5 @@ -mod open; - -use open::Open; +mod load; +use load::Load; use gtk::{ gio::SimpleActionGroup, @@ -12,7 +11,7 @@ use std::rc::Rc; /// [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) wrapper for `Browser` actions pub struct Action { // Actions - open: Rc, + load: Rc, // Group id: GString, gobject: SimpleActionGroup, @@ -24,7 +23,7 @@ impl Action { /// Create new `Self` pub fn new() -> Self { // Init actions - let open = Rc::new(Open::new()); + let load = Rc::new(Load::new()); // Generate unique group ID let id = uuid_string_random(); @@ -33,17 +32,17 @@ impl Action { let gobject = SimpleActionGroup::new(); // Add action to given group - gobject.add_action(open.gobject()); + gobject.add_action(load.gobject()); // Done - Self { open, id, gobject } + Self { load, id, gobject } } // Getters - /// Get reference `Open` action - pub fn open(&self) -> &Rc { - &self.open + /// Get reference to `Load` action + pub fn load(&self) -> &Rc { + &self.load } /// Get auto-generated name for action group diff --git a/src/app/browser/window/tab/action/open.rs b/src/app/browser/window/tab/item/action/load.rs similarity index 72% rename from src/app/browser/window/tab/action/open.rs rename to src/app/browser/window/tab/item/action/load.rs index 22f630cc..260191da 100644 --- a/src/app/browser/window/tab/action/open.rs +++ b/src/app/browser/window/tab/item/action/load.rs @@ -4,12 +4,12 @@ use gtk::{ prelude::{ActionExt, StaticVariantType, ToVariant}, }; -/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Open` action of `Browser` group -pub struct Open { +/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Load` action of `Item` group +pub struct Load { gobject: SimpleAction, } -impl Open { +impl Load { // Constructors /// Create new `Self` @@ -23,9 +23,9 @@ impl Open { /// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal /// with formatted for this action [Variant](https://docs.gtk.org/glib/struct.Variant.html) value - pub fn activate(&self, tab_item_id: Option<&str>) { + pub fn activate(&self, request: Option<&str>) { self.gobject.activate(Some( - &match tab_item_id { + &match request { Some(value) => String::from(value), None => String::new(), } @@ -39,14 +39,14 @@ impl Open { /// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal pub fn connect_activate(&self, callback: impl Fn(Option) + 'static) { self.gobject.connect_activate(move |_, variant| { - let tab_item_id = variant - .expect("Variant required to call this action") + let request = variant + .expect("Parameter value required") .get::() .expect("Parameter type does not match `String`"); - callback(match tab_item_id.is_empty() { + callback(match request.is_empty() { true => None, - false => Some(tab_item_id.into()), + false => Some(request.into()), }) }); } @@ -57,10 +57,4 @@ impl Open { pub fn gobject(&self) -> &SimpleAction { &self.gobject } - - /* @TODO not in use - /// Get auto-generated [action name](https://docs.gtk.org/gio/property.SimpleAction.name.html) - pub fn id(&self) -> GString { - self.gobject.name() - } */ } diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 01e37130..9902df5f 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -12,24 +12,18 @@ use meta::{Meta, Status}; use navigation::Navigation; use widget::Widget; -use crate::app::browser::action::Action as BrowserAction; -use crate::app::browser::window::action::Action as WindowAction; -use crate::app::browser::window::tab::action::Action as TabAction; +use crate::app::browser::{ + window::{tab::item::Action as TabAction, Action as WindowAction}, + Action as BrowserAction, +}; use gtk::{ gdk_pixbuf::Pixbuf, - gio::{ - Cancellable, SimpleAction, SocketClient, SocketClientEvent, SocketProtocol, - TlsCertificateFlags, - }, + gio::{Cancellable, SocketClient, SocketClientEvent, SocketProtocol, TlsCertificateFlags}, glib::{ - gformat, uuid_string_random, Bytes, GString, Priority, Regex, RegexCompileFlags, - RegexMatchFlags, Uri, UriFlags, UriHideFlags, + gformat, Bytes, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, + UriFlags, UriHideFlags, }, - prelude::{ - ActionExt, CancellableExt, EditableExt, IOStreamExt, OutputStreamExt, SocketClientExt, - StaticVariantType, - }, - Box, + prelude::{CancellableExt, EditableExt, IOStreamExt, OutputStreamExt, SocketClientExt}, }; use sqlite::Transaction; use std::{cell::RefCell, rc::Rc, time::Duration}; @@ -39,47 +33,38 @@ pub struct Page { cancellable: RefCell, // Actions browser_action: Rc, + window_action: Rc, tab_action: Rc, - action_page_load: SimpleAction, // Components navigation: Rc, content: Rc, input: Rc, - // Extras meta: Rc, - // GTK widget: Rc, } impl Page { // Constructors - /// Create new activated `Rc` - pub fn new_rc( + pub fn new( id: GString, browser_action: Rc, window_action: Rc, tab_action: Rc, - ) -> Rc { - // Init local actions - let action_page_load = SimpleAction::new(&uuid_string_random(), None); - let action_page_open = - SimpleAction::new(&uuid_string_random(), Some(&String::static_variant_type())); - + ) -> Self { // Init components - let content = Rc::new(Content::new(tab_action.clone(), action_page_open.clone())); + let content = Rc::new(Content::new(window_action.clone(), tab_action.clone())); let navigation = Rc::new(Navigation::new( browser_action.clone(), window_action.clone(), - action_page_open.clone(), + tab_action.clone(), )); let input = Rc::new(Input::new()); let widget = Rc::new(Widget::new( &id, - action_page_open.clone(), navigation.widget().gobject(), content.gobject(), input.gobject(), @@ -87,48 +72,21 @@ impl Page { let meta = Rc::new(Meta::new(Status::New, gformat!("New page"))); - // Init `Self` - let this = Rc::new(Self { + // Done + Self { cancellable: RefCell::new(Cancellable::new()), id, // Actions browser_action, + window_action, tab_action, - action_page_load: action_page_load.clone(), // Components content, navigation, input, - // Extras meta, - // GTK widget, - }); - - // Init events - action_page_load.connect_activate({ - let this = this.clone(); - move |_, _| this.load(false) - }); - - action_page_open.connect_activate({ - let this = this.clone(); - move |_, request| { - // Set request value from action parameter - this.navigation().request().widget().gobject().set_text( - &request - .expect("Parameter required for this action") - .get::() - .expect("Parameter does not match `String`"), - ); - - // Reload page - this.load(true); - } - }); - - // Return activated `Self` - this + } } // Actions @@ -138,7 +96,7 @@ impl Page { pub fn home(&self) { if let Some(url) = self.navigation.home().url() { // Update with history record - self.tab_action.open().activate(Some(&url)); + self.tab_action.load().activate(Some(&url)); } } @@ -432,21 +390,16 @@ impl Page { } } - pub fn meta_title(&self) -> GString { - self.meta.title() - } - - /* pub fn meta(&self) -> &Rc { &self.meta - } */ + } pub fn navigation(&self) -> &Rc { &self.navigation } - pub fn gobject(&self) -> &Box { - self.widget.gobject() + pub fn widget(&self) -> &Rc { + &self.widget } // Private helpers @TODO move outside @@ -457,7 +410,6 @@ impl Page { // Init shared objects (async) let cancellable = self.cancellable.borrow().clone(); let update = self.browser_action.update().clone(); - let action_page_load = self.action_page_load.clone(); let tab_action = self.tab_action.clone(); let content = self.content.clone(); let id = self.id.clone(); @@ -799,7 +751,7 @@ impl Page { .set_title("Redirect"); // Reload page to apply redirection - action_page_load.activate(None); + tab_action.load().activate(None); } }, Err(reason) => { diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index 2b4d4977..0101aa2d 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -6,10 +6,9 @@ use image::Image; use status::Status; use text::Text; -use crate::app::browser::window::tab::action::Action as TabAction; +use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction}; use gtk::{ gdk_pixbuf::Pixbuf, - gio::SimpleAction, glib::Uri, prelude::{BoxExt, WidgetExt}, Box, Orientation, @@ -17,22 +16,20 @@ use gtk::{ use std::{rc::Rc, time::Duration}; pub struct Content { - // GTK - gobject: Box, - // Actions + window_action: Rc, tab_action: Rc, - action_page_open: SimpleAction, + gobject: Box, } impl Content { // Construct /// Create new container for different components - pub fn new(tab_action: Rc, action_page_open: SimpleAction) -> Self { + pub fn new(window_action: Rc, tab_action: Rc) -> Self { Self { gobject: Box::builder().orientation(Orientation::Vertical).build(), + window_action, tab_action, - action_page_open, } } @@ -88,8 +85,8 @@ impl Content { let text = Text::gemini( data, base, + self.window_action.clone(), self.tab_action.clone(), - self.action_page_open.clone(), ); self.gobject.append(text.gobject()); text diff --git a/src/app/browser/window/tab/item/page/content/text.rs b/src/app/browser/window/tab/item/page/content/text.rs index fe36bd47..45d84910 100644 --- a/src/app/browser/window/tab/item/page/content/text.rs +++ b/src/app/browser/window/tab/item/page/content/text.rs @@ -2,9 +2,8 @@ mod gemini; use gemini::Gemini; -use crate::app::browser::window::tab::action::Action as TabAction; +use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction}; use gtk::{ - gio::SimpleAction, glib::{GString, Uri}, ScrolledWindow, }; @@ -24,11 +23,11 @@ impl Text { pub fn gemini( gemtext: &str, base: &Uri, + window_action: Rc, tab_action: Rc, - action_page_open: SimpleAction, ) -> Self { // Init components - let gemini = Gemini::new(gemtext, base, tab_action, action_page_open); + let gemini = Gemini::new(gemtext, base, window_action, tab_action); // Init meta let meta = Meta { diff --git a/src/app/browser/window/tab/item/page/content/text/gemini.rs b/src/app/browser/window/tab/item/page/content/text/gemini.rs index 14e32cc2..d08ebfbf 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini.rs @@ -4,12 +4,9 @@ mod widget; use reader::Reader; use widget::Widget; -use crate::app::browser::window::tab::action::Action as TabAction; +use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction}; use adw::ClampScrollable; -use gtk::{ - gio::SimpleAction, - glib::{GString, Uri}, -}; +use gtk::glib::{GString, Uri}; use std::rc::Rc; pub struct Gemini { @@ -22,11 +19,11 @@ impl Gemini { pub fn new( gemtext: &str, base: &Uri, + window_action: Rc, tab_action: Rc, - action_page_open: SimpleAction, ) -> Self { // Init components - let reader = Rc::new(Reader::new(gemtext, base, tab_action, action_page_open)); + let reader = Rc::new(Reader::new(gemtext, base, window_action, tab_action)); let widget = Rc::new(Widget::new(reader.gobject())); // Result diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs index ccc54954..a33595f8 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs @@ -4,7 +4,7 @@ mod widget; use tag::Tag; use widget::Widget; -use crate::app::browser::window::tab::action::Action as TabAction; +use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction}; use adw::StyleManager; use gemtext::line::{ code::Code, @@ -15,9 +15,9 @@ use gemtext::line::{ }; use gtk::{ gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY}, - gio::{Cancellable, SimpleAction}, + gio::Cancellable, glib::{GString, TimeZone, Uri}, - prelude::{ActionExt, TextBufferExt, TextBufferExtManual, TextViewExt, ToVariant, WidgetExt}, + prelude::{TextBufferExt, TextBufferExtManual, TextViewExt, WidgetExt}, EventControllerMotion, GestureClick, TextBuffer, TextTag, TextView, TextWindowType, UriLauncher, Window, WrapMode, }; @@ -33,8 +33,8 @@ impl Reader { pub fn new( gemtext: &str, base: &Uri, + window_action: Rc, tab_action: Rc, - action_page_open: SimpleAction, ) -> Self { // Init default values let mut title = None; @@ -232,7 +232,7 @@ impl Reader { // Init events primary_button_controller.connect_released({ - let action_page_open = action_page_open.clone(); + let tab_action = tab_action.clone(); let gobject = widget.gobject().clone(); let _links_ = links.clone(); // is copy move |_, _, window_x, window_y| { @@ -251,7 +251,7 @@ impl Reader { return match uri.scheme().as_str() { "gemini" => { // Open new page in browser - action_page_open.activate(Some(&uri.to_str().to_variant())); + tab_action.load().activate(Some(&uri.to_str())); } // Scheme not supported, delegate _ => UriLauncher::new(&uri.to_str()).launch( @@ -259,8 +259,7 @@ impl Reader { None::<&Cancellable>, |result| { if let Err(error) = result { - // @TODO - println!("Could not delegate launch action: {error}") + println!("{error}") } }, ), @@ -289,7 +288,7 @@ impl Reader { return match uri.scheme().as_str() { "gemini" => { // Open new page in browser - tab_action.open().activate(Some(&uri.to_string())); + window_action.append().activate(); } // Scheme not supported, delegate _ => UriLauncher::new(&uri.to_str()).launch( @@ -297,8 +296,7 @@ impl Reader { None::<&Cancellable>, |result| { if let Err(error) = result { - // @TODO - println!("Could not delegate launch action: {error}") + println!("{error}") } }, ), diff --git a/src/app/browser/window/tab/item/page/input.rs b/src/app/browser/window/tab/item/page/input.rs index 32b46a17..7e2f00f0 100644 --- a/src/app/browser/window/tab/item/page/input.rs +++ b/src/app/browser/window/tab/item/page/input.rs @@ -6,7 +6,7 @@ use response::Response; use sensitive::Sensitive; use widget::Widget; -use crate::app::browser::window::tab::action::Action as TabAction; +use crate::app::browser::window::tab::item::Action as TabAction; use adw::Clamp; use gtk::glib::Uri; use std::rc::Rc; diff --git a/src/app/browser/window/tab/item/page/input/response.rs b/src/app/browser/window/tab/item/page/input/response.rs index 79d513a3..1e846b29 100644 --- a/src/app/browser/window/tab/item/page/input/response.rs +++ b/src/app/browser/window/tab/item/page/input/response.rs @@ -8,7 +8,7 @@ use form::Form; use title::Title; use widget::Widget; -use crate::app::browser::window::tab::action::Action as TabAction; +use crate::app::browser::window::tab::item::action::Action as TabAction; use gtk::{ gio::SimpleAction, glib::{uuid_string_random, Uri, UriHideFlags}, @@ -63,7 +63,7 @@ impl Response { action_send.connect_activate({ let form = form.clone(); move |_, _| { - tab_action.open().activate(Some(&format!( + tab_action.load().activate(Some(&format!( "{}?{}", base.to_string_partial(UriHideFlags::QUERY), Uri::escape_string(form.text().as_str(), None, false), diff --git a/src/app/browser/window/tab/item/page/input/sensitive.rs b/src/app/browser/window/tab/item/page/input/sensitive.rs index 75c418aa..4aa0de5a 100644 --- a/src/app/browser/window/tab/item/page/input/sensitive.rs +++ b/src/app/browser/window/tab/item/page/input/sensitive.rs @@ -4,7 +4,7 @@ mod widget; use form::Form; use widget::Widget; -use crate::app::browser::window::tab::action::Action as TabAction; +use crate::app::browser::window::tab::item::action::Action as TabAction; use gtk::{ gio::SimpleAction, glib::{uuid_string_random, Uri, UriHideFlags}, @@ -44,7 +44,7 @@ impl Sensitive { action_send.connect_activate({ let form = form.clone(); move |_, _| { - tab_action.open().activate(Some(&format!( + tab_action.load().activate(Some(&format!( "{}?{}", base.to_string_partial(UriHideFlags::QUERY), Uri::escape_string(form.text().as_str(), None, false), diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 036273cb..9dafc9ee 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -14,9 +14,10 @@ use reload::Reload; use request::Request; use widget::Widget; -use crate::app::browser::action::Action as BrowserAction; -use crate::app::browser::window::action::Action as WindowAction; -use gtk::{gio::SimpleAction, prelude::EditableExt}; +use crate::app::browser::window::tab::item::Action as TabAction; +use crate::app::browser::window::Action as WindowAction; +use crate::app::browser::Action as BrowserAction; +use gtk::prelude::EditableExt; use sqlite::Transaction; use std::rc::Rc; @@ -33,22 +34,22 @@ impl Navigation { pub fn new( browser_action: Rc, window_action: Rc, - action_page_open: SimpleAction, + tab_action: Rc, ) -> Self { // Init components let home = Rc::new(Home::new(window_action.clone())); let history = Rc::new(History::new(window_action.clone())); let reload = Rc::new(Reload::new(window_action)); - let request = Rc::new(Request::new(browser_action, action_page_open.clone())); + let request = Rc::new(Request::new(browser_action, tab_action)); let bookmark = Rc::new(Bookmark::new()); // Init widget let widget = Rc::new(Widget::new( - home.gobject(), - history.gobject(), - reload.gobject(), + home.widget().gobject(), + history.widget().gobject(), + reload.widget().gobject(), request.widget().gobject(), - bookmark.gobject(), + bookmark.widget().gobject(), )); // Done diff --git a/src/app/browser/window/tab/item/page/navigation/bookmark.rs b/src/app/browser/window/tab/item/page/navigation/bookmark.rs index 8e4ec699..39f15a40 100644 --- a/src/app/browser/window/tab/item/page/navigation/bookmark.rs +++ b/src/app/browser/window/tab/item/page/navigation/bookmark.rs @@ -2,7 +2,6 @@ mod widget; use widget::Widget; -use gtk::Button; use std::rc::Rc; pub struct Bookmark { @@ -23,7 +22,8 @@ impl Bookmark { } // Getters - pub fn gobject(&self) -> &Button { - self.widget.gobject() + + pub fn widget(&self) -> &Rc { + &self.widget } } diff --git a/src/app/browser/window/tab/item/page/navigation/history.rs b/src/app/browser/window/tab/item/page/navigation/history.rs index 620e8627..30f4b120 100644 --- a/src/app/browser/window/tab/item/page/navigation/history.rs +++ b/src/app/browser/window/tab/item/page/navigation/history.rs @@ -7,7 +7,7 @@ use forward::Forward; use widget::Widget; use crate::app::browser::window::action::Action as WindowAction; -use gtk::{glib::GString, Box}; +use gtk::glib::GString; use std::{cell::RefCell, rc::Rc}; struct Memory { @@ -34,7 +34,10 @@ impl History { let forward = Rc::new(Forward::new(window_action)); // Init widget - let widget = Rc::new(Widget::new(back.gobject(), forward.gobject())); + let widget = Rc::new(Widget::new( + back.widget().gobject(), + forward.widget().gobject(), + )); // Init memory let memory = RefCell::new(Vec::new()); @@ -122,7 +125,8 @@ impl History { } // Getters - pub fn gobject(&self) -> &Box { - self.widget.gobject() + + pub fn widget(&self) -> &Rc { + &self.widget } } diff --git a/src/app/browser/window/tab/item/page/navigation/history/back.rs b/src/app/browser/window/tab/item/page/navigation/history/back.rs index 565e3f02..ad23fdee 100644 --- a/src/app/browser/window/tab/item/page/navigation/history/back.rs +++ b/src/app/browser/window/tab/item/page/navigation/history/back.rs @@ -3,7 +3,6 @@ mod widget; use widget::Widget; use crate::app::browser::window::action::Action as WindowAction; -use gtk::Button; use std::rc::Rc; pub struct Back { @@ -12,7 +11,8 @@ pub struct Back { } impl Back { - // Construct + // Constructors + pub fn new(window_action: Rc) -> Self { Self { window_action: window_action.clone(), @@ -21,6 +21,7 @@ impl Back { } // Actions + pub fn update(&self, status: bool) { // Update actions self.window_action @@ -33,7 +34,8 @@ impl Back { } // Getters - pub fn gobject(&self) -> &Button { - self.widget.gobject() + + pub fn widget(&self) -> &Rc { + &self.widget } } diff --git a/src/app/browser/window/tab/item/page/navigation/history/forward.rs b/src/app/browser/window/tab/item/page/navigation/history/forward.rs index e772eae8..438b9ca4 100644 --- a/src/app/browser/window/tab/item/page/navigation/history/forward.rs +++ b/src/app/browser/window/tab/item/page/navigation/history/forward.rs @@ -3,7 +3,6 @@ mod widget; use widget::Widget; use crate::app::browser::window::action::Action as WindowAction; -use gtk::Button; use std::rc::Rc; pub struct Forward { @@ -33,7 +32,8 @@ impl Forward { } // Getters - pub fn gobject(&self) -> &Button { - self.widget.gobject() + + pub fn widget(&self) -> &Rc { + &self.widget } } diff --git a/src/app/browser/window/tab/item/page/navigation/home.rs b/src/app/browser/window/tab/item/page/navigation/home.rs index 9fc5be59..04b16520 100644 --- a/src/app/browser/window/tab/item/page/navigation/home.rs +++ b/src/app/browser/window/tab/item/page/navigation/home.rs @@ -3,10 +3,7 @@ mod widget; use widget::Widget; use crate::app::browser::window::action::Action as WindowAction; -use gtk::{ - glib::{gformat, GString, Uri}, - Button, -}; +use gtk::glib::{gformat, GString, Uri}; use std::{cell::RefCell, rc::Rc}; pub struct Home { @@ -44,8 +41,8 @@ impl Home { } // Getters - pub fn gobject(&self) -> &Button { - self.widget.gobject() + pub fn widget(&self) -> &Rc { + &self.widget } pub fn url(&self) -> Option { diff --git a/src/app/browser/window/tab/item/page/navigation/reload.rs b/src/app/browser/window/tab/item/page/navigation/reload.rs index 58088b70..108de94d 100644 --- a/src/app/browser/window/tab/item/page/navigation/reload.rs +++ b/src/app/browser/window/tab/item/page/navigation/reload.rs @@ -3,7 +3,6 @@ mod widget; use widget::Widget; use crate::app::browser::window::action::Action as WindowAction; -use gtk::Button; use std::rc::Rc; pub struct Reload { @@ -21,6 +20,7 @@ impl Reload { } // Actions + pub fn update(&self, is_enabled: bool) { // Update actions self.window_action @@ -33,7 +33,8 @@ impl Reload { } // Getters - pub fn gobject(&self) -> &Button { - self.widget.gobject() + + pub fn widget(&self) -> &Rc { + &self.widget } } diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index d20837ba..bd5aad40 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -4,9 +4,8 @@ mod widget; use database::Database; use widget::Widget; -use crate::app::browser::action::Action as BrowserAction; +use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction}; use gtk::{ - gio::SimpleAction, glib::{Uri, UriFlags}, prelude::EditableExt, }; @@ -23,10 +22,10 @@ impl Request { pub fn new( // Actions browser_action: Rc, - action_page_reload: SimpleAction, // @TODO local `action_page_open`? + tab_action: Rc, ) -> Self { Self { - widget: Rc::new(Widget::new(browser_action, action_page_reload)), + widget: Rc::new(Widget::new(browser_action, tab_action)), } } diff --git a/src/app/browser/window/tab/item/page/navigation/request/widget.rs b/src/app/browser/window/tab/item/page/navigation/request/widget.rs index b5d87a2f..b46d1c3c 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/widget.rs @@ -2,11 +2,10 @@ mod database; use database::Database; -use crate::app::browser::action::Action as BrowserAction; +use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction}; use gtk::{ - gio::SimpleAction, glib::{timeout_add_local, ControlFlow, SourceId}, - prelude::{ActionExt, EditableExt, EntryExt, ToVariant, WidgetExt}, + prelude::{EditableExt, EntryExt, WidgetExt}, Entry, StateFlags, }; use sqlite::Transaction; @@ -30,7 +29,7 @@ pub struct Widget { impl Widget { // Construct - pub fn new(browser_action: Rc, action_page_open: SimpleAction) -> Self { + pub fn new(browser_action: Rc, tab_action: Rc) -> Self { // Init animated progress bar state let progress = Rc::new(Progress { fraction: RefCell::new(0.0), @@ -49,7 +48,7 @@ impl Widget { }); gobject.connect_activate(move |this| { - action_page_open.activate(Some(&this.text().to_variant())); + tab_action.load().activate(Some(&this.text())); }); gobject.connect_state_flags_changed({ diff --git a/src/app/browser/window/tab/item/page/widget.rs b/src/app/browser/window/tab/item/page/widget.rs index 8c2e79e3..fcedee5e 100644 --- a/src/app/browser/window/tab/item/page/widget.rs +++ b/src/app/browser/window/tab/item/page/widget.rs @@ -1,7 +1,5 @@ use gtk::{ - gio::{SimpleAction, SimpleActionGroup}, - glib::uuid_string_random, - prelude::{ActionMapExt, BoxExt, IsA, WidgetExt}, + prelude::{BoxExt, IsA}, Box, Orientation, }; @@ -13,17 +11,11 @@ impl Widget { // Construct pub fn new( name: &str, - // Actions - action_page_open: SimpleAction, // Components navigation: &impl IsA, content: &impl IsA, input: &impl IsA, ) -> Self { - // Init additional action group - let action_group = SimpleActionGroup::new(); - action_group.add_action(&action_page_open); - // Init self let gobject = Box::builder() .orientation(Orientation::Vertical) @@ -34,8 +26,6 @@ impl Widget { gobject.append(content); gobject.append(input); - gobject.insert_action_group(&uuid_string_random(), Some(&action_group)); - Self { gobject } }