From 3d9ea1d54e6fc0eb4ee89da50559fba13f650766 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 11 Nov 2024 13:03:55 +0200 Subject: [PATCH] add is_load state --- src/app/browser/window.rs | 4 +-- src/app/browser/window/action/append.rs | 35 +++++++++++-------- src/app/browser/window/tab.rs | 4 ++- src/app/browser/window/tab/item.rs | 9 +++-- .../item/page/content/text/gemini/reader.rs | 1 + 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 4daba859..92681b79 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -38,8 +38,8 @@ impl Window { // Init events action.append().connect_activate({ let tab = tab.clone(); - move |position, request, is_pinned, is_selected| { - tab.append(position, request, is_pinned, is_selected); + move |position, request, is_pinned, is_selected, is_load| { + tab.append(position, request, is_pinned, is_selected, is_load); } }); diff --git a/src/app/browser/window/action/append.rs b/src/app/browser/window/action/append.rs index de6026dc..15911e21 100644 --- a/src/app/browser/window/action/append.rs +++ b/src/app/browser/window/action/append.rs @@ -9,6 +9,7 @@ const DEFAULT_POSITION: i32 = -1; const DEFAULT_REQUEST: String = String::new(); const DEFAULT_IS_PINNED: bool = false; const DEFAULT_IS_SELECTED: bool = true; +const DEFAULT_IS_LOAD: bool = false; /// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Append` action of `Window` group pub struct Append { @@ -29,6 +30,7 @@ impl Append { DEFAULT_REQUEST, DEFAULT_IS_PINNED, DEFAULT_IS_SELECTED, + DEFAULT_IS_LOAD, ) .to_variant(), ), @@ -41,7 +43,7 @@ impl Append { /// * this action reset previous state for action after activation pub fn activate_default_once(&self) { // Save current state in memory - let (position, request, is_pinned, is_selected) = state(&self.gobject); + let (position, request, is_pinned, is_selected, is_load) = state(&self.gobject); // Set default state self.change_state( @@ -49,13 +51,14 @@ impl Append { Some(DEFAULT_REQUEST), DEFAULT_IS_PINNED, DEFAULT_IS_SELECTED, + DEFAULT_IS_LOAD, ); // Activate action self.gobject.activate(None); // Return previous state - self.change_state(position, request, is_pinned, is_selected); + self.change_state(position, request, is_pinned, is_selected, is_load); } /// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal @@ -66,18 +69,19 @@ impl Append { request: Option, is_pinned: bool, is_selected: bool, + is_load: bool, ) { // Save current state in memory - let (_position, _request, _is_pinned, _is_selected) = state(&self.gobject); + let (_position, _request, _is_pinned, _is_selected, _is_load) = state(&self.gobject); // Apply requested state - self.change_state(position, request, is_pinned, is_selected); + self.change_state(position, request, is_pinned, is_selected, is_load); // Activate action self.gobject.activate(None); // Return previous state - self.change_state(_position, _request, _is_pinned, _is_selected); + self.change_state(_position, _request, _is_pinned, _is_selected, _is_load); } /// Emit state change for action @@ -87,6 +91,7 @@ impl Append { request: Option, is_pinned: bool, is_selected: bool, + is_load: bool, ) { self.gobject.change_state( &( @@ -103,6 +108,7 @@ impl Append { }, is_pinned, is_selected, + is_load, ) .to_variant(), ); @@ -112,14 +118,14 @@ impl Append { /// Define callback function for /// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal - /// * return `position`, `is_pinned`, `is_selected` state as tuple + /// * return `position`,`request`,`is_pinned`,`is_selected`,`is_load` state as tuple pub fn connect_activate( &self, - callback: impl Fn(Option, Option, bool, bool) + 'static, + callback: impl Fn(Option, Option, bool, bool, bool) + 'static, ) { self.gobject.connect_activate(move |this, _| { - let (position, request, is_pinned, is_selected) = state(this); - callback(position, request, is_pinned, is_selected) + let (position, request, is_pinned, is_selected, is_load) = state(this); + callback(position, request, is_pinned, is_selected, is_load) }); } @@ -137,12 +143,12 @@ impl Append { } /// Shared helper to get C-based action state in Optional format -pub fn state(this: &SimpleAction) -> (Option, Option, bool, bool) { - let (position, request, is_pinned, is_selected) = this +pub fn state(this: &SimpleAction) -> (Option, Option, bool, bool, bool) { + let (position, request, is_pinned, is_selected, is_load) = this .state() - .expect("Expected (`position`,`request`,`is_pinned`,`is_selected`) state") - .get::<(i32, String, bool, bool)>() - .expect("Parameter type does not match (`i32`,`String`,`bool`,`bool`) tuple"); + .expect("Expected (`position`,`request`,`is_pinned`,`is_selected`,`is_load`) state") + .get::<(i32, String, bool, bool, bool)>() + .expect("Parameter type does not match (`i32`,`String`,`bool`,`bool`,`bool`) tuple"); ( // Convert from C-based variant value to Option if position == DEFAULT_POSITION { @@ -157,5 +163,6 @@ pub fn state(this: &SimpleAction) -> (Option, Option, bool, bool) { }, is_pinned, is_selected, + is_load, ) } diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 20bd0f7a..f25db3de 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -105,6 +105,7 @@ impl Tab { request: Option, is_pinned: bool, is_selected: bool, + is_load: bool, ) -> Rc { // Init new tab item let item = Rc::new(Item::new( @@ -116,6 +117,7 @@ impl Tab { request, is_pinned, is_selected, + is_load, )); // Register dynamically created tab components in the HashMap index @@ -312,7 +314,7 @@ impl Tab { pub fn init(&self) { // Append just one blank page if no tabs available after last session restore if self.index.borrow().is_empty() { - self.append(None, None, false, true); + self.append(None, None, false, true, false); } // @TODO other/child features.. diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index 0240b2c4..2d86e4be 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -39,6 +39,7 @@ impl Item { request: Option, is_pinned: bool, is_selected: bool, + is_load: bool, ) -> Self { // Generate unique ID for new page components let id = uuid_string_random(); @@ -72,8 +73,11 @@ impl Item { .widget() .gobject() .set_text(&text); - page.load(true); - } // @TODO load optionally + + if is_load { + page.load(true); + } + } action.load().connect_activate({ let page = page.clone(); @@ -157,6 +161,7 @@ impl Item { None, record.is_pinned, record.is_selected, + false, )); // Delegate restore action to the item childs 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 cca2803d..d8e2d813 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 @@ -293,6 +293,7 @@ impl Reader { Some(uri.to_string()), false, false, + true, ); // @TODO } // Scheme not supported, delegate