mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
move global actions to the app level
This commit is contained in:
parent
2a985a6fa1
commit
3959872201
@ -7,11 +7,14 @@ use main::Main;
|
|||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
prelude::{ActionExt, ActionMapExt, GtkWindowExt},
|
prelude::{ActionMapExt, GtkWindowExt},
|
||||||
Application, ApplicationWindow,
|
Application, ApplicationWindow,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
const DEFAULT_HEIGHT: i32 = 480;
|
||||||
|
const DEFAULT_WIDTH: i32 = 640;
|
||||||
|
|
||||||
pub struct Browser {
|
pub struct Browser {
|
||||||
// Extras
|
// Extras
|
||||||
// db: db::Browser,
|
// db: db::Browser,
|
||||||
@ -26,22 +29,20 @@ impl Browser {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
app: &Application,
|
app: &Application,
|
||||||
// connection: Arc<sqlite::Connection>,
|
// connection: Arc<sqlite::Connection>,
|
||||||
default_width: i32,
|
// Actions
|
||||||
default_height: i32,
|
action_debug: Arc<SimpleAction>,
|
||||||
|
action_quit: Arc<SimpleAction>,
|
||||||
|
action_update: Arc<SimpleAction>,
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
|
action_tab_close: Arc<SimpleAction>,
|
||||||
|
action_tab_close_all: Arc<SimpleAction>,
|
||||||
|
action_tab_page_reload: Arc<SimpleAction>,
|
||||||
|
action_tab_pin: Arc<SimpleAction>,
|
||||||
) -> Browser {
|
) -> Browser {
|
||||||
// Init window actions
|
// Init database
|
||||||
let action_debug = Arc::new(SimpleAction::new("debug", None));
|
// let db = db::Browser::new(connection); @TODO
|
||||||
let action_quit = Arc::new(SimpleAction::new("quit", None));
|
|
||||||
let action_update = Arc::new(SimpleAction::new("update", None));
|
|
||||||
|
|
||||||
let action_tab_append = Arc::new(SimpleAction::new("tab_append", None));
|
|
||||||
let action_tab_close = Arc::new(SimpleAction::new("tab_close", None));
|
|
||||||
let action_tab_close_all = Arc::new(SimpleAction::new("tab_close_all", None));
|
|
||||||
let action_tab_page_reload = Arc::new(SimpleAction::new("tab_page_reload", None));
|
|
||||||
let action_tab_pin = Arc::new(SimpleAction::new("tab_pin", None));
|
|
||||||
|
|
||||||
// Init components
|
// Init components
|
||||||
// let db = db::Browser::new(connection);
|
|
||||||
let header = Arc::new(Header::new(
|
let header = Arc::new(Header::new(
|
||||||
action_debug.clone(),
|
action_debug.clone(),
|
||||||
action_quit.clone(),
|
action_quit.clone(),
|
||||||
@ -60,10 +61,10 @@ impl Browser {
|
|||||||
// Init widget
|
// Init widget
|
||||||
let widget = ApplicationWindow::builder()
|
let widget = ApplicationWindow::builder()
|
||||||
.application(app)
|
.application(app)
|
||||||
.default_width(default_width)
|
|
||||||
.default_height(default_height)
|
|
||||||
.titlebar(header.widget())
|
.titlebar(header.widget())
|
||||||
.child(main.widget())
|
.child(main.widget())
|
||||||
|
.default_height(DEFAULT_HEIGHT)
|
||||||
|
.default_width(DEFAULT_WIDTH)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
widget.add_action(action_debug.as_ref());
|
widget.add_action(action_debug.as_ref());
|
||||||
@ -135,9 +136,6 @@ impl Browser {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make initial update @TODO move to the app init level
|
|
||||||
action_update.activate(None);
|
|
||||||
|
|
||||||
// Return activated browser struct
|
// Return activated browser struct
|
||||||
Self {
|
Self {
|
||||||
// db,
|
// db,
|
||||||
|
43
src/main.rs
43
src/main.rs
@ -3,12 +3,13 @@ mod browser;
|
|||||||
use browser::Browser;
|
use browser::Browser;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
|
gio::SimpleAction,
|
||||||
glib::{user_config_dir, ExitCode},
|
glib::{user_config_dir, ExitCode},
|
||||||
prelude::{ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
|
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
|
||||||
Application,
|
Application,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::fs::create_dir_all;
|
use std::{fs::create_dir_all, sync::Arc};
|
||||||
|
|
||||||
const APP_ID: &str = "io.github.yggverse.Yoda";
|
const APP_ID: &str = "io.github.yggverse.Yoda";
|
||||||
|
|
||||||
@ -16,7 +17,22 @@ fn main() -> ExitCode {
|
|||||||
// Init app
|
// Init app
|
||||||
let app = Application::builder().application_id(APP_ID).build();
|
let app = Application::builder().application_id(APP_ID).build();
|
||||||
|
|
||||||
|
// Init actions
|
||||||
|
let action_debug = Arc::new(SimpleAction::new("debug", None));
|
||||||
|
let action_quit = Arc::new(SimpleAction::new("quit", None));
|
||||||
|
let action_update = Arc::new(SimpleAction::new("update", None));
|
||||||
|
|
||||||
|
let action_tab_append = Arc::new(SimpleAction::new("tab_append", None));
|
||||||
|
let action_tab_close = Arc::new(SimpleAction::new("tab_close", None));
|
||||||
|
let action_tab_close_all = Arc::new(SimpleAction::new("tab_close_all", None));
|
||||||
|
let action_tab_page_reload = Arc::new(SimpleAction::new("tab_page_reload", None));
|
||||||
|
let action_tab_pin = Arc::new(SimpleAction::new("tab_pin", None));
|
||||||
|
|
||||||
// Init accels
|
// Init accels
|
||||||
|
app.set_accels_for_action("win.debug", &["<Primary>i"]);
|
||||||
|
app.set_accels_for_action("win.update", &["<Primary>u"]);
|
||||||
|
app.set_accels_for_action("win.quit", &["<Primary>Escape"]);
|
||||||
|
|
||||||
app.set_accels_for_action("win.tab_append", &["<Primary>t"]);
|
app.set_accels_for_action("win.tab_append", &["<Primary>t"]);
|
||||||
app.set_accels_for_action("win.tab_pin", &["<Primary>p"]);
|
app.set_accels_for_action("win.tab_pin", &["<Primary>p"]);
|
||||||
app.set_accels_for_action("win.tab_close", &["<Primary>q"]);
|
app.set_accels_for_action("win.tab_close", &["<Primary>q"]);
|
||||||
@ -25,9 +41,6 @@ fn main() -> ExitCode {
|
|||||||
app.set_accels_for_action("win.tab_page_history_forward", &["<Primary>Right"]);
|
app.set_accels_for_action("win.tab_page_history_forward", &["<Primary>Right"]);
|
||||||
app.set_accels_for_action("win.tab_page_reload", &["<Primary>r"]);
|
app.set_accels_for_action("win.tab_page_reload", &["<Primary>r"]);
|
||||||
app.set_accels_for_action("win.tab_page_bookmark", &["<Primary>b"]);
|
app.set_accels_for_action("win.tab_page_bookmark", &["<Primary>b"]);
|
||||||
app.set_accels_for_action("win.debug", &["<Primary>i"]);
|
|
||||||
app.set_accels_for_action("win.update", &["<Primary>u"]);
|
|
||||||
app.set_accels_for_action("win.quit", &["<Primary>Escape"]);
|
|
||||||
|
|
||||||
// Create new window
|
// Create new window
|
||||||
app.connect_activate({
|
app.connect_activate({
|
||||||
@ -52,9 +65,23 @@ fn main() -> ExitCode {
|
|||||||
};*/
|
};*/
|
||||||
|
|
||||||
move |this: &Application| {
|
move |this: &Application| {
|
||||||
Browser::new(this, /*db.clone(),*/ 640, 480)
|
Browser::new(
|
||||||
.widget()
|
this,
|
||||||
.present();
|
/*db.clone(),*/
|
||||||
|
action_debug.clone(),
|
||||||
|
action_quit.clone(),
|
||||||
|
action_update.clone(),
|
||||||
|
action_tab_append.clone(),
|
||||||
|
action_tab_close.clone(),
|
||||||
|
action_tab_close_all.clone(),
|
||||||
|
action_tab_page_reload.clone(),
|
||||||
|
action_tab_pin.clone(),
|
||||||
|
)
|
||||||
|
.widget()
|
||||||
|
.present();
|
||||||
|
|
||||||
|
// Make initial update
|
||||||
|
action_update.activate(None);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user