mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
integrate bookmark action
This commit is contained in:
parent
c279576ee2
commit
3db4c2c6be
@ -174,6 +174,14 @@ impl App {
|
|||||||
),
|
),
|
||||||
&["<Primary>t"],
|
&["<Primary>t"],
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
format!(
|
||||||
|
"{}.{}",
|
||||||
|
browser.window().action().id(),
|
||||||
|
browser.window().action().bookmark().id()
|
||||||
|
),
|
||||||
|
&["<Primary>b"],
|
||||||
|
),
|
||||||
(
|
(
|
||||||
format!(
|
format!(
|
||||||
"{}.{}",
|
"{}.{}",
|
||||||
|
@ -69,27 +69,27 @@ impl Action {
|
|||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
/// Get reference `About` action
|
/// Get reference to `About` action
|
||||||
pub fn about(&self) -> &Rc<About> {
|
pub fn about(&self) -> &Rc<About> {
|
||||||
&self.about
|
&self.about
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `Close` action
|
/// Get reference to `Close` action
|
||||||
pub fn close(&self) -> &Rc<Close> {
|
pub fn close(&self) -> &Rc<Close> {
|
||||||
&self.close
|
&self.close
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `Debug` action
|
/// Get reference to `Debug` action
|
||||||
pub fn debug(&self) -> &Rc<Debug> {
|
pub fn debug(&self) -> &Rc<Debug> {
|
||||||
&self.debug
|
&self.debug
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `Profile` action
|
/// Get reference to `Profile` action
|
||||||
pub fn profile(&self) -> &Rc<Profile> {
|
pub fn profile(&self) -> &Rc<Profile> {
|
||||||
&self.profile
|
&self.profile
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `Update` action
|
/// Get reference to `Update` action
|
||||||
pub fn update(&self) -> &Rc<Update> {
|
pub fn update(&self) -> &Rc<Update> {
|
||||||
&self.update
|
&self.update
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,11 @@ impl Window {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
action.bookmark().connect_activate({
|
||||||
|
let tab = tab.clone();
|
||||||
|
move |position| tab.bookmark(position)
|
||||||
|
});
|
||||||
|
|
||||||
action.pin().connect_activate({
|
action.pin().connect_activate({
|
||||||
let tab = tab.clone();
|
let tab = tab.clone();
|
||||||
move |position| tab.pin(position)
|
move |position| tab.pin(position)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
mod append;
|
mod append;
|
||||||
|
mod bookmark;
|
||||||
mod close;
|
mod close;
|
||||||
mod close_all;
|
mod close_all;
|
||||||
mod history_back;
|
mod history_back;
|
||||||
@ -8,6 +9,7 @@ mod pin;
|
|||||||
mod reload;
|
mod reload;
|
||||||
|
|
||||||
use append::Append;
|
use append::Append;
|
||||||
|
use bookmark::Bookmark;
|
||||||
use close::Close;
|
use close::Close;
|
||||||
use close_all::CloseAll;
|
use close_all::CloseAll;
|
||||||
use history_back::HistoryBack;
|
use history_back::HistoryBack;
|
||||||
@ -29,6 +31,7 @@ pub use append::Position; // public enum
|
|||||||
pub struct Action {
|
pub struct Action {
|
||||||
// Actions
|
// Actions
|
||||||
append: Rc<Append>,
|
append: Rc<Append>,
|
||||||
|
bookmark: Rc<Bookmark>,
|
||||||
close_all: Rc<CloseAll>,
|
close_all: Rc<CloseAll>,
|
||||||
close: Rc<Close>,
|
close: Rc<Close>,
|
||||||
history_back: Rc<HistoryBack>,
|
history_back: Rc<HistoryBack>,
|
||||||
@ -48,6 +51,7 @@ impl Action {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
// Init actions
|
// Init actions
|
||||||
let append = Rc::new(Append::new());
|
let append = Rc::new(Append::new());
|
||||||
|
let bookmark = Rc::new(Bookmark::new());
|
||||||
let close = Rc::new(Close::new());
|
let close = Rc::new(Close::new());
|
||||||
let close_all = Rc::new(CloseAll::new());
|
let close_all = Rc::new(CloseAll::new());
|
||||||
let history_back = Rc::new(HistoryBack::new());
|
let history_back = Rc::new(HistoryBack::new());
|
||||||
@ -64,6 +68,7 @@ impl Action {
|
|||||||
|
|
||||||
// Add action to given group
|
// Add action to given group
|
||||||
gobject.add_action(append.gobject());
|
gobject.add_action(append.gobject());
|
||||||
|
gobject.add_action(bookmark.gobject());
|
||||||
gobject.add_action(close_all.gobject());
|
gobject.add_action(close_all.gobject());
|
||||||
gobject.add_action(close.gobject());
|
gobject.add_action(close.gobject());
|
||||||
gobject.add_action(history_back.gobject());
|
gobject.add_action(history_back.gobject());
|
||||||
@ -75,6 +80,7 @@ impl Action {
|
|||||||
// Done
|
// Done
|
||||||
Self {
|
Self {
|
||||||
append,
|
append,
|
||||||
|
bookmark,
|
||||||
close_all,
|
close_all,
|
||||||
close,
|
close,
|
||||||
history_back,
|
history_back,
|
||||||
@ -89,42 +95,47 @@ impl Action {
|
|||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
/// Get reference `Append` action
|
/// Get reference to `Append` action
|
||||||
pub fn append(&self) -> &Rc<Append> {
|
pub fn append(&self) -> &Rc<Append> {
|
||||||
&self.append
|
&self.append
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `CloseAll` action
|
/// Get reference to `Bookmark` action
|
||||||
|
pub fn bookmark(&self) -> &Rc<Bookmark> {
|
||||||
|
&self.bookmark
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get reference to `CloseAll` action
|
||||||
pub fn close_all(&self) -> &Rc<CloseAll> {
|
pub fn close_all(&self) -> &Rc<CloseAll> {
|
||||||
&self.close_all
|
&self.close_all
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `Close` action
|
/// Get reference to `Close` action
|
||||||
pub fn close(&self) -> &Rc<Close> {
|
pub fn close(&self) -> &Rc<Close> {
|
||||||
&self.close
|
&self.close
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `HistoryBack` action
|
/// Get reference to `HistoryBack` action
|
||||||
pub fn history_back(&self) -> &Rc<HistoryBack> {
|
pub fn history_back(&self) -> &Rc<HistoryBack> {
|
||||||
&self.history_back
|
&self.history_back
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `HistoryForward` action
|
/// Get reference to `HistoryForward` action
|
||||||
pub fn history_forward(&self) -> &Rc<HistoryForward> {
|
pub fn history_forward(&self) -> &Rc<HistoryForward> {
|
||||||
&self.history_forward
|
&self.history_forward
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `Home` action
|
/// Get reference to `Home` action
|
||||||
pub fn home(&self) -> &Rc<Home> {
|
pub fn home(&self) -> &Rc<Home> {
|
||||||
&self.home
|
&self.home
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `Pin` action
|
/// Get reference to `Pin` action
|
||||||
pub fn pin(&self) -> &Rc<Pin> {
|
pub fn pin(&self) -> &Rc<Pin> {
|
||||||
&self.pin
|
&self.pin
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get reference `Reload` action
|
/// Get reference to `Reload` action
|
||||||
pub fn reload(&self) -> &Rc<Reload> {
|
pub fn reload(&self) -> &Rc<Reload> {
|
||||||
&self.reload
|
&self.reload
|
||||||
}
|
}
|
||||||
|
81
src/app/browser/window/action/bookmark.rs
Normal file
81
src/app/browser/window/action/bookmark.rs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
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 `Home` action of `Window` group
|
||||||
|
pub struct Bookmark {
|
||||||
|
gobject: SimpleAction,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bookmark {
|
||||||
|
// 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) {
|
||||||
|
self.gobject.connect_activate(move |this, _| {
|
||||||
|
let state = this
|
||||||
|
.state()
|
||||||
|
.expect("State value required")
|
||||||
|
.get::<i32>()
|
||||||
|
.expect("Parameter type does not match `i32`");
|
||||||
|
|
||||||
|
callback(if state == DEFAULT_STATE {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(state)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
}
|
||||||
|
}
|
@ -36,16 +36,27 @@ impl Menu {
|
|||||||
window_action.reload().id()
|
window_action.reload().id()
|
||||||
)));
|
)));
|
||||||
|
|
||||||
main_page.append(Some("Pin"), Some(&format!(
|
// Main > Page > Mark
|
||||||
"{}.{}",
|
let main_page_mark = gio::Menu::new();
|
||||||
window_action.id(),
|
|
||||||
window_action.pin().id()
|
main_page_mark.append(Some("Bookmark"), Some(&format!(
|
||||||
)));
|
"{}.{}",
|
||||||
|
window_action.id(),
|
||||||
|
window_action.bookmark().id()
|
||||||
|
)));
|
||||||
|
|
||||||
|
main_page_mark.append(Some("Pin"), Some(&format!(
|
||||||
|
"{}.{}",
|
||||||
|
window_action.id(),
|
||||||
|
window_action.pin().id()
|
||||||
|
)));
|
||||||
|
|
||||||
|
main_page.append_section(None, &main_page_mark);
|
||||||
|
|
||||||
// Main > Page > Navigation
|
// Main > Page > Navigation
|
||||||
let main_page_navigation = gio::Menu::new();
|
let main_page_navigation = gio::Menu::new();
|
||||||
|
|
||||||
main_page.append(Some("Home"), Some(&format!(
|
main_page_navigation.append(Some("Home"), Some(&format!(
|
||||||
"{}.{}",
|
"{}.{}",
|
||||||
window_action.id(),
|
window_action.id(),
|
||||||
window_action.home().id()
|
window_action.home().id()
|
||||||
|
@ -152,6 +152,16 @@ impl Tab {
|
|||||||
self.widget.close_all();
|
self.widget.close_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn bookmark(&self, page_position: Option<i32>) {
|
||||||
|
if let Some(page) = self.widget.page(page_position) {
|
||||||
|
if let Some(id) = page.keyword() {
|
||||||
|
if let Some(item) = self.index.borrow().get(&id) {
|
||||||
|
item.page().bookmark();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Toggle pin status for active tab
|
// Toggle pin status for active tab
|
||||||
pub fn pin(&self, page_position: Option<i32>) {
|
pub fn pin(&self, page_position: Option<i32>) {
|
||||||
self.widget.pin(page_position);
|
self.widget.pin(page_position);
|
||||||
|
@ -88,6 +88,10 @@ impl Page {
|
|||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
||||||
|
pub fn bookmark(&self) {
|
||||||
|
// @TODO self.navigation.request().widget().gobject().text()
|
||||||
|
}
|
||||||
|
|
||||||
/// Navigate home URL (parsed from current navigation entry)
|
/// Navigate home URL (parsed from current navigation entry)
|
||||||
/// * this method create new history record in memory as defined in `action_page_open` action
|
/// * this method create new history record in memory as defined in `action_page_open` action
|
||||||
pub fn home(&self) {
|
pub fn home(&self) {
|
||||||
|
@ -24,7 +24,18 @@ impl Menu {
|
|||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
main.append(
|
let main_mark = gtk::gio::Menu::new();
|
||||||
|
|
||||||
|
main_mark.append(
|
||||||
|
Some("Bookmark"),
|
||||||
|
Some(&format!(
|
||||||
|
"{}.{}",
|
||||||
|
window_action.id(),
|
||||||
|
window_action.bookmark().id()
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
|
||||||
|
main_mark.append(
|
||||||
Some("Pin"),
|
Some("Pin"),
|
||||||
Some(&format!(
|
Some(&format!(
|
||||||
"{}.{}",
|
"{}.{}",
|
||||||
@ -33,6 +44,8 @@ impl Menu {
|
|||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
main.append_section(None, &main_mark);
|
||||||
|
|
||||||
let navigation = gtk::gio::Menu::new();
|
let navigation = gtk::gio::Menu::new();
|
||||||
|
|
||||||
navigation.append(
|
navigation.append(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user