mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 09:10:08 +00:00
add find action
This commit is contained in:
parent
80f7451cdc
commit
b56b36cb41
@ -173,6 +173,14 @@ impl App {
|
||||
),
|
||||
&["<Primary>b"],
|
||||
),
|
||||
(
|
||||
format!(
|
||||
"{}.{}",
|
||||
browser.window.action.id,
|
||||
browser.window.action.find.simple_action.name()
|
||||
),
|
||||
&["<Primary>f"],
|
||||
),
|
||||
(
|
||||
format!(
|
||||
"{}.{}",
|
||||
|
@ -2,6 +2,7 @@ mod append;
|
||||
mod bookmark;
|
||||
mod close;
|
||||
mod close_all;
|
||||
mod find;
|
||||
mod history_back;
|
||||
mod history_forward;
|
||||
mod home;
|
||||
@ -14,6 +15,7 @@ use append::Append;
|
||||
use bookmark::Bookmark;
|
||||
use close::Close;
|
||||
use close_all::CloseAll;
|
||||
use find::Find;
|
||||
use history_back::HistoryBack;
|
||||
use history_forward::HistoryForward;
|
||||
use home::Home;
|
||||
@ -38,6 +40,7 @@ pub struct Action {
|
||||
pub bookmark: Rc<Bookmark>,
|
||||
pub close_all: Rc<CloseAll>,
|
||||
pub close: Rc<Close>,
|
||||
pub find: Rc<Find>,
|
||||
pub history_back: Rc<HistoryBack>,
|
||||
pub history_forward: Rc<HistoryForward>,
|
||||
pub home: Rc<Home>,
|
||||
@ -60,6 +63,7 @@ impl Action {
|
||||
let bookmark = Rc::new(Bookmark::new());
|
||||
let close = Rc::new(Close::new());
|
||||
let close_all = Rc::new(CloseAll::new());
|
||||
let find = Rc::new(Find::new());
|
||||
let history_back = Rc::new(HistoryBack::new());
|
||||
let history_forward = Rc::new(HistoryForward::new());
|
||||
let home = Rc::new(Home::new());
|
||||
@ -79,6 +83,7 @@ impl Action {
|
||||
simple_action_group.add_action(&bookmark.simple_action);
|
||||
simple_action_group.add_action(&close_all.simple_action);
|
||||
simple_action_group.add_action(&close.simple_action);
|
||||
simple_action_group.add_action(&find.simple_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);
|
||||
@ -93,6 +98,7 @@ impl Action {
|
||||
bookmark,
|
||||
close_all,
|
||||
close,
|
||||
find,
|
||||
history_back,
|
||||
history_forward,
|
||||
home,
|
||||
|
64
src/app/browser/window/action/find.rs
Normal file
64
src/app/browser/window/action/find.rs
Normal file
@ -0,0 +1,64 @@
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::uuid_string_random,
|
||||
prelude::{ActionExt, ToVariant},
|
||||
};
|
||||
|
||||
// Defaults
|
||||
|
||||
/// C-compatible variant type
|
||||
const DEFAULT_STATE: i32 = -1;
|
||||
|
||||
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Find` action of `Window` group
|
||||
pub struct Find {
|
||||
pub simple_action: SimpleAction,
|
||||
}
|
||||
|
||||
impl Find {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
simple_action: SimpleAction::new_stateful(
|
||||
&uuid_string_random(),
|
||||
None,
|
||||
&DEFAULT_STATE.to_variant(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// 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.simple_action.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.simple_action.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)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
@ -36,6 +36,12 @@ impl Menu {
|
||||
window_action.reload.simple_action.name()
|
||||
)));
|
||||
|
||||
main_page.append(Some("Find.."), Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.find.simple_action.name()
|
||||
)));
|
||||
|
||||
main_page.append(Some("Save as.."), Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
|
@ -75,6 +75,7 @@ impl Tab {
|
||||
action.bookmark.change_state(state);
|
||||
action.close_all.change_state(state);
|
||||
action.close.change_state(state);
|
||||
action.find.change_state(state);
|
||||
action.history_back.change_state(state);
|
||||
action.history_forward.change_state(state);
|
||||
action.home.change_state(state);
|
||||
|
@ -25,6 +25,15 @@ impl Menu {
|
||||
)),
|
||||
);
|
||||
|
||||
main.append(
|
||||
Some("Find.."),
|
||||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.find.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
main.append(
|
||||
Some("Save as.."),
|
||||
Some(&format!(
|
||||
|
Loading…
x
Reference in New Issue
Block a user