From 5348417a732eac6cfadb715a21733c376cd8ebfe Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 11 Dec 2024 05:44:59 +0200 Subject: [PATCH] implement identity button as navigation entry primary icon --- .../window/tab/item/page/navigation.rs | 22 +++--- .../tab/item/page/navigation/identity.rs | 29 -------- .../item/page/navigation/identity/widget.rs | 35 ---------- .../tab/item/page/navigation/request.rs | 13 +++- .../item/page/navigation/request/widget.rs | 70 +++++++++++++------ .../window/tab/item/page/navigation/widget.rs | 2 - 6 files changed, 66 insertions(+), 105 deletions(-) delete mode 100644 src/app/browser/window/tab/item/page/navigation/identity.rs delete mode 100644 src/app/browser/window/tab/item/page/navigation/identity/widget.rs diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 3553081e..ca6a78d4 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -2,7 +2,6 @@ mod bookmark; mod database; mod history; mod home; -mod identity; mod reload; mod request; mod widget; @@ -10,7 +9,6 @@ mod widget; use bookmark::Bookmark; use history::History; use home::Home; -use identity::Identity; use reload::Reload; use request::Request; use widget::Widget; @@ -27,7 +25,6 @@ pub struct Navigation { pub bookmark: Rc, pub history: Rc, pub home: Rc, - pub identity: Rc, pub profile: Rc, pub reload: Rc, pub request: Rc, @@ -40,7 +37,6 @@ impl Navigation { action: (Rc, Rc, Rc), ) -> Self { // Init components - let identity = Rc::new(Identity::new(action.2.clone())); let home = Rc::new(Home::new(action.1.clone())); let history = Rc::new(History::new(action.1.clone())); let reload = Rc::new(Reload::new(action.1.clone())); @@ -49,7 +45,6 @@ impl Navigation { // Init widget let widget = Rc::new(Widget::new( - &identity.widget.gobject, &home.widget.gobject, &history.widget.gobject, &reload.widget.gobject, @@ -62,7 +57,6 @@ impl Navigation { bookmark, history, home, - identity, profile, reload, request, @@ -75,7 +69,14 @@ impl Navigation { pub fn update(&self, progress_fraction: Option) { let request_text = self.request.widget.entry.text(); - self.identity.update( + self.bookmark + .update(self.profile.bookmark.get(&request_text).is_ok()); + self.history.update(); + self.home.update(self.request.uri()); + self.reload.update(!request_text.is_empty()); + self.request.update( + progress_fraction, + !request_text.is_empty() && request_text.starts_with("gemini"), self.profile .identity .gemini @@ -83,14 +84,7 @@ impl Navigation { .memory .match_scope(&request_text) .is_some(), - !request_text.is_empty() && request_text.starts_with("gemini"), ); - self.bookmark - .update(self.profile.bookmark.get(&request_text).is_ok()); - self.history.update(); - self.home.update(self.request.uri()); - self.reload.update(!request_text.is_empty()); - self.request.update(progress_fraction); } pub fn clean( diff --git a/src/app/browser/window/tab/item/page/navigation/identity.rs b/src/app/browser/window/tab/item/page/navigation/identity.rs deleted file mode 100644 index d3ebbfd0..00000000 --- a/src/app/browser/window/tab/item/page/navigation/identity.rs +++ /dev/null @@ -1,29 +0,0 @@ -mod widget; -use widget::Widget; - -use crate::app::browser::window::tab::item::Action; -use std::rc::Rc; - -pub struct Identity { - action: Rc, - pub widget: Rc, -} - -impl Identity { - // Construct - pub fn new(action: Rc) -> Self { - Self { - action: action.clone(), - widget: Rc::new(Widget::new(action)), - } - } - - // Actions - pub fn update(&self, is_auth: bool, is_enabled: bool) { - // Update action status - self.action.ident.simple_action.set_enabled(is_enabled); - - // Update widget - self.widget.update(is_auth, is_enabled) - } -} diff --git a/src/app/browser/window/tab/item/page/navigation/identity/widget.rs b/src/app/browser/window/tab/item/page/navigation/identity/widget.rs deleted file mode 100644 index 08d2935b..00000000 --- a/src/app/browser/window/tab/item/page/navigation/identity/widget.rs +++ /dev/null @@ -1,35 +0,0 @@ -use crate::app::browser::window::tab::item::Action; -use gtk::{ - prelude::{ButtonExt, WidgetExt}, - Button, -}; -use std::rc::Rc; - -pub struct Widget { - pub gobject: Button, -} - -impl Widget { - // Construct - pub fn new(action: Rc) -> Self { - // Init gobject - let gobject = Button::builder() - .icon_name("avatar-default-symbolic") - .tooltip_text("Identity") - //.sensitive(false) - .build(); - - // Init events @TODO dialog window required - gobject.connect_clicked(move |_| action.ident.activate()); - - // Return activated `Self` - Self { gobject } - } - - // Actions - pub fn update(&self, is_auth: bool, is_enabled: bool) { - self.gobject.set_sensitive(is_enabled); - self.gobject - .set_css_classes(if is_auth { &["success"] } else { &[] }); - } -} 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 961269f1..f9008374 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -25,8 +25,17 @@ impl Request { } // Actions - pub fn update(&self, progress_fraction: Option) { - self.widget.update(progress_fraction); + pub fn update( + &self, + progress_fraction: Option, + is_identity_applicable: bool, + is_identity_active: bool, + ) { + self.widget.update( + progress_fraction, + is_identity_applicable, + is_identity_active, + ); } pub fn clean( 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 4c09eb2a..f34f1827 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,7 +2,6 @@ mod database; use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction}; use gtk::{ - gio::Icon, glib::{timeout_add_local, ControlFlow, SourceId}, prelude::{EditableExt, EntryExt, WidgetExt}, Entry, EntryIconPosition, StateFlags, @@ -15,7 +14,16 @@ use std::{ }; const PLACEHOLDER_TEXT: &str = "URL or search term..."; + const GO_TOOLTIP_TEXT: &str = "Go to the address"; +const GO_ICON_NAME: &str = "pan-end-symbolic"; + +const IDENTITY_TOOLTIP_TEXT: (&str, &str) = ( + "Identity", + "Identity feature not available for this location", +); +const IDENTITY_ICON_NAME: (&str, &str) = + ("avatar-default-symbolic", "applications-system-symbolic"); // Progress bar animation setup const PROGRESS_ANIMATION_STEP: f64 = 0.05; @@ -49,31 +57,19 @@ impl Widget { .hexpand(true) .build(); - // Init `go` button feature (if icon available) - let go = match Icon::for_string("pan-end-symbolic") { - Ok(icon) => { - entry.set_secondary_icon_gicon(Some(&icon)); - entry.set_secondary_icon_tooltip_text(Some(GO_TOOLTIP_TEXT)); - Some(icon) - } - Err(e) => { - println!("{e}"); // drop notice @TODO - None - } - }; + entry.set_primary_icon_name(Some(IDENTITY_ICON_NAME.0)); + entry.set_primary_icon_tooltip_text(Some(IDENTITY_TOOLTIP_TEXT.0)); + + entry.set_secondary_icon_name(Some(GO_ICON_NAME)); + entry.set_secondary_icon_tooltip_text(Some(GO_TOOLTIP_TEXT)); // Connect events entry.connect_icon_release({ let tab_action = tab_action.clone(); - let go = go.clone(); move |this, position| match position { - EntryIconPosition::Primary => todo!(), - EntryIconPosition::Secondary => { - if go.is_some() { - tab_action.load.activate(Some(&this.text()), true); - } - } - _ => println!("Undefined icon position"), // drop notice @TODO + EntryIconPosition::Primary => tab_action.ident.activate(), + EntryIconPosition::Secondary => tab_action.load.activate(Some(&this.text()), true), + _ => todo!(), // unexpected } }); @@ -190,8 +186,36 @@ impl Widget { Ok(()) } - pub fn update(&self, progress_fraction: Option) { - // Skip update animation for None value + pub fn update( + &self, + progress_fraction: Option, + is_identity_applicable: bool, + is_identity_active: bool, + ) { + // Update identity + self.entry + .set_primary_icon_activatable(is_identity_applicable); + self.entry + .set_primary_icon_sensitive(is_identity_applicable); + + if is_identity_applicable { + self.entry.set_primary_icon_name(Some(IDENTITY_ICON_NAME.0)); + self.entry + .set_primary_icon_tooltip_text(Some(IDENTITY_TOOLTIP_TEXT.0)); + } else { + self.entry.set_primary_icon_name(Some(IDENTITY_ICON_NAME.1)); + self.entry + .set_primary_icon_tooltip_text(Some(IDENTITY_TOOLTIP_TEXT.1)); + } + + let identity = self.entry.first_child().unwrap(); // @TODO handle + identity.remove_css_class("success"); + if is_identity_active { + identity.add_css_class("success"); + } + + // Update progress + // * skip update animation for None value if let Some(value) = progress_fraction { // Update shared fraction on new value was changed if value != self.progress.fraction.replace(value) { diff --git a/src/app/browser/window/tab/item/page/navigation/widget.rs b/src/app/browser/window/tab/item/page/navigation/widget.rs index fc51628f..51ca2f57 100644 --- a/src/app/browser/window/tab/item/page/navigation/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/widget.rs @@ -13,7 +13,6 @@ pub struct Widget { impl Widget { // Construct pub fn new( - auth: &impl IsA, base: &impl IsA, history: &impl IsA, reload: &impl IsA, @@ -33,7 +32,6 @@ impl Widget { gobject.append(reload); gobject.append(request); gobject.append(bookmark); - gobject.append(auth); Self { gobject } }