mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
implement recent bookmarks menu item
This commit is contained in:
parent
c335207b28
commit
9e86e9b29f
13 changed files with 155 additions and 60 deletions
|
|
@ -6,6 +6,7 @@ mod find;
|
|||
mod history_back;
|
||||
mod history_forward;
|
||||
mod home;
|
||||
mod open;
|
||||
mod pin;
|
||||
mod reload;
|
||||
mod save_as;
|
||||
|
|
@ -19,6 +20,7 @@ use find::Find;
|
|||
use history_back::HistoryBack;
|
||||
use history_forward::HistoryForward;
|
||||
use home::Home;
|
||||
use open::Open;
|
||||
use pin::Pin;
|
||||
use reload::Reload;
|
||||
use save_as::SaveAs;
|
||||
|
|
@ -44,6 +46,7 @@ pub struct Action {
|
|||
pub history_back: Rc<HistoryBack>,
|
||||
pub history_forward: Rc<HistoryForward>,
|
||||
pub home: Rc<Home>,
|
||||
pub open: Rc<Open>,
|
||||
pub pin: Rc<Pin>,
|
||||
pub reload: Rc<Reload>,
|
||||
pub save_as: Rc<SaveAs>,
|
||||
|
|
@ -67,6 +70,7 @@ impl Action {
|
|||
let history_back = Rc::new(HistoryBack::new());
|
||||
let history_forward = Rc::new(HistoryForward::new());
|
||||
let home = Rc::new(Home::new());
|
||||
let open = Rc::new(Open::new());
|
||||
let pin = Rc::new(Pin::new());
|
||||
let reload = Rc::new(Reload::new());
|
||||
let save_as = Rc::new(SaveAs::new());
|
||||
|
|
@ -87,6 +91,7 @@ impl Action {
|
|||
simple_action_group.add_action(&history_back.simple_action);
|
||||
simple_action_group.add_action(&history_forward.simple_action);
|
||||
simple_action_group.add_action(&home.simple_action);
|
||||
simple_action_group.add_action(&open.simple_action);
|
||||
simple_action_group.add_action(&pin.simple_action);
|
||||
simple_action_group.add_action(&reload.simple_action);
|
||||
simple_action_group.add_action(&save_as.simple_action);
|
||||
|
|
@ -102,6 +107,7 @@ impl Action {
|
|||
history_back,
|
||||
history_forward,
|
||||
home,
|
||||
open,
|
||||
pin,
|
||||
reload,
|
||||
save_as,
|
||||
|
|
|
|||
44
src/app/browser/window/action/open.rs
Normal file
44
src/app/browser/window/action/open.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// Defaults
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, SignalHandlerId},
|
||||
prelude::StaticVariantType,
|
||||
};
|
||||
|
||||
/// Open [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html)
|
||||
pub struct Open {
|
||||
pub simple_action: SimpleAction,
|
||||
}
|
||||
|
||||
impl Open {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
simple_action: SimpleAction::new(
|
||||
&uuid_string_random(),
|
||||
Some(&String::static_variant_type()),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Formatted action connector for external implementation
|
||||
pub fn on_activate(
|
||||
&self,
|
||||
callback: impl Fn(&SimpleAction, String) + 'static,
|
||||
) -> SignalHandlerId {
|
||||
self.simple_action.connect_activate(move |this, message| {
|
||||
callback(
|
||||
this,
|
||||
message
|
||||
.expect("Variant required to call this action")
|
||||
.get::<String>()
|
||||
.expect("Parameter does not match `String` type"),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -13,14 +13,15 @@ pub struct Header {
|
|||
}
|
||||
|
||||
impl Header {
|
||||
// Construct
|
||||
// Constructors
|
||||
|
||||
pub fn new(
|
||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
profile: &Rc<Profile>,
|
||||
tab_view: &TabView,
|
||||
) -> Self {
|
||||
// Init components
|
||||
let bar = Bar::new((browser_action, window_action), profile, tab_view);
|
||||
let bar = Rc::new(Bar::new((browser_action, window_action), profile, tab_view));
|
||||
|
||||
// Return new struct
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ impl Bar {
|
|||
) -> Self {
|
||||
let control = Control::new();
|
||||
let tab = Tab::new(window_action, view);
|
||||
let menu = Menu::new((browser_action, window_action), profile);
|
||||
let menu = Rc::new(Menu::new((browser_action, window_action), profile));
|
||||
Self {
|
||||
widget: Rc::new(Widget::new(
|
||||
&control.widget.gobject,
|
||||
&menu.widget.gobject,
|
||||
&control.window_controls,
|
||||
&menu.menu_button,
|
||||
&tab.widget.tab_bar,
|
||||
)),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
mod widget;
|
||||
use widget::Widget;
|
||||
use gtk::{PackType, WindowControls};
|
||||
|
||||
use std::rc::Rc;
|
||||
const MARGIN: i32 = 4;
|
||||
|
||||
pub struct Control {
|
||||
pub widget: Rc<Widget>,
|
||||
pub window_controls: WindowControls,
|
||||
}
|
||||
|
||||
impl Control {
|
||||
// Construct
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
widget: Rc::new(Widget::new()),
|
||||
window_controls: WindowControls::builder()
|
||||
.margin_end(MARGIN)
|
||||
.side(PackType::End)
|
||||
.build(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
use gtk::{PackType, WindowControls};
|
||||
|
||||
pub struct Widget {
|
||||
pub gobject: WindowControls,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
gobject: WindowControls::builder()
|
||||
.side(PackType::End)
|
||||
.margin_end(4)
|
||||
.build(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +1,24 @@
|
|||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use super::{BrowserAction, Profile, WindowAction};
|
||||
use gtk::{
|
||||
gio::{self},
|
||||
prelude::ActionExt,
|
||||
prelude::{ActionExt, ToVariant},
|
||||
Align, MenuButton,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
// Config options
|
||||
|
||||
const RECENT_BOOKMARKS: usize = 50;
|
||||
|
||||
pub struct Menu {
|
||||
pub widget: Rc<Widget>,
|
||||
pub menu_button: MenuButton,
|
||||
}
|
||||
|
||||
#[rustfmt::skip] // @TODO template builder?
|
||||
impl Menu {
|
||||
pub fn new(
|
||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
_profile: &Rc<Profile>,
|
||||
profile: &Rc<Profile>,
|
||||
) -> Self {
|
||||
// Main
|
||||
let main = gio::Menu::new();
|
||||
|
|
@ -122,6 +124,12 @@ impl Menu {
|
|||
|
||||
main.append_submenu(Some("Page"), &main_page);
|
||||
|
||||
// Main > Bookmark
|
||||
// * menu items dynamically generated using profile memory pool and `set_create_popup_func`
|
||||
let main_bookmarks = gio::Menu::new();
|
||||
|
||||
main.append_submenu(Some("Bookmarks"), &main_bookmarks);
|
||||
|
||||
// Main > Tool
|
||||
let main_tool = gio::Menu::new();
|
||||
|
||||
|
|
@ -152,7 +160,42 @@ impl Menu {
|
|||
browser_action.close.simple_action.name()
|
||||
)));
|
||||
|
||||
// Init main widget
|
||||
let menu_button = MenuButton::builder()
|
||||
.css_classes(["flat"])
|
||||
.icon_name("open-menu-symbolic")
|
||||
.menu_model(&main)
|
||||
.tooltip_text("Menu")
|
||||
.valign(Align::Center)
|
||||
.build();
|
||||
|
||||
// Generate dynamical menu items
|
||||
menu_button.set_create_popup_func({
|
||||
let profile = profile.clone();
|
||||
let main_bookmarks = main_bookmarks.clone();
|
||||
let window_action = window_action.clone();
|
||||
move |_| {
|
||||
main_bookmarks.remove_all();
|
||||
for bookmark in profile.bookmark.memory.recent(RECENT_BOOKMARKS) {
|
||||
let menu_item = gio::MenuItem::new(Some(&bookmark), None);
|
||||
menu_item.set_action_and_target_value(Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.open.simple_action.name()
|
||||
)), Some(&bookmark.to_variant()));
|
||||
|
||||
main_bookmarks.append_item(&menu_item);
|
||||
}
|
||||
// Show all bookmarks menu item
|
||||
// if profile.bookmark.memory.total() > RECENT_BOOKMARKS {
|
||||
// @TODO
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
// Result
|
||||
Self { widget:Rc::new(Widget::new(&main)) }
|
||||
Self {
|
||||
menu_button
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
use gtk::{gio::Menu, Align, MenuButton};
|
||||
|
||||
pub struct Widget {
|
||||
pub gobject: MenuButton,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new(model: &Menu) -> Self {
|
||||
Self {
|
||||
gobject: MenuButton::builder()
|
||||
.css_classes(["flat"])
|
||||
.icon_name("open-menu-symbolic")
|
||||
.menu_model(model)
|
||||
.tooltip_text("Menu")
|
||||
.valign(Align::Center)
|
||||
.build(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue