Browse Source

remove action delegation

master
yggverse 2 months ago
parent
commit
ee095163da
  1. 54
      src/browser/main/tab/page.rs
  2. 10
      src/browser/main/tab/page/navigation.rs
  3. 6
      src/browser/main/tab/page/navigation/request.rs

54
src/browser/main/tab/page.rs

@ -25,7 +25,7 @@ pub struct Page {
widget: Box, widget: Box,
// Actions // Actions
action_page_open: Arc<SimpleAction>, action_page_open: Arc<SimpleAction>,
// action_tab_page_navigation_reload: Arc<SimpleAction>, action_tab_page_navigation_reload: Arc<SimpleAction>,
action_update: Arc<SimpleAction>, action_update: Arc<SimpleAction>,
// Components // Components
navigation: Arc<Navigation>, navigation: Arc<Navigation>,
@ -83,6 +83,7 @@ impl Page {
// Init events // Init events
action_page_open.connect_activate({ action_page_open.connect_activate({
let navigation = navigation.clone(); let navigation = navigation.clone();
let action_tab_page_navigation_reload = action_tab_page_navigation_reload.clone();
move |_, request| { move |_, request| {
// Convert to GString // Convert to GString
let request = GString::from( let request = GString::from(
@ -103,9 +104,10 @@ impl Page {
} }
// Update // Update
navigation.set_request_text( navigation.set_request_text(&request);
&request, true, // activate (page reload)
); // Reload page
action_tab_page_navigation_reload.activate(None);
} }
}); });
@ -115,7 +117,7 @@ impl Page {
widget, widget,
// Actions // Actions
action_page_open, action_page_open,
// action_tab_page_navigation_reload, action_tab_page_navigation_reload,
action_update, action_update,
// Components // Components
content, content,
@ -139,19 +141,21 @@ impl Page {
pub fn navigation_history_back(&self) { pub fn navigation_history_back(&self) {
if let Some(request) = self.navigation.history_back(true) { if let Some(request) = self.navigation.history_back(true) {
// Update without history record // Update
self.navigation.set_request_text( self.navigation.set_request_text(&request);
&request, true, // activate (page reload)
); // Reload page
self.action_tab_page_navigation_reload.activate(None);
} }
} }
pub fn navigation_history_forward(&self) { pub fn navigation_history_forward(&self) {
if let Some(request) = self.navigation.history_forward(true) { if let Some(request) = self.navigation.history_forward(true) {
// Update without history record // Update
self.navigation.set_request_text( self.navigation.set_request_text(&request);
&request, true, // activate (page reload)
); // Reload page
self.action_tab_page_navigation_reload.activate(None);
} }
} }
@ -423,10 +427,11 @@ impl Page {
// Make sure new request conversible to valid URI // Make sure new request conversible to valid URI
match Uri::parse(&request_text, UriFlags::NONE) { match Uri::parse(&request_text, UriFlags::NONE) {
Ok(_) => { Ok(_) => {
self.navigation.set_request_text( // Update
&request_text, self.navigation.set_request_text(&request_text);
true, // activate (page reload)
); // Reload page
self.action_tab_page_navigation_reload.activate(None);
} }
Err(_) => { Err(_) => {
// @TODO any action here? // @TODO any action here?
@ -434,13 +439,16 @@ impl Page {
} }
} else { } else {
// Plain text given, make search request to default provider // Plain text given, make search request to default provider
self.navigation.set_request_text( let request_text = gformat!(
&gformat!( "gemini://tlgs.one/search?{}",
"gemini://tlgs.one/search?{}", Uri::escape_string(&request_text, None, false)
Uri::escape_string(&request_text, None, false)
),
true, // activate (page reload)
); );
// Update
self.navigation.set_request_text(&request_text);
// Reload page
self.action_tab_page_navigation_reload.activate(None);
} }
} }
}; };

10
src/browser/main/tab/page/navigation.rs

@ -110,13 +110,11 @@ impl Navigation {
} }
// Setters // Setters
pub fn set_request_text(&self, value: &GString, activate: bool) { pub fn set_request_text(&self, value: &GString) {
if activate { // Focus out from content area on activate the link @TODO
// Focus out from content area on activate the link @TODO self.widget.child_focus(DirectionType::Right);
self.widget.child_focus(DirectionType::Right);
}
self.request.set_text(value, activate); self.request.set_text(value);
} }
// Getters // Getters

6
src/browser/main/tab/page/navigation/request.rs

@ -103,12 +103,8 @@ impl Request {
} }
// Setters // Setters
pub fn set_text(&self, value: &GString, activate: bool) { pub fn set_text(&self, value: &GString) {
self.widget.set_text(value); self.widget.set_text(value);
if activate {
self.widget.emit_activate();
}
} }
// Getters // Getters

Loading…
Cancel
Save