begin window actions group implementation

This commit is contained in:
yggverse 2024-11-10 08:51:08 +02:00
parent 5f280efaf3
commit 36b86ef5cf
15 changed files with 145 additions and 63 deletions

View file

@ -1,7 +1,5 @@
mod append;
mod open;
use append::Append;
use open::Open;
use gtk::{
@ -14,7 +12,6 @@ use std::rc::Rc;
/// [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) wrapper for `Browser` actions
pub struct Action {
// Actions
append: Rc<Append>,
open: Rc<Open>,
// Group
id: GString,
@ -27,7 +24,6 @@ impl Action {
/// Create new `Self`
pub fn new() -> Self {
// Init actions
let append = Rc::new(Append::new());
let open = Rc::new(Open::new());
// Generate unique group ID
@ -37,25 +33,14 @@ impl Action {
let gobject = SimpleActionGroup::new();
// Add action to given group
gobject.add_action(append.gobject());
gobject.add_action(open.gobject());
// Done
Self {
append,
open,
id,
gobject,
}
Self { open, id, gobject }
}
// Getters
/// Get reference `Append` action
pub fn append(&self) -> &Rc<Append> {
&self.append
}
/// Get reference `Open` action
pub fn open(&self) -> &Rc<Open> {
&self.open

View file

@ -1,41 +0,0 @@
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, GString},
prelude::ActionExt,
};
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Close` action of `Browser` group
pub struct Append {
gobject: SimpleAction,
}
impl Append {
// Constructors
/// Create new `Self`
pub fn new() -> Self {
Self {
gobject: SimpleAction::new(&uuid_string_random(), None),
}
}
// Events
/// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
pub fn connect_activate(&self, callback: impl Fn() + 'static) {
self.gobject.connect_activate(move |_, _| callback());
}
// Getters
/// Get reference to [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) GObject
pub fn gobject(&self) -> &SimpleAction {
&self.gobject
}
/// Get auto-generated [action name](https://docs.gtk.org/gio/property.SimpleAction.name.html)
pub fn id(&self) -> GString {
self.gobject.name()
}
}

View file

@ -7,6 +7,7 @@ use page::Page;
use widget::Widget;
use crate::app::browser::action::Action as BrowserAction;
use crate::app::browser::window::action::Action as WindowAction;
use crate::app::browser::window::tab::action::Action as TabAction;
use adw::{TabPage, TabView};
use gtk::{
@ -31,6 +32,7 @@ impl Item {
tab_view: &TabView,
// Global actions
browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
// @TODO
action_page_home: SimpleAction,
@ -132,6 +134,7 @@ impl Item {
app_browser_window_tab_id: &i64,
// Actions
browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
action_page_home: SimpleAction,
action_page_history_back: SimpleAction,
@ -148,6 +151,7 @@ impl Item {
tab_view,
// Actions
browser_action.clone(),
window_action.clone(),
tab_action.clone(),
action_page_home.clone(),
action_page_history_back.clone(),

View file

@ -33,25 +33,25 @@ impl Input {
// Setters
pub fn set_new_response(
&self,
tab_action: Rc<TabAction>,
action: Rc<TabAction>,
base: Uri,
title: Option<&str>,
size_limit: Option<usize>,
) {
self.widget.update(Some(
Response::new_rc(tab_action, base, title, size_limit).gobject(),
Response::new_rc(action, base, title, size_limit).gobject(),
));
}
pub fn set_new_sensitive(
&self,
tab_action: Rc<TabAction>,
action: Rc<TabAction>,
base: Uri,
title: Option<&str>,
max_length: Option<i32>,
) {
self.widget.update(Some(
Sensitive::new_rc(tab_action, base, title, max_length).gobject(),
Sensitive::new_rc(action, base, title, max_length).gobject(),
));
}