mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
begin window actions group implementation
This commit is contained in:
parent
5f280efaf3
commit
36b86ef5cf
15 changed files with 145 additions and 63 deletions
65
src/app/browser/window/action.rs
Normal file
65
src/app/browser/window/action.rs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
mod append;
|
||||
|
||||
use append::Append;
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleActionGroup,
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::ActionMapExt,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
/// [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) wrapper for `Browser` actions
|
||||
pub struct Action {
|
||||
// Actions
|
||||
append: Rc<Append>,
|
||||
// Group
|
||||
id: GString,
|
||||
gobject: SimpleActionGroup,
|
||||
}
|
||||
|
||||
impl Action {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
// Init actions
|
||||
let append = Rc::new(Append::new());
|
||||
|
||||
// Generate unique group ID
|
||||
let id = uuid_string_random();
|
||||
|
||||
// Init group
|
||||
let gobject = SimpleActionGroup::new();
|
||||
|
||||
// Add action to given group
|
||||
gobject.add_action(append.gobject());
|
||||
|
||||
// Done
|
||||
Self {
|
||||
append,
|
||||
id,
|
||||
gobject,
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
/// Get reference `Append` action
|
||||
pub fn append(&self) -> &Rc<Append> {
|
||||
&self.append
|
||||
}
|
||||
|
||||
/// Get auto-generated name for action group
|
||||
/// * useful for manual relationship with GObjects or as the `detailed_name`
|
||||
/// for [Accels](https://docs.gtk.org/gtk4/method.Application.set_accels_for_action.html) or
|
||||
/// [Menu](https://docs.gtk.org/gio/class.Menu.html) builder
|
||||
pub fn id(&self) -> &GString {
|
||||
&self.id
|
||||
}
|
||||
|
||||
/// Get reference to [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) GObject
|
||||
pub fn gobject(&self) -> &SimpleActionGroup {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,13 @@ impl Append {
|
|||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
pub fn activate(&self) {
|
||||
self.gobject.activate(None);
|
||||
}
|
||||
|
||||
// Events
|
||||
|
||||
/// Define callback function for
|
||||
|
|
@ -5,6 +5,7 @@ use bar::Bar;
|
|||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use adw::{TabView, ToolbarView};
|
||||
use gtk::gio::SimpleAction;
|
||||
use std::rc::Rc;
|
||||
|
|
@ -18,7 +19,7 @@ impl Header {
|
|||
pub fn new_rc(
|
||||
// Actions
|
||||
browser_action: Rc<BrowserAction>,
|
||||
action_page_new: SimpleAction,
|
||||
window_action: Rc<WindowAction>,
|
||||
action_page_close: SimpleAction,
|
||||
action_page_close_all: SimpleAction,
|
||||
action_page_home: SimpleAction,
|
||||
|
|
@ -32,7 +33,7 @@ impl Header {
|
|||
// Init components
|
||||
let bar = Bar::new_rc(
|
||||
browser_action,
|
||||
action_page_new,
|
||||
window_action,
|
||||
action_page_close,
|
||||
action_page_close_all,
|
||||
action_page_home,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use tab::Tab;
|
|||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use adw::TabView;
|
||||
use gtk::{gio::SimpleAction, Box};
|
||||
use std::rc::Rc;
|
||||
|
|
@ -21,7 +22,7 @@ impl Bar {
|
|||
// Construct
|
||||
pub fn new_rc(
|
||||
browser_action: Rc<BrowserAction>,
|
||||
action_page_new: SimpleAction,
|
||||
window_action: Rc<WindowAction>,
|
||||
action_page_close: SimpleAction,
|
||||
action_page_close_all: SimpleAction,
|
||||
action_page_home: SimpleAction,
|
||||
|
|
@ -33,10 +34,10 @@ impl Bar {
|
|||
) -> Rc<Self> {
|
||||
// Init components
|
||||
let control = Control::new_rc();
|
||||
let tab = Tab::new_rc(action_page_new.clone(), view);
|
||||
let tab = Tab::new_rc(window_action.clone(), view);
|
||||
let menu = Menu::new_rc(
|
||||
browser_action,
|
||||
action_page_new,
|
||||
window_action,
|
||||
action_page_close,
|
||||
action_page_close_all,
|
||||
action_page_home,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ mod widget;
|
|||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use gtk::{
|
||||
gio::{self, SimpleAction},
|
||||
glib::{gformat, GString},
|
||||
|
|
@ -18,7 +19,7 @@ pub struct Menu {
|
|||
impl Menu {
|
||||
pub fn new_rc(
|
||||
browser_action: Rc<BrowserAction>,
|
||||
action_page_new: SimpleAction,
|
||||
window_action: Rc<WindowAction>,
|
||||
action_page_close: SimpleAction,
|
||||
action_page_close_all: SimpleAction,
|
||||
action_page_home: SimpleAction,
|
||||
|
|
@ -32,7 +33,12 @@ impl Menu {
|
|||
|
||||
// Main > Page
|
||||
let main_page = gio::Menu::new();
|
||||
main_page.append(Some("New"), Some(&detailed_action_name(&action_page_new)));
|
||||
main_page.append(Some("New"), Some(&gformat!(
|
||||
"{}.{}",
|
||||
window_action.id(),
|
||||
window_action.append().id()
|
||||
)));
|
||||
|
||||
main_page.append(Some("Reload"), Some(&detailed_action_name(&action_page_reload)));
|
||||
main_page.append(Some("Pin"), Some(&detailed_action_name(&action_page_pin)));
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ mod widget;
|
|||
use append::Append;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use adw::{TabBar, TabView};
|
||||
use gtk::gio::SimpleAction;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Tab {
|
||||
|
|
@ -14,9 +14,9 @@ pub struct Tab {
|
|||
|
||||
impl Tab {
|
||||
// Construct
|
||||
pub fn new_rc(action_page_new: SimpleAction, view: &TabView) -> Rc<Self> {
|
||||
pub fn new_rc(window_action: Rc<WindowAction>, view: &TabView) -> Rc<Self> {
|
||||
Rc::new(Self {
|
||||
widget: Widget::new_rc(view, Append::new_rc(action_page_new).gobject()),
|
||||
widget: Widget::new_rc(view, Append::new_rc(window_action).gobject()),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ mod widget;
|
|||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{gio::SimpleAction, Button};
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use gtk::Button;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Append {
|
||||
|
|
@ -11,9 +12,9 @@ pub struct Append {
|
|||
|
||||
impl Append {
|
||||
// Construct
|
||||
pub fn new_rc(action_page_new: SimpleAction) -> Rc<Self> {
|
||||
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
|
||||
Rc::new(Self {
|
||||
widget: Widget::new_rc(action_page_new),
|
||||
widget: Widget::new_rc(window_action),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt},
|
||||
Align, Button,
|
||||
};
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use gtk::{prelude::ButtonExt, Align, Button};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Widget {
|
||||
|
|
@ -11,7 +8,7 @@ pub struct Widget {
|
|||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_rc(action_page_new: SimpleAction) -> Rc<Self> {
|
||||
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
|
||||
// Init gobject
|
||||
let gobject = Button::builder()
|
||||
.icon_name("tab-new-symbolic")
|
||||
|
|
@ -21,9 +18,7 @@ impl Widget {
|
|||
.build();
|
||||
|
||||
// Init events
|
||||
gobject.connect_clicked(move |_| {
|
||||
action_page_new.activate(None);
|
||||
});
|
||||
gobject.connect_clicked(move |_| window_action.append().activate());
|
||||
|
||||
Rc::new(Self { gobject })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use menu::Menu;
|
|||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use adw::TabView;
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
|
|
@ -24,6 +25,7 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
|||
pub struct Tab {
|
||||
// Global actions
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
// Page actions
|
||||
action_page_home: SimpleAction,
|
||||
action_page_history_back: SimpleAction,
|
||||
|
|
@ -39,6 +41,7 @@ impl Tab {
|
|||
// Construct
|
||||
pub fn new_rc(
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
action_page_close: SimpleAction,
|
||||
action_page_close_all: SimpleAction,
|
||||
action_page_home: SimpleAction,
|
||||
|
|
@ -74,6 +77,7 @@ impl Tab {
|
|||
let gobject = widget.gobject().clone();
|
||||
// Actions
|
||||
let browser_action = browser_action.clone();
|
||||
let window_action = window_action.clone();
|
||||
let action = action.clone();
|
||||
|
||||
let action_page_home = action_page_home.clone();
|
||||
|
|
@ -87,6 +91,7 @@ impl Tab {
|
|||
&gobject,
|
||||
// Global actions
|
||||
browser_action.clone(),
|
||||
window_action.clone(),
|
||||
action.clone(),
|
||||
// Page actions
|
||||
action_page_home.clone(),
|
||||
|
|
@ -174,6 +179,7 @@ impl Tab {
|
|||
// Return activated struct
|
||||
Rc::new(Self {
|
||||
browser_action,
|
||||
window_action,
|
||||
// Global actions
|
||||
action_page_home,
|
||||
action_page_history_back,
|
||||
|
|
@ -192,6 +198,7 @@ impl Tab {
|
|||
let item = Item::new_rc(
|
||||
self.gobject(),
|
||||
self.browser_action.clone(),
|
||||
self.window_action.clone(),
|
||||
// Local actions
|
||||
self.action.clone(),
|
||||
// Global actions
|
||||
|
|
@ -337,6 +344,7 @@ impl Tab {
|
|||
transaction,
|
||||
&record.id,
|
||||
self.browser_action.clone(),
|
||||
self.window_action.clone(),
|
||||
self.action.clone(),
|
||||
self.action_page_home.clone(),
|
||||
self.action_page_history_back.clone(),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue