register new local action

This commit is contained in:
yggverse 2024-10-14 05:57:33 +03:00
parent 7fdc053051
commit ab73b9de5b
7 changed files with 60 additions and 24 deletions

View File

@ -38,7 +38,6 @@ impl Window {
) -> Self {
// Init components
let tab = Tab::new_arc(
action_tab_append.clone(),
action_tab_page_navigation_base.clone(),
action_tab_page_navigation_history_back.clone(),
action_tab_page_navigation_history_forward.clone(),

View File

@ -17,8 +17,9 @@ use std::{cell::RefCell, collections::HashMap, sync::Arc};
// Main
pub struct Tab {
// Actions
action_tab_append: Arc<SimpleAction>,
// Local actions
action_tab_open: Arc<SimpleAction>,
// Global actions
action_tab_page_navigation_base: Arc<SimpleAction>,
action_tab_page_navigation_history_back: Arc<SimpleAction>,
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
@ -34,7 +35,6 @@ impl Tab {
// Construct
pub fn new_arc(
// Actions
action_tab_append: Arc<SimpleAction>,
action_tab_page_navigation_base: Arc<SimpleAction>,
action_tab_page_navigation_history_back: Arc<SimpleAction>,
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
@ -73,10 +73,45 @@ impl Tab {
}
});
action_tab_open.connect_activate({
let index = index.clone();
let gobject = widget.gobject().clone();
// Actions
let action_tab_open = action_tab_open.clone();
let action_tab_page_navigation_base = action_tab_page_navigation_base.clone();
let action_tab_page_navigation_history_back =
action_tab_page_navigation_history_back.clone();
let action_tab_page_navigation_history_forward =
action_tab_page_navigation_history_forward.clone();
let action_tab_page_navigation_reload = action_tab_page_navigation_reload.clone();
let action_update = action_update.clone();
move |_, _| {
// Init new tab item
let item = Item::new_arc(
&gobject,
// Local actions
action_tab_open.clone(),
// Global actions
action_tab_page_navigation_base.clone(),
action_tab_page_navigation_history_back.clone(),
action_tab_page_navigation_history_forward.clone(),
action_tab_page_navigation_reload.clone(),
action_update.clone(),
// Options
false,
false, // open on background
);
// Register dynamically created tab components in the HashMap index
index.borrow_mut().insert(item.id(), item.clone());
}
});
// Return activated struct
Arc::new(Self {
// Define action links
action_tab_append,
// Local actions
action_tab_open,
// Global actions
action_tab_page_navigation_base,
action_tab_page_navigation_history_back,
action_tab_page_navigation_history_forward,
@ -94,8 +129,9 @@ impl Tab {
// Init new tab item
let item = Item::new_arc(
self.gobject(),
// Actions
self.action_tab_append.clone(),
// Local actions
self.action_tab_open.clone(),
// Global actions
self.action_tab_page_navigation_base.clone(),
self.action_tab_page_navigation_history_back.clone(),
self.action_tab_page_navigation_history_forward.clone(),
@ -217,7 +253,7 @@ impl Tab {
self.gobject(),
transaction,
&record.id,
self.action_tab_append.clone(),
self.action_tab_open.clone(),
self.action_tab_page_navigation_base.clone(),
self.action_tab_page_navigation_history_back.clone(),
self.action_tab_page_navigation_history_forward.clone(),

View File

@ -28,7 +28,7 @@ impl Item {
pub fn new_arc(
tab_view: &TabView,
// Actions
action_tab_append: Arc<SimpleAction>,
action_tab_open: Arc<SimpleAction>,
action_tab_page_navigation_base: Arc<SimpleAction>,
action_tab_page_navigation_history_back: Arc<SimpleAction>,
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
@ -44,7 +44,8 @@ impl Item {
// Init components
let page = Page::new_arc(
id.clone(),
action_tab_append.clone(),
// Actions
action_tab_open.clone(),
action_tab_page_navigation_base.clone(),
action_tab_page_navigation_history_back.clone(),
action_tab_page_navigation_history_forward.clone(),
@ -125,7 +126,7 @@ impl Item {
transaction: &Transaction,
app_browser_window_tab_id: &i64,
// Actions
action_tab_append: Arc<SimpleAction>,
action_tab_open: Arc<SimpleAction>,
action_tab_page_navigation_base: Arc<SimpleAction>,
action_tab_page_navigation_history_back: Arc<SimpleAction>,
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
@ -141,7 +142,7 @@ impl Item {
let item = Item::new_arc(
tab_view,
// Actions
action_tab_append.clone(),
action_tab_open.clone(),
action_tab_page_navigation_base.clone(),
action_tab_page_navigation_history_back.clone(),
action_tab_page_navigation_history_forward.clone(),

View File

@ -44,7 +44,7 @@ impl Page {
// Construct
pub fn new_arc(
id: GString,
action_tab_append: Arc<SimpleAction>,
action_tab_open: Arc<SimpleAction>,
action_tab_page_navigation_base: Arc<SimpleAction>,
action_tab_page_navigation_history_back: Arc<SimpleAction>,
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
@ -59,7 +59,7 @@ impl Page {
// Init components
let content = Arc::new(Content::new(
action_tab_append.clone(),
action_tab_open.clone(),
action_page_open.clone(),
));

View File

@ -25,16 +25,16 @@ pub struct Content {
// GTK
widget: Box,
// Actions
action_tab_append: Arc<SimpleAction>,
action_tab_open: Arc<SimpleAction>,
action_page_open: Arc<SimpleAction>,
}
impl Content {
// Construct
pub fn new(action_tab_append: Arc<SimpleAction>, action_page_open: Arc<SimpleAction>) -> Self {
pub fn new(action_tab_open: Arc<SimpleAction>, action_page_open: Arc<SimpleAction>) -> Self {
Self {
widget: Box::builder().orientation(Orientation::Vertical).build(),
action_tab_append,
action_tab_open,
action_page_open,
}
}
@ -52,7 +52,7 @@ impl Content {
let child = Text::gemini(
data,
base,
self.action_tab_append.clone(),
self.action_tab_open.clone(),
self.action_page_open.clone(),
);

View File

@ -23,11 +23,11 @@ impl Gemini {
pub fn new(
gemtext: &str,
base: &Uri,
action_tab_append: Arc<SimpleAction>,
action_tab_open: Arc<SimpleAction>,
action_page_open: Arc<SimpleAction>,
) -> Self {
// Init components
let reader = Reader::new_arc(gemtext, base, action_tab_append, action_page_open);
let reader = Reader::new_arc(gemtext, base, action_tab_open, action_page_open);
let widget = Widget::new_arc(&reader.gobject());

View File

@ -26,7 +26,7 @@ impl Reader {
pub fn new_arc(
gemtext: &str,
base: &Uri,
action_tab_append: Arc<SimpleAction>,
action_tab_open: Arc<SimpleAction>,
action_page_open: Arc<SimpleAction>,
) -> Arc<Self> {
// Init default values
@ -197,8 +197,8 @@ impl Reader {
for tag in iter.tags() {
// Tag is link
if let Some(_) = _links_.get(&tag) {
return action_tab_append.activate(None); // @TODO implement URI option
// @TODO action does not work after focus out
return action_tab_open.activate(None); // @TODO implement URI option
// @TODO action does not work after focus out
}
}
}