draft focus out action

This commit is contained in:
yggverse 2024-12-13 00:03:33 +02:00
parent 44c669389a
commit e606ef5fa9
5 changed files with 48 additions and 2 deletions

View File

@ -156,6 +156,14 @@ impl App {
),
&["<Primary>u"],
),
(
format!(
"{}.{}",
browser.action.id,
browser.action.focus.gobject.name()
),
&["Escape"],
),
// Tab actions
(
format!(

View File

@ -69,6 +69,13 @@ impl Browser {
}
});
action.focus.connect_activate({
let widget = widget.clone();
move || {
widget.application_window.set_focus(gtk::Window::NONE);
}
});
action.profile.connect_activate({
let profile = profile.clone();
move || {

View File

@ -1,12 +1,14 @@
mod about;
mod close;
mod debug;
mod focus;
mod profile;
mod update;
use about::About;
use close::Close;
use debug::Debug;
use focus::Focus;
use profile::Profile;
use update::Update;
@ -23,6 +25,7 @@ pub struct Action {
pub about: Rc<About>,
pub close: Rc<Close>,
pub debug: Rc<Debug>,
pub focus: Rc<Focus>,
pub profile: Rc<Profile>,
pub update: Rc<Update>,
// Group
@ -39,6 +42,7 @@ impl Action {
let about = Rc::new(About::new());
let close = Rc::new(Close::new());
let debug = Rc::new(Debug::new());
let focus = Rc::new(Focus::new());
let profile = Rc::new(Profile::new());
let update = Rc::new(Update::new());
@ -52,6 +56,7 @@ impl Action {
gobject.add_action(&about.gobject);
gobject.add_action(&close.gobject);
gobject.add_action(&debug.gobject);
gobject.add_action(&focus.gobject);
gobject.add_action(&profile.gobject);
gobject.add_action(&update.gobject);
@ -60,6 +65,7 @@ impl Action {
about,
close,
debug,
focus,
profile,
update,
id,

View File

@ -0,0 +1,25 @@
use gtk::{gio::SimpleAction, glib::uuid_string_random};
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Focus` action of `Browser` group
pub struct Focus {
pub gobject: SimpleAction,
}
impl Focus {
// Constructors
/// Create new `Self`
pub fn new() -> Self {
Self {
gobject: SimpleAction::new(&uuid_string_random(), None),
}
}
// 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() + 'static) {
self.gobject.connect_activate(move |_, _| callback());
}
}

View File

@ -27,7 +27,7 @@ use gtk::{
gdk_pixbuf::Pixbuf,
gio::SocketClientEvent,
glib::{gformat, GString, Priority, Uri, UriFlags, UriHideFlags},
prelude::{EditableExt, FileExt, SocketClientExt, WidgetExt},
prelude::{EditableExt, FileExt, SocketClientExt},
};
use sqlite::Transaction;
use std::{rc::Rc, time::Duration};
@ -149,7 +149,7 @@ impl Page {
const DEFAULT_MAX_REDIRECT_COUNT: usize = 10;
// Move focus out from navigation entry
self.navigation.reload.widget.gobject.grab_focus();
// self.navigation.reload.widget.gobject.grab_focus();
// Reset widgets
self.input.unset();