mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
create separated wrappers for history, close action group
This commit is contained in:
parent
4afa2c204c
commit
8113022cd4
22 changed files with 557 additions and 335 deletions
|
|
@ -1,9 +1,17 @@
|
|||
mod append;
|
||||
mod close;
|
||||
mod close_all;
|
||||
mod history_back;
|
||||
mod history_forward;
|
||||
mod home;
|
||||
mod pin;
|
||||
mod reload;
|
||||
|
||||
use append::Append;
|
||||
use close::Close;
|
||||
use close_all::CloseAll;
|
||||
use history_back::HistoryBack;
|
||||
use history_forward::HistoryForward;
|
||||
use home::Home;
|
||||
use pin::Pin;
|
||||
use reload::Reload;
|
||||
|
|
@ -19,6 +27,10 @@ use std::rc::Rc;
|
|||
pub struct Action {
|
||||
// Actions
|
||||
append: Rc<Append>,
|
||||
close_all: Rc<CloseAll>,
|
||||
close: Rc<Close>,
|
||||
history_back: Rc<HistoryBack>,
|
||||
history_forward: Rc<HistoryForward>,
|
||||
home: Rc<Home>,
|
||||
pin: Rc<Pin>,
|
||||
reload: Rc<Reload>,
|
||||
|
|
@ -34,6 +46,10 @@ impl Action {
|
|||
pub fn new() -> Self {
|
||||
// Init actions
|
||||
let append = Rc::new(Append::new());
|
||||
let close = Rc::new(Close::new());
|
||||
let close_all = Rc::new(CloseAll::new());
|
||||
let history_back = Rc::new(HistoryBack::new());
|
||||
let history_forward = Rc::new(HistoryForward::new());
|
||||
let home = Rc::new(Home::new());
|
||||
let pin = Rc::new(Pin::new());
|
||||
let reload = Rc::new(Reload::new());
|
||||
|
|
@ -46,6 +62,10 @@ impl Action {
|
|||
|
||||
// Add action to given group
|
||||
gobject.add_action(append.gobject());
|
||||
gobject.add_action(close_all.gobject());
|
||||
gobject.add_action(close.gobject());
|
||||
gobject.add_action(history_back.gobject());
|
||||
gobject.add_action(history_forward.gobject());
|
||||
gobject.add_action(home.gobject());
|
||||
gobject.add_action(pin.gobject());
|
||||
gobject.add_action(reload.gobject());
|
||||
|
|
@ -53,6 +73,10 @@ impl Action {
|
|||
// Done
|
||||
Self {
|
||||
append,
|
||||
close_all,
|
||||
close,
|
||||
history_back,
|
||||
history_forward,
|
||||
home,
|
||||
pin,
|
||||
reload,
|
||||
|
|
@ -68,6 +92,26 @@ impl Action {
|
|||
&self.append
|
||||
}
|
||||
|
||||
/// Get reference `CloseAll` action
|
||||
pub fn close_all(&self) -> &Rc<CloseAll> {
|
||||
&self.close_all
|
||||
}
|
||||
|
||||
/// Get reference `Close` action
|
||||
pub fn close(&self) -> &Rc<Close> {
|
||||
&self.close
|
||||
}
|
||||
|
||||
/// Get reference `HistoryBack` action
|
||||
pub fn history_back(&self) -> &Rc<HistoryBack> {
|
||||
&self.history_back
|
||||
}
|
||||
|
||||
/// Get reference `HistoryForward` action
|
||||
pub fn history_forward(&self) -> &Rc<HistoryForward> {
|
||||
&self.history_forward
|
||||
}
|
||||
|
||||
/// Get reference `Home` action
|
||||
pub fn home(&self) -> &Rc<Home> {
|
||||
&self.home
|
||||
|
|
|
|||
85
src/app/browser/window/action/close.rs
Normal file
85
src/app/browser/window/action/close.rs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::{ActionExt, ToVariant},
|
||||
};
|
||||
|
||||
// Defaults
|
||||
|
||||
/// C-compatible variant type
|
||||
const DEFAULT_STATE: i32 = -1;
|
||||
|
||||
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Close` action of `Window` group
|
||||
pub struct Close {
|
||||
gobject: SimpleAction,
|
||||
}
|
||||
|
||||
impl Close {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
gobject: SimpleAction::new_stateful(
|
||||
&uuid_string_random(),
|
||||
None,
|
||||
&DEFAULT_STATE.to_variant(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
pub fn activate(&self) {
|
||||
self.gobject.activate(None);
|
||||
}
|
||||
|
||||
/// Change action [state](https://docs.gtk.org/gio/method.SimpleAction.set_state.html)
|
||||
/// * set `DEFAULT_STATE` on `None`
|
||||
pub fn change_state(&self, state: Option<i32>) {
|
||||
self.gobject.change_state(
|
||||
&match state {
|
||||
Some(value) => value,
|
||||
None => DEFAULT_STATE,
|
||||
}
|
||||
.to_variant(),
|
||||
)
|
||||
}
|
||||
|
||||
// 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(Option<i32>) + 'static) {
|
||||
let state = self.state();
|
||||
self.gobject.connect_activate(move |_, _| callback(state));
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn state(&self) -> Option<i32> {
|
||||
let state = self
|
||||
.gobject
|
||||
.state()
|
||||
.expect("State value required")
|
||||
.get::<i32>()
|
||||
.expect("Parameter type does not match `i32`");
|
||||
|
||||
if state != DEFAULT_STATE {
|
||||
Some(state)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// 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()
|
||||
}
|
||||
}
|
||||
85
src/app/browser/window/action/close_all.rs
Normal file
85
src/app/browser/window/action/close_all.rs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::{ActionExt, ToVariant},
|
||||
};
|
||||
|
||||
// Defaults
|
||||
|
||||
/// C-compatible variant type
|
||||
const DEFAULT_STATE: i32 = -1;
|
||||
|
||||
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `CloseAll` action of `Window` group
|
||||
pub struct CloseAll {
|
||||
gobject: SimpleAction,
|
||||
}
|
||||
|
||||
impl CloseAll {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
gobject: SimpleAction::new_stateful(
|
||||
&uuid_string_random(),
|
||||
None,
|
||||
&DEFAULT_STATE.to_variant(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
pub fn activate(&self) {
|
||||
self.gobject.activate(None);
|
||||
}
|
||||
|
||||
/// Change action [state](https://docs.gtk.org/gio/method.SimpleAction.set_state.html)
|
||||
/// * set `DEFAULT_STATE` on `None`
|
||||
pub fn change_state(&self, state: Option<i32>) {
|
||||
self.gobject.change_state(
|
||||
&match state {
|
||||
Some(value) => value,
|
||||
None => DEFAULT_STATE,
|
||||
}
|
||||
.to_variant(),
|
||||
)
|
||||
}
|
||||
|
||||
// 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(Option<i32>) + 'static) {
|
||||
let state = self.state();
|
||||
self.gobject.connect_activate(move |_, _| callback(state));
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn state(&self) -> Option<i32> {
|
||||
let state = self
|
||||
.gobject
|
||||
.state()
|
||||
.expect("State value required")
|
||||
.get::<i32>()
|
||||
.expect("Parameter type does not match `i32`");
|
||||
|
||||
if state != DEFAULT_STATE {
|
||||
Some(state)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// 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()
|
||||
}
|
||||
}
|
||||
85
src/app/browser/window/action/history_back.rs
Normal file
85
src/app/browser/window/action/history_back.rs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::{ActionExt, ToVariant},
|
||||
};
|
||||
|
||||
// Defaults
|
||||
|
||||
/// C-compatible variant type
|
||||
const DEFAULT_STATE: i32 = -1;
|
||||
|
||||
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `HistoryBack` action of `Window` group
|
||||
pub struct HistoryBack {
|
||||
gobject: SimpleAction,
|
||||
}
|
||||
|
||||
impl HistoryBack {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
gobject: SimpleAction::new_stateful(
|
||||
&uuid_string_random(),
|
||||
None,
|
||||
&DEFAULT_STATE.to_variant(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
pub fn activate(&self) {
|
||||
self.gobject.activate(None);
|
||||
}
|
||||
|
||||
/// Change action [state](https://docs.gtk.org/gio/method.SimpleAction.set_state.html)
|
||||
/// * set `DEFAULT_STATE` on `None`
|
||||
pub fn change_state(&self, state: Option<i32>) {
|
||||
self.gobject.change_state(
|
||||
&match state {
|
||||
Some(value) => value,
|
||||
None => DEFAULT_STATE,
|
||||
}
|
||||
.to_variant(),
|
||||
)
|
||||
}
|
||||
|
||||
// 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(Option<i32>) + 'static) {
|
||||
let state = self.state();
|
||||
self.gobject.connect_activate(move |_, _| callback(state));
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn state(&self) -> Option<i32> {
|
||||
let state = self
|
||||
.gobject
|
||||
.state()
|
||||
.expect("State value required")
|
||||
.get::<i32>()
|
||||
.expect("Parameter type does not match `i32`");
|
||||
|
||||
if state != DEFAULT_STATE {
|
||||
Some(state)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// 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()
|
||||
}
|
||||
}
|
||||
85
src/app/browser/window/action/history_forward.rs
Normal file
85
src/app/browser/window/action/history_forward.rs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::{ActionExt, ToVariant},
|
||||
};
|
||||
|
||||
// Defaults
|
||||
|
||||
/// C-compatible variant type
|
||||
const DEFAULT_STATE: i32 = -1;
|
||||
|
||||
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `HistoryForward` action of `Window` group
|
||||
pub struct HistoryForward {
|
||||
gobject: SimpleAction,
|
||||
}
|
||||
|
||||
impl HistoryForward {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
gobject: SimpleAction::new_stateful(
|
||||
&uuid_string_random(),
|
||||
None,
|
||||
&DEFAULT_STATE.to_variant(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
pub fn activate(&self) {
|
||||
self.gobject.activate(None);
|
||||
}
|
||||
|
||||
/// Change action [state](https://docs.gtk.org/gio/method.SimpleAction.set_state.html)
|
||||
/// * set `DEFAULT_STATE` on `None`
|
||||
pub fn change_state(&self, state: Option<i32>) {
|
||||
self.gobject.change_state(
|
||||
&match state {
|
||||
Some(value) => value,
|
||||
None => DEFAULT_STATE,
|
||||
}
|
||||
.to_variant(),
|
||||
)
|
||||
}
|
||||
|
||||
// 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(Option<i32>) + 'static) {
|
||||
let state = self.state();
|
||||
self.gobject.connect_activate(move |_, _| callback(state));
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn state(&self) -> Option<i32> {
|
||||
let state = self
|
||||
.gobject
|
||||
.state()
|
||||
.expect("State value required")
|
||||
.get::<i32>()
|
||||
.expect("Parameter type does not match `i32`");
|
||||
|
||||
if state != DEFAULT_STATE {
|
||||
Some(state)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// 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()
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@ 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;
|
||||
|
||||
pub struct Header {
|
||||
|
|
@ -20,23 +19,11 @@ impl Header {
|
|||
// Actions
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
action_page_close: SimpleAction,
|
||||
action_page_close_all: SimpleAction,
|
||||
action_page_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
// Widgets
|
||||
tab_view: &TabView,
|
||||
) -> Rc<Self> {
|
||||
// Init components
|
||||
let bar = Bar::new_rc(
|
||||
browser_action,
|
||||
window_action,
|
||||
action_page_close,
|
||||
action_page_close_all,
|
||||
action_page_history_back,
|
||||
action_page_history_forward,
|
||||
tab_view,
|
||||
);
|
||||
let bar = Bar::new_rc(browser_action, window_action, tab_view);
|
||||
|
||||
// Return new struct
|
||||
Rc::new(Self {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ 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 gtk::Box;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Bar {
|
||||
|
|
@ -23,23 +23,12 @@ impl Bar {
|
|||
pub fn new_rc(
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
action_page_close: SimpleAction,
|
||||
action_page_close_all: SimpleAction,
|
||||
action_page_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
view: &TabView,
|
||||
) -> Rc<Self> {
|
||||
// Init components
|
||||
let control = Control::new_rc();
|
||||
let tab = Tab::new_rc(window_action.clone(), view);
|
||||
let menu = Menu::new_rc(
|
||||
browser_action,
|
||||
window_action,
|
||||
action_page_close,
|
||||
action_page_close_all,
|
||||
action_page_history_back,
|
||||
action_page_history_forward,
|
||||
);
|
||||
let menu = Menu::new_rc(browser_action, window_action);
|
||||
|
||||
// Build result
|
||||
Rc::new(Self {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ 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},
|
||||
prelude::ActionExt,
|
||||
gio::{self},
|
||||
MenuButton,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
|
@ -19,10 +18,6 @@ impl Menu {
|
|||
pub fn new_rc(
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
action_page_close: SimpleAction,
|
||||
action_page_close_all: SimpleAction,
|
||||
action_page_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
) -> Rc<Self> {
|
||||
// Main
|
||||
let main = gio::Menu::new();
|
||||
|
|
@ -58,8 +53,18 @@ impl Menu {
|
|||
|
||||
// Main > Page > Navigation > History
|
||||
let main_page_navigation_history = gio::Menu::new();
|
||||
main_page_navigation_history.append(Some("Back"), Some(&detailed_action_name(&action_page_history_back)));
|
||||
main_page_navigation_history.append(Some("Forward"), Some(&detailed_action_name(&action_page_history_forward)));
|
||||
|
||||
main_page_navigation_history.append(Some("Back"), Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id(),
|
||||
window_action.history_back().id()
|
||||
)));
|
||||
|
||||
main_page_navigation_history.append(Some("Forward"), Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id(),
|
||||
window_action.history_forward().id()
|
||||
)));
|
||||
|
||||
main_page_navigation.append_submenu(Some("History"), &main_page_navigation_history);
|
||||
|
||||
|
|
@ -67,8 +72,18 @@ impl Menu {
|
|||
|
||||
// Main > Page > Close
|
||||
let main_page_close = gio::Menu::new();
|
||||
main_page_close.append(Some("Current"), Some(&detailed_action_name(&action_page_close)));
|
||||
main_page_close.append(Some("All"), Some(&detailed_action_name(&action_page_close_all)));
|
||||
|
||||
main_page_close.append(Some("Current"), Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id(),
|
||||
window_action.close().id()
|
||||
)));
|
||||
|
||||
main_page_close.append(Some("All"), Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id(),
|
||||
window_action.close_all().id()
|
||||
)));
|
||||
|
||||
main_page.append_submenu(Some("Close"), &main_page_close);
|
||||
|
||||
|
|
@ -113,10 +128,3 @@ impl Menu {
|
|||
self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
||||
// Private helpers
|
||||
fn detailed_action_name(action: &SimpleAction) -> String {
|
||||
format!("win.{}", action.name()) // @TODO find the way to ident parent group
|
||||
// without application-wide dependencies import
|
||||
// see also src/app/action.rs
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,22 +13,15 @@ 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,
|
||||
glib::{GString, Propagation},
|
||||
prelude::{ActionExt, ToVariant},
|
||||
};
|
||||
use gtk::glib::{GString, Propagation};
|
||||
use sqlite::Transaction;
|
||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||
|
||||
// Main
|
||||
pub struct Tab {
|
||||
// Global actions
|
||||
// Actions
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
// Page actions
|
||||
action_page_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
// Dynamically allocated reference index
|
||||
index: Rc<RefCell<HashMap<GString, Rc<Item>>>>,
|
||||
action: Rc<Action>,
|
||||
|
|
@ -37,14 +30,7 @@ pub struct Tab {
|
|||
|
||||
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_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
) -> Rc<Self> {
|
||||
pub fn new_rc(browser_action: Rc<BrowserAction>, window_action: Rc<WindowAction>) -> Rc<Self> {
|
||||
// Init local actions
|
||||
let action = Rc::new(Action::new());
|
||||
|
||||
|
|
@ -52,13 +38,7 @@ impl Tab {
|
|||
let index = Rc::new(RefCell::new(HashMap::new()));
|
||||
|
||||
// Init context menu
|
||||
let menu = Menu::new(
|
||||
window_action.clone(),
|
||||
action_page_close_all.clone(),
|
||||
action_page_close.clone(),
|
||||
action_page_history_back.clone(),
|
||||
action_page_history_forward.clone(),
|
||||
);
|
||||
let menu = Menu::new(window_action.clone());
|
||||
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::new(menu.gobject()));
|
||||
|
|
@ -73,20 +53,14 @@ impl Tab {
|
|||
let window_action = window_action.clone();
|
||||
let action = action.clone();
|
||||
|
||||
let action_page_history_back = action_page_history_back.clone();
|
||||
let action_page_history_forward = action_page_history_forward.clone();
|
||||
|
||||
move |request| {
|
||||
// Init new tab item
|
||||
let item = Item::new_rc(
|
||||
&gobject,
|
||||
// Global actions
|
||||
// Actions
|
||||
browser_action.clone(),
|
||||
window_action.clone(),
|
||||
action.clone(),
|
||||
// Page actions
|
||||
action_page_history_back.clone(),
|
||||
action_page_history_forward.clone(),
|
||||
// Options
|
||||
gobject
|
||||
.selected_page()
|
||||
|
|
@ -107,36 +81,23 @@ impl Tab {
|
|||
});
|
||||
|
||||
widget.gobject().connect_setup_menu({
|
||||
// Clone actions to update
|
||||
let action_page_close = action_page_close.clone();
|
||||
let action_page_history_back = action_page_history_back.clone();
|
||||
let action_page_history_forward = action_page_history_forward.clone();
|
||||
let window_action = window_action.clone();
|
||||
move |tab_view, tab_page| {
|
||||
// Update actions
|
||||
let state_v2 = match tab_page {
|
||||
// Set state
|
||||
let state = match tab_page {
|
||||
// Context menu opened
|
||||
Some(this) => Some(tab_view.page_position(this)),
|
||||
// Context menu closed (reset state to defaults)
|
||||
None => None,
|
||||
}; // @TODO
|
||||
|
||||
window_action.pin().change_state(state_v2);
|
||||
window_action.reload().change_state(state_v2);
|
||||
window_action.home().change_state(state_v2);
|
||||
|
||||
// @TODO old version requires update
|
||||
// Setup state for selected page
|
||||
let state = match tab_page {
|
||||
// Context menu opened
|
||||
Some(this) => tab_view.page_position(this).to_variant(),
|
||||
// Context menu closed (reset state to defaults)
|
||||
None => (-1).to_variant(),
|
||||
};
|
||||
|
||||
action_page_close.change_state(&state);
|
||||
action_page_history_back.change_state(&state);
|
||||
action_page_history_forward.change_state(&state);
|
||||
// Update actions with new state value
|
||||
window_action.close_all().change_state(state);
|
||||
window_action.close().change_state(state);
|
||||
window_action.history_back().change_state(state);
|
||||
window_action.history_forward().change_state(state);
|
||||
window_action.home().change_state(state);
|
||||
window_action.pin().change_state(state);
|
||||
window_action.reload().change_state(state);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -176,10 +137,6 @@ impl Tab {
|
|||
Rc::new(Self {
|
||||
browser_action,
|
||||
window_action,
|
||||
// Global actions
|
||||
action_page_history_back,
|
||||
action_page_history_forward,
|
||||
// Init empty HashMap index as no tabs appended yet
|
||||
index,
|
||||
action,
|
||||
widget,
|
||||
|
|
@ -193,11 +150,8 @@ impl Tab {
|
|||
self.gobject(),
|
||||
self.browser_action.clone(),
|
||||
self.window_action.clone(),
|
||||
// Local actions
|
||||
// Actions
|
||||
self.action.clone(),
|
||||
// Global actions
|
||||
self.action_page_history_back.clone(),
|
||||
self.action_page_history_forward.clone(),
|
||||
// Options
|
||||
position,
|
||||
false,
|
||||
|
|
@ -338,8 +292,6 @@ impl Tab {
|
|||
self.browser_action.clone(),
|
||||
self.window_action.clone(),
|
||||
self.action.clone(),
|
||||
self.action_page_history_back.clone(),
|
||||
self.action_page_history_forward.clone(),
|
||||
) {
|
||||
Ok(items) => {
|
||||
for item in items {
|
||||
|
|
|
|||
|
|
@ -10,10 +10,7 @@ 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::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, GString},
|
||||
};
|
||||
use gtk::glib::{uuid_string_random, GString};
|
||||
use sqlite::Transaction;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
|
@ -30,13 +27,10 @@ impl Item {
|
|||
// Construct
|
||||
pub fn new_rc(
|
||||
tab_view: &TabView,
|
||||
// Global actions
|
||||
// Actions
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
// @TODO
|
||||
action_page_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
// Options
|
||||
position: Option<i32>,
|
||||
is_pinned: bool,
|
||||
|
|
@ -52,8 +46,6 @@ impl Item {
|
|||
browser_action,
|
||||
window_action,
|
||||
tab_action,
|
||||
action_page_history_back.clone(),
|
||||
action_page_history_forward.clone(),
|
||||
);
|
||||
|
||||
let widget = Widget::new_rc(
|
||||
|
|
@ -133,8 +125,6 @@ impl Item {
|
|||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
action_page_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
) -> Result<Vec<Rc<Item>>, String> {
|
||||
let mut items = Vec::new();
|
||||
|
||||
|
|
@ -148,8 +138,6 @@ impl Item {
|
|||
browser_action.clone(),
|
||||
window_action.clone(),
|
||||
tab_action.clone(),
|
||||
action_page_history_back.clone(),
|
||||
action_page_history_forward.clone(),
|
||||
// Options
|
||||
None,
|
||||
record.is_pinned,
|
||||
|
|
|
|||
|
|
@ -60,8 +60,6 @@ impl Page {
|
|||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
action_page_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
) -> Rc<Self> {
|
||||
// Init local actions
|
||||
let action_page_load = SimpleAction::new(&uuid_string_random(), None);
|
||||
|
|
@ -74,8 +72,6 @@ impl Page {
|
|||
let navigation = Navigation::new_rc(
|
||||
browser_action.clone(),
|
||||
window_action.clone(),
|
||||
action_page_history_back.clone(),
|
||||
action_page_history_forward.clone(),
|
||||
action_page_open.clone(),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,13 +33,11 @@ impl Navigation {
|
|||
pub fn new_rc(
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
action_page_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
action_page_open: SimpleAction,
|
||||
) -> Rc<Self> {
|
||||
// Init components
|
||||
let home = Home::new_rc(window_action.clone());
|
||||
let history = History::new_rc(action_page_history_back, action_page_history_forward);
|
||||
let history = History::new_rc(window_action.clone());
|
||||
let reload = Reload::new_rc(window_action);
|
||||
let request = Request::new_rc(browser_action, action_page_open.clone());
|
||||
let bookmark = Bookmark::new_rc();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ use back::Back;
|
|||
use forward::Forward;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{gio::SimpleAction, glib::GString, Box};
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use gtk::{glib::GString, Box};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
struct Memory {
|
||||
|
|
@ -27,13 +28,10 @@ pub struct History {
|
|||
|
||||
impl History {
|
||||
// Construct
|
||||
pub fn new_rc(
|
||||
action_page_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
) -> Rc<Self> {
|
||||
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
|
||||
// init components
|
||||
let back = Back::new_rc(action_page_history_back);
|
||||
let forward = Forward::new_rc(action_page_history_forward);
|
||||
let back = Back::new_rc(window_action.clone());
|
||||
let forward = Forward::new_rc(window_action);
|
||||
|
||||
// Init widget
|
||||
let widget = Widget::new_rc(back.gobject(), forward.gobject());
|
||||
|
|
|
|||
|
|
@ -2,28 +2,32 @@ 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 Back {
|
||||
action_page_history_back: SimpleAction,
|
||||
window_action: Rc<WindowAction>,
|
||||
widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Back {
|
||||
// Construct
|
||||
pub fn new_rc(action_page_history_back: SimpleAction) -> Rc<Self> {
|
||||
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
|
||||
// Return activated struct
|
||||
Rc::new(Self {
|
||||
action_page_history_back: action_page_history_back.clone(),
|
||||
widget: Widget::new_rc(action_page_history_back),
|
||||
window_action: window_action.clone(),
|
||||
widget: Widget::new_rc(window_action),
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, status: bool) {
|
||||
// Update actions
|
||||
self.action_page_history_back.set_enabled(status);
|
||||
self.window_action
|
||||
.history_back()
|
||||
.gobject()
|
||||
.set_enabled(status);
|
||||
|
||||
// Update child components
|
||||
self.widget.update(status);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
prelude::{ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
|
@ -11,7 +11,7 @@ pub struct Widget {
|
|||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_rc(action_page_history_back: SimpleAction) -> Rc<Self> {
|
||||
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
|
||||
// Init gobject
|
||||
let gobject = Button::builder()
|
||||
.icon_name("go-previous-symbolic")
|
||||
|
|
@ -21,9 +21,9 @@ impl Widget {
|
|||
|
||||
// Init events
|
||||
gobject.connect_clicked({
|
||||
let action_page_history_back = action_page_history_back.clone();
|
||||
let window_action = window_action.clone();
|
||||
move |_| {
|
||||
action_page_history_back.activate(None);
|
||||
window_action.history_back().activate();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -2,28 +2,32 @@ 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 Forward {
|
||||
action_page_history_forward: SimpleAction,
|
||||
window_action: Rc<WindowAction>,
|
||||
widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Forward {
|
||||
// Construct
|
||||
pub fn new_rc(action_page_history_forward: SimpleAction) -> Rc<Self> {
|
||||
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
|
||||
// Return activated struct
|
||||
Rc::new(Self {
|
||||
action_page_history_forward: action_page_history_forward.clone(),
|
||||
widget: Widget::new_rc(action_page_history_forward),
|
||||
window_action: window_action.clone(),
|
||||
widget: Widget::new_rc(window_action),
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, status: bool) {
|
||||
// Update actions
|
||||
self.action_page_history_forward.set_enabled(status);
|
||||
self.window_action
|
||||
.history_forward()
|
||||
.gobject()
|
||||
.set_enabled(status);
|
||||
|
||||
// Update child components
|
||||
self.widget.update(status);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
prelude::{ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
|
@ -11,7 +11,7 @@ pub struct Widget {
|
|||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_rc(action_page_history_forward: SimpleAction) -> Rc<Self> {
|
||||
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
|
||||
// Init gobject
|
||||
let gobject = Button::builder()
|
||||
.icon_name("go-next-symbolic")
|
||||
|
|
@ -21,9 +21,9 @@ impl Widget {
|
|||
|
||||
// Init events
|
||||
gobject.connect_clicked({
|
||||
let action_page_history_forward = action_page_history_forward.clone();
|
||||
let window_action = window_action.clone();
|
||||
move |_| {
|
||||
action_page_history_forward.activate(None);
|
||||
window_action.history_forward().activate();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use gtk::{gio::SimpleAction, prelude::ActionExt};
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Context menu wrapper
|
||||
///
|
||||
|
|
@ -14,13 +12,7 @@ impl Menu {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(
|
||||
window_action: Rc<WindowAction>,
|
||||
action_page_close_all: SimpleAction,
|
||||
action_page_close: SimpleAction,
|
||||
action_page_history_back: SimpleAction,
|
||||
action_page_history_forward: SimpleAction,
|
||||
) -> Self {
|
||||
pub fn new(window_action: Rc<WindowAction>) -> Self {
|
||||
let main = gtk::gio::Menu::new();
|
||||
|
||||
main.append(
|
||||
|
|
@ -58,12 +50,20 @@ impl Menu {
|
|||
|
||||
history.append(
|
||||
Some("Back"),
|
||||
Some(&detailed_action_name(action_page_history_back)),
|
||||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id(),
|
||||
window_action.history_back().id()
|
||||
)),
|
||||
);
|
||||
|
||||
history.append(
|
||||
Some("Forward"),
|
||||
Some(&detailed_action_name(action_page_history_forward)),
|
||||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id(),
|
||||
window_action.history_forward().id()
|
||||
)),
|
||||
);
|
||||
|
||||
main.append_submenu(Some("History"), &history);
|
||||
|
|
@ -72,12 +72,20 @@ impl Menu {
|
|||
|
||||
close.append(
|
||||
Some("Current"),
|
||||
Some(&detailed_action_name(action_page_close)),
|
||||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id(),
|
||||
window_action.close().id()
|
||||
)),
|
||||
);
|
||||
|
||||
close.append(
|
||||
Some("All"),
|
||||
Some(&detailed_action_name(action_page_close_all)),
|
||||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id(),
|
||||
window_action.close_all().id()
|
||||
)),
|
||||
);
|
||||
|
||||
main.append_submenu(Some("Close"), &close);
|
||||
|
|
@ -90,11 +98,3 @@ impl Menu {
|
|||
&self.gobject
|
||||
}
|
||||
}
|
||||
|
||||
// Private helpers
|
||||
|
||||
fn detailed_action_name(action: SimpleAction) -> String {
|
||||
format!("win.{}", action.name()) // @TODO find the way to ident parent group
|
||||
// without application-wide dependencies import
|
||||
// see also src/app/action.rs
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue