Skip to content

Commit

Permalink
fix identity request implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Jan 29, 2025
1 parent 2dc6154 commit f581f1d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
5 changes: 5 additions & 0 deletions src/app/browser/window/tab/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ impl Item {
}
});

action.identity.connect_activate({
let page = page.clone();
move |_, _| page.navigation.identity()
});

action.reload.connect_activate({
let page = page.clone();
let client = client.clone();
Expand Down
4 changes: 1 addition & 3 deletions src/app/browser/window/tab/item/action/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ pub trait Identity {

impl Identity for SimpleAction {
fn identity() -> Self {
let identity = SimpleAction::new(&uuid_string_random(), None);
identity.set_enabled(false);
identity
SimpleAction::new(&uuid_string_random(), None)
}
}
4 changes: 4 additions & 0 deletions src/app/browser/window/tab/item/page/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ impl Navigation {
self.request.grab_focus()
}

pub fn identity(&self) {
self.request.identity(&self.profile)
}

pub fn update(&self) {
self.bookmark.update(&self.profile, &self.request);
self.request.update(&self.profile);
Expand Down
49 changes: 26 additions & 23 deletions src/app/browser/window/tab/item/page/navigation/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub trait Request {
) -> Result<(), String>;

fn update(&self, profile: &Profile);
fn identity(&self, profile: &Rc<Profile>);

// Setters

Expand Down Expand Up @@ -72,27 +73,12 @@ impl Request for Entry {

// Connect events
entry.connect_icon_release({
let item_action = item_action.clone();
let profile = profile.clone();
move |this, position| match position {
EntryIconPosition::Primary => {
if let Some(request) = this.uri() {
if ["gemini", "titan"].contains(&request.scheme().as_str()) {
return identity::default(&profile, &request, {
let item_action = item_action.clone();
let profile = profile.clone();
let this = this.clone();
move || {
this.update(&profile);
item_action.load.activate(Some(&this.text()), false);
} // on apply
})
.present(Some(this));
}
}
identity::unsupported().present(Some(this));
EntryIconPosition::Primary => this.identity(&profile),
EntryIconPosition::Secondary => {
this.activate();
}
EntryIconPosition::Secondary => item_action.load.activate(Some(&this.text()), true),
_ => todo!(), // unexpected
}
});
Expand Down Expand Up @@ -121,15 +107,15 @@ impl Request for Entry {

entry.connect_activate({
let item_action = item_action.clone();
move |entry| {
item_action.load.activate(Some(&entry.text()), true);
move |this| {
item_action.load.activate(Some(&this.text()), true);
}
});

entry.connect_state_flags_changed({
// Define last focus state container
let has_focus = Cell::new(false);
move |entry, state| {
move |this, state| {
// Select entire text on first click (release)
// this behavior implemented in most web-browsers,
// to simply overwrite current request with new value
Expand All @@ -138,9 +124,9 @@ impl Request for Entry {
// * This is experimental feature does not follow native GTK behavior @TODO make optional
if !has_focus.take()
&& state.contains(StateFlags::ACTIVE | StateFlags::FOCUS_WITHIN)
&& entry.selection_bounds().is_none()
&& this.selection_bounds().is_none()
{
entry.select_region(0, entry.text_length().into());
this.select_region(0, this.text_length().into());
}
// Update last focus state
has_focus.replace(state.contains(StateFlags::FOCUS_WITHIN));
Expand Down Expand Up @@ -258,6 +244,23 @@ impl Request for Entry {
}
}

fn identity(&self, profile: &Rc<Profile>) {
if let Some(uri) = self.uri() {
if ["gemini", "titan"].contains(&uri.scheme().as_str()) {
return identity::default(profile, &uri, {
let profile = profile.clone();
let this = self.clone();
move || {
this.update(&profile);
this.emit_activate();
} // on apply
})
.present(Some(self));
}
}
identity::unsupported().present(Some(self));
}

// Setters

fn to_download(&self) {
Expand Down

0 comments on commit f581f1d

Please sign in to comment.