Skip to content

Commit

Permalink
separate update implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Jan 28, 2025
1 parent ab6375a commit 4203b91
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
11 changes: 9 additions & 2 deletions src/app/browser/window/tab/item/page/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ const MARGIN: i32 = 6;
const SPACING: i32 = 6;

pub struct Navigation {
profile: Rc<Profile>,
//home: Button,
//reload: Button,
//bookmark: Button,
bookmark: Button,
request: Entry,
pub g_box: Box,
}
Expand Down Expand Up @@ -62,10 +63,11 @@ impl Navigation {
g_box.append(&bookmark);

Self {
profile: profile.clone(),
//home,
request,
//reload,
//bookmark,
bookmark,
g_box,
}
}
Expand Down Expand Up @@ -135,6 +137,11 @@ impl Navigation {
self.request.grab_focus()
}

pub fn update(&self) {
self.bookmark.update(&self.profile, &self.request);
self.request.update(&self.profile);
}

// Setters

pub fn set_request(&self, value: &str) {
Expand Down
68 changes: 37 additions & 31 deletions src/app/browser/window/tab/item/page/navigation/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub trait Request {
app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<(), String>;

fn update(&self, profile: &Profile);

// Setters

fn to_download(&self);
Expand Down Expand Up @@ -96,37 +98,7 @@ impl Request for Entry {
.set_enabled(uri(&this.text()).is_some_and(|uri| uri.path().len() > 1));

// Update primary icon
this.first_child().unwrap().remove_css_class("success"); // @TODO handle

this.set_primary_icon_activatable(false);
this.set_primary_icon_sensitive(false);

match primary_icon::from(&this.text()) {
PrimaryIcon::Download { name, tooltip } => {
this.set_primary_icon_name(Some(name));
this.set_primary_icon_tooltip_text(Some(tooltip));
}
PrimaryIcon::Gemini { name, tooltip }
| PrimaryIcon::Titan { name, tooltip } => {
this.set_primary_icon_activatable(true);
this.set_primary_icon_sensitive(true);
this.set_primary_icon_name(Some(name));
if profile.identity.get(&strip_prefix(this.text())).is_some() {
this.first_child().unwrap().add_css_class("success"); // @TODO handle
this.set_primary_icon_tooltip_text(Some(tooltip.1));
} else {
this.set_primary_icon_tooltip_text(Some(tooltip.0));
}
}
PrimaryIcon::Search { name, tooltip } => {
this.set_primary_icon_name(Some(name));
this.set_primary_icon_tooltip_text(Some(tooltip));
}
PrimaryIcon::Source { name, tooltip } => {
this.set_primary_icon_name(Some(name));
this.set_primary_icon_tooltip_text(Some(tooltip));
}
}
this.update(&profile)
}
});

Expand Down Expand Up @@ -235,6 +207,40 @@ impl Request for Entry {
Ok(())
}

fn update(&self, profile: &Profile) {
// Update primary icon
self.first_child().unwrap().remove_css_class("success"); // @TODO handle

self.set_primary_icon_activatable(false);
self.set_primary_icon_sensitive(false);

match primary_icon::from(&self.text()) {
PrimaryIcon::Download { name, tooltip } => {
self.set_primary_icon_name(Some(name));
self.set_primary_icon_tooltip_text(Some(tooltip));
}
PrimaryIcon::Gemini { name, tooltip } | PrimaryIcon::Titan { name, tooltip } => {
self.set_primary_icon_activatable(true);
self.set_primary_icon_sensitive(true);
self.set_primary_icon_name(Some(name));
if profile.identity.get(&strip_prefix(self.text())).is_some() {
self.first_child().unwrap().add_css_class("success"); // @TODO handle
self.set_primary_icon_tooltip_text(Some(tooltip.1));
} else {
self.set_primary_icon_tooltip_text(Some(tooltip.0));
}
}
PrimaryIcon::Search { name, tooltip } => {
self.set_primary_icon_name(Some(name));
self.set_primary_icon_tooltip_text(Some(tooltip));
}
PrimaryIcon::Source { name, tooltip } => {
self.set_primary_icon_name(Some(name));
self.set_primary_icon_tooltip_text(Some(tooltip));
}
}
}

// Setters

fn to_download(&self) {
Expand Down

0 comments on commit 4203b91

Please sign in to comment.