add pin action to context menu

This commit is contained in:
yggverse 2024-11-04 23:04:57 +02:00
parent 2aed6691b9
commit 998f51e0fc
4 changed files with 30 additions and 18 deletions

View File

@ -147,8 +147,8 @@ impl Browser {
action_page_home.connect_activate({
let window = window.clone();
move |_, _| {
window.tab_page_navigation_home();
move |this, _| {
window.tab_page_navigation_home(page_position_from_action_state(this));
}
});
@ -173,8 +173,8 @@ impl Browser {
action_page_pin.connect_activate({
let window = window.clone();
move |_, _| {
window.tab_pin();
move |this, _| {
window.tab_pin(page_position_from_action_state(this));
}
});

View File

@ -44,6 +44,7 @@ impl Window {
action_page_home.clone(),
action_page_history_back.clone(),
action_page_history_forward.clone(),
action_page_pin.clone(),
action_page_reload.clone(),
action_update.clone(),
);
@ -82,8 +83,8 @@ impl Window {
self.tab.append(page_position);
}
pub fn tab_page_navigation_home(&self) {
self.tab.page_navigation_home();
pub fn tab_page_navigation_home(&self, page_position: Option<i32>) {
self.tab.page_navigation_home(page_position);
}
pub fn tab_page_navigation_history_back(&self) {
@ -108,8 +109,8 @@ impl Window {
self.tab.close_all();
}
pub fn tab_pin(&self) {
self.tab.pin();
pub fn tab_pin(&self, page_position: Option<i32>) {
self.tab.pin(page_position);
}
pub fn update(&self, id: &str) {

View File

@ -39,6 +39,7 @@ impl Tab {
action_page_home: SimpleAction,
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
action_page_pin: SimpleAction,
action_page_reload: SimpleAction,
action_update: SimpleAction,
) -> Arc<Self> {
@ -55,7 +56,12 @@ impl Tab {
menu.append(
Some("Reload"),
Some(&gformat!("win.{}", action_page_reload.name())),
); // @TODO resolve namespace outside
);
menu.append(
Some("Pin"),
Some(&gformat!("win.{}", action_page_pin.name())),
);
let navigation = Menu::new();
@ -89,6 +95,7 @@ impl Tab {
// Clone actions to update
let action_page_close = action_page_close.clone();
let action_page_home = action_page_home.clone();
let action_page_pin = action_page_pin.clone();
let action_page_reload = action_page_reload.clone();
move |tab_view, tab_page| {
// Setup state for selected page
@ -102,6 +109,7 @@ impl Tab {
// Update actions
action_page_close.change_state(&state);
action_page_home.change_state(&state);
action_page_pin.change_state(&state);
action_page_reload.change_state(&state);
}
});
@ -223,16 +231,12 @@ impl Tab {
}
// Toggle pin status for active tab
pub fn pin(&self) {
if let Some(page) = self.widget.gobject().selected_page() {
self.widget
.gobject()
.set_page_pinned(&page, !page.is_pinned()); // toggle
}
pub fn pin(&self, page_position: Option<i32>) {
self.widget.pin(page_position);
}
pub fn page_navigation_home(&self) {
if let Some(id) = self.widget.current_page_keyword() {
pub fn page_navigation_home(&self, page_position: Option<i32>) {
if let Some(id) = self.widget.page_keyword(page_position) {
if let Some(item) = self.index.borrow().get(&id) {
item.page_navigation_home();
}

View File

@ -32,7 +32,7 @@ impl Widget {
// Actions
/// Close page at given `position`, `None` to close selected page
/// Close page at given `position`, `None` to close selected page (if available)
/// * this action includes `pinned` pages, to prevent that:
/// * deactivate [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) outside if selected page should not be closed
/// * use native [TabView](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabView.html) API with `GObject` reference getter
@ -54,6 +54,13 @@ impl Widget {
}
}
/// Toggle pin for page at given `position`, `None` to pin selected page (if available)
pub fn pin(&self, position: Option<i32>) {
if let Some(page) = self.page(position) {
self.gobject.set_page_pinned(&page, !page.is_pinned()); // toggle
}
}
// Getters
pub fn current_page_keyword(&self) -> Option<GString> {