From 957e56cc3ea24e8994020c3fa58cb0248c368faa Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 16 Dec 2024 14:17:34 +0200 Subject: [PATCH] toggle find action depending of content type --- src/app/browser/window/action/find.rs | 13 +++-- src/app/browser/window/tab/item/page.rs | 49 ++++++++++++------- .../window/tab/item/page/content/text.rs | 5 +- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/app/browser/window/action/find.rs b/src/app/browser/window/action/find.rs index 15391959..7f9e7ec7 100644 --- a/src/app/browser/window/action/find.rs +++ b/src/app/browser/window/action/find.rs @@ -19,13 +19,12 @@ impl Find { /// Create new `Self` pub fn new() -> Self { - Self { - simple_action: SimpleAction::new_stateful( - &uuid_string_random(), - None, - &DEFAULT_STATE.to_variant(), - ), - } + let simple_action = + SimpleAction::new_stateful(&uuid_string_random(), None, &DEFAULT_STATE.to_variant()); + + simple_action.set_enabled(false); + + Self { simple_action } } // Actions diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 9df13a2a..be08f422 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -38,6 +38,7 @@ pub struct Page { // Actions browser_action: Rc, tab_action: Rc, + window_action: Rc, // Components pub client: Rc, pub content: Rc, @@ -53,14 +54,22 @@ impl Page { pub fn new( id: Rc, profile: Rc, - action: (Rc, Rc, Rc), + (browser_action, window_action, tab_action): ( + Rc, + Rc, + Rc, + ), ) -> Self { // Init components - let content = Rc::new(Content::new((action.1.clone(), action.2.clone()))); + let content = Rc::new(Content::new((window_action.clone(), tab_action.clone()))); let navigation = Rc::new(Navigation::new( profile.clone(), - (action.0.clone(), action.1.clone(), action.2.clone()), + ( + browser_action.clone(), + window_action.clone(), + tab_action.clone(), + ), )); let input = Rc::new(Input::new()); @@ -79,8 +88,9 @@ impl Page { id, profile, // Actions - browser_action: action.0, - tab_action: action.2, + browser_action, + tab_action, + window_action, // Components client: Rc::new(Client::new()), content, @@ -151,6 +161,9 @@ impl Page { // Move focus out from navigation entry self.browser_action.focus.activate(); + // Initially disable find action + self.window_action.find.simple_action.set_enabled(false); + // Reset widgets self.input.unset(); @@ -356,13 +369,14 @@ impl Page { // Init shared clones let cancellable = self.client.cancellable(); - let update = self.browser_action.update.clone(); - let tab_action = self.tab_action.clone(); - let navigation = self.navigation.clone(); let content = self.content.clone(); + let find = self.window_action.find.clone(); let id = self.id.clone(); let input = self.input.clone(); let meta = self.meta.clone(); + let navigation = self.navigation.clone(); + let tab_action = self.tab_action.clone(); + let update = self.browser_action.update.clone(); // Listen for connection status updates self.client.gemini.socket.connect_event({ @@ -515,6 +529,7 @@ impl Page { cancellable.clone(), { let content = content.clone(); + let find = find.clone(); let id = id.clone(); let meta = meta.clone(); let update = update.clone(); @@ -524,26 +539,26 @@ impl Page { Ok(buffer) => { // Set children component, // extract title from meta parsed - let title = if is_source { + let text = if is_source { content.to_text_source( &buffer.data - ); - uri_to_title(&uri) + ) } else { - match content.to_text_gemini( + content.to_text_gemini( &uri, &buffer.data - ).meta.title { - Some(meta_title) => meta_title, - None => uri_to_title(&uri) - } + ) }; // Update page meta meta.set_status(Status::Success) - .set_title(&title); + .set_title(&match text.meta.title { + Some(meta_title) => meta_title, + None => uri_to_title(&uri) + }); // Update window components + find.simple_action.set_enabled(text.has_search); update.activate(Some(&id)); } Err(e) => { 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 8fb84bd6..b32f813b 100644 --- a/src/app/browser/window/tab/item/page/content/text.rs +++ b/src/app/browser/window/tab/item/page/content/text.rs @@ -19,8 +19,9 @@ pub struct Meta { } // @TODO move to separated mod pub struct Text { - pub meta: Meta, pub g_box: Box, + pub has_search: bool, + pub meta: Meta, } impl Text { @@ -86,6 +87,7 @@ impl Text { meta: Meta { title: gemini.reader.title.clone(), }, + has_search: true, g_box, } } @@ -101,6 +103,7 @@ impl Text { Self { meta: Meta { title: None }, + has_search: false, g_box, } }