mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
begin action collections implementation (to reduce argument size by clippy)
This commit is contained in:
parent
7c7e91ca31
commit
ec7a668cd9
15 changed files with 164 additions and 129 deletions
|
|
@ -8,6 +8,7 @@ use menu::Menu;
|
|||
use tab::Tab;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::action::Browser as BrowserAction;
|
||||
use adw::TabView;
|
||||
use gtk::{gio::SimpleAction, Box};
|
||||
use std::rc::Rc;
|
||||
|
|
@ -19,10 +20,7 @@ pub struct Bar {
|
|||
impl Bar {
|
||||
// Construct
|
||||
pub fn new_rc(
|
||||
action_about: SimpleAction,
|
||||
action_debug: SimpleAction,
|
||||
action_profile: SimpleAction,
|
||||
action_quit: SimpleAction,
|
||||
browser_action: Rc<BrowserAction>,
|
||||
action_page_new: SimpleAction,
|
||||
action_page_close: SimpleAction,
|
||||
action_page_close_all: SimpleAction,
|
||||
|
|
@ -37,10 +35,7 @@ impl Bar {
|
|||
let control = Control::new_rc();
|
||||
let tab = Tab::new_rc(action_page_new.clone(), view);
|
||||
let menu = Menu::new_rc(
|
||||
action_about,
|
||||
action_debug,
|
||||
action_profile,
|
||||
action_quit,
|
||||
browser_action,
|
||||
action_page_new,
|
||||
action_page_close,
|
||||
action_page_close_all,
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ mod widget;
|
|||
|
||||
use widget::Widget;
|
||||
|
||||
use crate::action::Browser as BrowserAction;
|
||||
use gtk::{
|
||||
gio::{self, SimpleAction},
|
||||
glib::{gformat, GString},
|
||||
prelude::ActionExt,
|
||||
MenuButton,
|
||||
};
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Menu {
|
||||
|
|
@ -17,10 +17,7 @@ pub struct Menu {
|
|||
#[rustfmt::skip] // @TODO template builder?
|
||||
impl Menu {
|
||||
pub fn new_rc(
|
||||
action_about: SimpleAction,
|
||||
action_debug: SimpleAction,
|
||||
action_profile: SimpleAction,
|
||||
action_quit: SimpleAction,
|
||||
browser_action: Rc<BrowserAction>,
|
||||
action_page_new: SimpleAction,
|
||||
action_page_close: SimpleAction,
|
||||
action_page_close_all: SimpleAction,
|
||||
|
|
@ -35,18 +32,18 @@ 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("Reload"), Some(&detailed_action_name(action_page_reload)));
|
||||
main_page.append(Some("Pin"), Some(&detailed_action_name(action_page_pin)));
|
||||
main_page.append(Some("New"), Some(&detailed_action_name(&action_page_new)));
|
||||
main_page.append(Some("Reload"), Some(&detailed_action_name(&action_page_reload)));
|
||||
main_page.append(Some("Pin"), Some(&detailed_action_name(&action_page_pin)));
|
||||
|
||||
// Main > Page > Navigation
|
||||
let main_page_navigation = gio::Menu::new();
|
||||
main_page_navigation.append(Some("Home"), Some(&detailed_action_name(action_page_home)));
|
||||
main_page_navigation.append(Some("Home"), Some(&detailed_action_name(&action_page_home)));
|
||||
|
||||
// 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(&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.append_submenu(Some("History"), &main_page_navigation_history);
|
||||
|
||||
|
|
@ -54,8 +51,8 @@ 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(&detailed_action_name(&action_page_close)));
|
||||
main_page_close.append(Some("All"), Some(&detailed_action_name(&action_page_close_all)));
|
||||
|
||||
main_page.append_submenu(Some("Close"), &main_page_close);
|
||||
|
||||
|
|
@ -63,13 +60,13 @@ impl Menu {
|
|||
|
||||
// Main > Tool
|
||||
let main_tool = gio::Menu::new();
|
||||
main_tool.append(Some("Debug"), Some(&detailed_action_name(action_debug)));
|
||||
main_tool.append(Some("Profile"), Some(&detailed_action_name(action_profile)));
|
||||
main_tool.append(Some("About"), Some(&detailed_action_name(action_about)));
|
||||
main_tool.append(Some("Debug"), Some(&detailed_action_name(browser_action.debug())));
|
||||
main_tool.append(Some("Profile"), Some(&detailed_action_name(browser_action.profile())));
|
||||
main_tool.append(Some("About"), Some(&detailed_action_name(browser_action.about())));
|
||||
|
||||
main.append_submenu(Some("Tool"), &main_tool);
|
||||
|
||||
main.append(Some("Quit"), Some(&detailed_action_name(action_quit)));
|
||||
main.append(Some("Quit"), Some(&detailed_action_name(browser_action.quit())));
|
||||
|
||||
// Result
|
||||
Rc::new(Self { widget:Widget::new_rc(&main) })
|
||||
|
|
@ -82,7 +79,7 @@ impl Menu {
|
|||
}
|
||||
|
||||
// Private helpers
|
||||
fn detailed_action_name(action: SimpleAction) -> GString {
|
||||
fn detailed_action_name(action: &SimpleAction) -> GString {
|
||||
gformat!("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