mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
remove Escape accels from window actions as blocking dialog windows, replace it with local EventControllerKey implementation, that depends of active focus
This commit is contained in:
parent
4a81297ef1
commit
d469499d46
10 changed files with 37 additions and 68 deletions
|
|
@ -150,10 +150,6 @@ impl App {
|
||||||
),
|
),
|
||||||
["<Primary>i"],
|
["<Primary>i"],
|
||||||
),
|
),
|
||||||
(
|
|
||||||
format!("{}.{}", browser.action.id, browser.action.escape.name()),
|
|
||||||
["Escape"],
|
|
||||||
),
|
|
||||||
// Tab actions
|
// Tab actions
|
||||||
(
|
(
|
||||||
format!(
|
format!(
|
||||||
|
|
|
||||||
|
|
@ -76,15 +76,6 @@ impl Browser {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
action.escape.connect_activate({
|
|
||||||
let widget = widget.clone();
|
|
||||||
let window = window.clone();
|
|
||||||
move |_, _| {
|
|
||||||
window.escape();
|
|
||||||
widget.application_window.set_focus(gtk::Window::NONE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
action.profile.connect_activate({
|
action.profile.connect_activate({
|
||||||
let profile = profile.clone();
|
let profile = profile.clone();
|
||||||
move || {
|
move || {
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
mod about;
|
mod about;
|
||||||
mod close;
|
mod close;
|
||||||
mod debug;
|
mod debug;
|
||||||
mod escape;
|
|
||||||
mod profile;
|
mod profile;
|
||||||
|
|
||||||
use about::About;
|
use about::About;
|
||||||
use close::Close;
|
use close::Close;
|
||||||
use debug::Debug;
|
use debug::Debug;
|
||||||
use escape::Escape;
|
|
||||||
use profile::Profile;
|
use profile::Profile;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{SimpleAction, SimpleActionGroup},
|
gio::SimpleActionGroup,
|
||||||
glib::{GString, uuid_string_random},
|
glib::{GString, uuid_string_random},
|
||||||
prelude::ActionMapExt,
|
prelude::ActionMapExt,
|
||||||
};
|
};
|
||||||
|
|
@ -23,7 +21,6 @@ pub struct Action {
|
||||||
pub about: Rc<About>,
|
pub about: Rc<About>,
|
||||||
pub close: Rc<Close>,
|
pub close: Rc<Close>,
|
||||||
pub debug: Rc<Debug>,
|
pub debug: Rc<Debug>,
|
||||||
pub escape: SimpleAction,
|
|
||||||
pub profile: Rc<Profile>,
|
pub profile: Rc<Profile>,
|
||||||
// Group
|
// Group
|
||||||
pub id: GString,
|
pub id: GString,
|
||||||
|
|
@ -45,7 +42,6 @@ impl Action {
|
||||||
let about = Rc::new(About::new());
|
let about = Rc::new(About::new());
|
||||||
let close = Rc::new(Close::new());
|
let close = Rc::new(Close::new());
|
||||||
let debug = Rc::new(Debug::new());
|
let debug = Rc::new(Debug::new());
|
||||||
let escape = SimpleAction::escape();
|
|
||||||
let profile = Rc::new(Profile::new());
|
let profile = Rc::new(Profile::new());
|
||||||
|
|
||||||
// Generate unique group ID
|
// Generate unique group ID
|
||||||
|
|
@ -58,7 +54,6 @@ impl Action {
|
||||||
simple_action_group.add_action(&about.simple_action);
|
simple_action_group.add_action(&about.simple_action);
|
||||||
simple_action_group.add_action(&close.simple_action);
|
simple_action_group.add_action(&close.simple_action);
|
||||||
simple_action_group.add_action(&debug.simple_action);
|
simple_action_group.add_action(&debug.simple_action);
|
||||||
simple_action_group.add_action(&escape);
|
|
||||||
simple_action_group.add_action(&profile.simple_action);
|
simple_action_group.add_action(&profile.simple_action);
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
|
|
@ -66,7 +61,6 @@ impl Action {
|
||||||
about,
|
about,
|
||||||
close,
|
close,
|
||||||
debug,
|
debug,
|
||||||
escape,
|
|
||||||
profile,
|
profile,
|
||||||
id,
|
id,
|
||||||
simple_action_group,
|
simple_action_group,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
use gtk::{gio::SimpleAction, glib::uuid_string_random};
|
|
||||||
|
|
||||||
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Escape` action of `Browser` group
|
|
||||||
pub trait Escape {
|
|
||||||
fn escape() -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Escape for SimpleAction {
|
|
||||||
fn escape() -> Self {
|
|
||||||
SimpleAction::new(&uuid_string_random(), None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -29,7 +29,7 @@ impl Window {
|
||||||
let action = Rc::new(Action::new());
|
let action = Rc::new(Action::new());
|
||||||
|
|
||||||
// Init components
|
// Init components
|
||||||
let tab = Rc::new(Tab::build(profile, (browser_action, &action)));
|
let tab = Rc::new(Tab::build(profile, &action));
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
action.append.connect_activate({
|
action.append.connect_activate({
|
||||||
|
|
@ -131,9 +131,6 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn escape(&self) {
|
|
||||||
self.tab.escape();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clean(&self, transaction: &Transaction, app_browser_id: i64) -> Result<()> {
|
pub fn clean(&self, transaction: &Transaction, app_browser_id: i64) -> Result<()> {
|
||||||
for record in database::select(transaction, app_browser_id)? {
|
for record in database::select(transaction, app_browser_id)? {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ mod database;
|
||||||
mod item;
|
mod item;
|
||||||
mod menu;
|
mod menu;
|
||||||
|
|
||||||
use super::{Action as WindowAction, BrowserAction, Position};
|
use super::{Action as WindowAction, Position};
|
||||||
use crate::Profile;
|
use crate::Profile;
|
||||||
use action::Action;
|
use action::Action;
|
||||||
use adw::{TabPage, TabView};
|
use adw::{TabPage, TabView};
|
||||||
|
|
@ -17,7 +17,6 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
pub struct Tab {
|
pub struct Tab {
|
||||||
browser_action: Rc<BrowserAction>,
|
|
||||||
window_action: Rc<WindowAction>,
|
window_action: Rc<WindowAction>,
|
||||||
profile: Arc<Profile>,
|
profile: Arc<Profile>,
|
||||||
index: Rc<RefCell<HashMap<TabPage, Rc<Item>>>>,
|
index: Rc<RefCell<HashMap<TabPage, Rc<Item>>>>,
|
||||||
|
|
@ -29,10 +28,7 @@ impl Tab {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Build new `Self`
|
/// Build new `Self`
|
||||||
pub fn build(
|
pub fn build(profile: &Arc<Profile>, window_action: &Rc<WindowAction>) -> Self {
|
||||||
profile: &Arc<Profile>,
|
|
||||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
|
||||||
) -> Self {
|
|
||||||
let action = Rc::new(Action::new());
|
let action = Rc::new(Action::new());
|
||||||
|
|
||||||
// Init empty HashMap index
|
// Init empty HashMap index
|
||||||
|
|
@ -126,7 +122,6 @@ impl Tab {
|
||||||
// Return activated `Self`
|
// Return activated `Self`
|
||||||
Self {
|
Self {
|
||||||
profile: profile.clone(),
|
profile: profile.clone(),
|
||||||
browser_action: browser_action.clone(),
|
|
||||||
window_action: window_action.clone(),
|
window_action: window_action.clone(),
|
||||||
index,
|
index,
|
||||||
tab_view,
|
tab_view,
|
||||||
|
|
@ -152,7 +147,7 @@ impl Tab {
|
||||||
(&tab_page, &target_child),
|
(&tab_page, &target_child),
|
||||||
&self.profile,
|
&self.profile,
|
||||||
// Actions
|
// Actions
|
||||||
(&self.browser_action, &self.window_action, &self.action),
|
(&self.window_action, &self.action),
|
||||||
// Options
|
// Options
|
||||||
request,
|
request,
|
||||||
is_load,
|
is_load,
|
||||||
|
|
@ -216,13 +211,6 @@ impl Tab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle escape action for specified or current item
|
|
||||||
pub fn escape(&self) {
|
|
||||||
if let Some(item) = self.item(None) {
|
|
||||||
item.page.escape();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Toggle search widget
|
// Toggle search widget
|
||||||
pub fn find(&self, page_position: Option<i32>) {
|
pub fn find(&self, page_position: Option<i32>) {
|
||||||
if let Some(item) = self.item(page_position) {
|
if let Some(item) = self.item(page_position) {
|
||||||
|
|
@ -317,7 +305,7 @@ impl Tab {
|
||||||
(&tab_page, &target_child),
|
(&tab_page, &target_child),
|
||||||
&self.profile,
|
&self.profile,
|
||||||
// Actions
|
// Actions
|
||||||
(&self.browser_action, &self.window_action, &self.action),
|
(&self.window_action, &self.action),
|
||||||
// Options
|
// Options
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ mod client;
|
||||||
mod database;
|
mod database;
|
||||||
mod page;
|
mod page;
|
||||||
|
|
||||||
use super::{Action as TabAction, BrowserAction, WindowAction};
|
use super::{Action as TabAction, WindowAction};
|
||||||
use crate::Profile;
|
use crate::Profile;
|
||||||
use action::Action;
|
use action::Action;
|
||||||
use adw::TabPage;
|
use adw::TabPage;
|
||||||
|
|
@ -33,11 +33,7 @@ impl Item {
|
||||||
pub fn build(
|
pub fn build(
|
||||||
(tab_page, target_child): (&TabPage, &Box),
|
(tab_page, target_child): (&TabPage, &Box),
|
||||||
profile: &Arc<Profile>,
|
profile: &Arc<Profile>,
|
||||||
(browser_action, window_action, tab_action): (
|
(window_action, tab_action): (&Rc<WindowAction>, &Rc<TabAction>),
|
||||||
&Rc<BrowserAction>,
|
|
||||||
&Rc<WindowAction>,
|
|
||||||
&Rc<TabAction>,
|
|
||||||
),
|
|
||||||
request: Option<&str>,
|
request: Option<&str>,
|
||||||
is_load: bool,
|
is_load: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|
@ -59,7 +55,7 @@ impl Item {
|
||||||
// Create new `Page` implementation for `TabPage`
|
// Create new `Page` implementation for `TabPage`
|
||||||
let page = Rc::new(Page::build(
|
let page = Rc::new(Page::build(
|
||||||
profile,
|
profile,
|
||||||
(browser_action, window_action, tab_action, &action),
|
(window_action, tab_action, &action),
|
||||||
tab_page,
|
tab_page,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use feature::Feature;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::Cancellable,
|
gio::Cancellable,
|
||||||
glib::{Uri, UriFlags},
|
glib::{Uri, UriFlags},
|
||||||
prelude::{ActionExt, CancellableExt},
|
prelude::CancellableExt,
|
||||||
};
|
};
|
||||||
use std::{cell::Cell, rc::Rc, sync::Arc};
|
use std::{cell::Cell, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
|
|
@ -37,12 +37,11 @@ impl Client {
|
||||||
/// Route tab item `request` to protocol driver
|
/// Route tab item `request` to protocol driver
|
||||||
/// * or `navigation` entry if the value not provided
|
/// * or `navigation` entry if the value not provided
|
||||||
pub fn handle(&self, request: &str, is_snap_history: bool) {
|
pub fn handle(&self, request: &str, is_snap_history: bool) {
|
||||||
|
self.page.escape();
|
||||||
|
|
||||||
// Deprecate page info but keep it data as is
|
// Deprecate page info but keep it data as is
|
||||||
self.page.info.borrow_mut().deprecate();
|
self.page.info.borrow_mut().deprecate();
|
||||||
|
|
||||||
// Move focus out from navigation entry @TODO
|
|
||||||
self.page.browser_action.escape.activate(None);
|
|
||||||
|
|
||||||
// Initially disable find action
|
// Initially disable find action
|
||||||
self.page
|
self.page
|
||||||
.window_action
|
.window_action
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,11 @@ mod input;
|
||||||
mod navigation;
|
mod navigation;
|
||||||
mod search;
|
mod search;
|
||||||
|
|
||||||
use super::{Action as ItemAction, BrowserAction, Profile, TabAction, WindowAction};
|
use super::{Action as ItemAction, Profile, TabAction, WindowAction};
|
||||||
use adw::TabPage;
|
use adw::TabPage;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use content::Content;
|
use content::Content;
|
||||||
|
use gtk::prelude::WidgetExt;
|
||||||
use info::Info;
|
use info::Info;
|
||||||
use input::Input;
|
use input::Input;
|
||||||
use navigation::Navigation;
|
use navigation::Navigation;
|
||||||
|
|
@ -19,7 +20,6 @@ use std::{cell::RefCell, rc::Rc, sync::Arc};
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
pub profile: Arc<Profile>,
|
pub profile: Arc<Profile>,
|
||||||
// Actions
|
// Actions
|
||||||
pub browser_action: Rc<BrowserAction>,
|
|
||||||
pub item_action: Rc<ItemAction>,
|
pub item_action: Rc<ItemAction>,
|
||||||
pub window_action: Rc<WindowAction>,
|
pub window_action: Rc<WindowAction>,
|
||||||
// Components
|
// Components
|
||||||
|
|
@ -42,8 +42,7 @@ impl Page {
|
||||||
|
|
||||||
pub fn build(
|
pub fn build(
|
||||||
profile: &Arc<Profile>,
|
profile: &Arc<Profile>,
|
||||||
(browser_action, window_action, tab_action, item_action): (
|
(window_action, tab_action, item_action): (
|
||||||
&Rc<BrowserAction>,
|
|
||||||
&Rc<WindowAction>,
|
&Rc<WindowAction>,
|
||||||
&Rc<TabAction>,
|
&Rc<TabAction>,
|
||||||
&Rc<ItemAction>,
|
&Rc<ItemAction>,
|
||||||
|
|
@ -65,7 +64,6 @@ impl Page {
|
||||||
profile: profile.clone(),
|
profile: profile.clone(),
|
||||||
tab_page: tab_page.clone(),
|
tab_page: tab_page.clone(),
|
||||||
// Actions
|
// Actions
|
||||||
browser_action: browser_action.clone(),
|
|
||||||
item_action: item_action.clone(),
|
item_action: item_action.clone(),
|
||||||
window_action: window_action.clone(),
|
window_action: window_action.clone(),
|
||||||
// Components
|
// Components
|
||||||
|
|
@ -86,8 +84,14 @@ impl Page {
|
||||||
|
|
||||||
/// Request `Escape` action for all page components
|
/// Request `Escape` action for all page components
|
||||||
pub fn escape(&self) {
|
pub fn escape(&self) {
|
||||||
|
use gtk::prelude::RootExt;
|
||||||
self.search.hide();
|
self.search.hide();
|
||||||
self.navigation.escape();
|
self.navigation.escape();
|
||||||
|
self.content
|
||||||
|
.g_box
|
||||||
|
.root()
|
||||||
|
.unwrap()
|
||||||
|
.set_focus(gtk::Window::NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Toggle `Find` widget
|
/// Toggle `Find` widget
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,22 @@ impl Search {
|
||||||
g_box.append(&placeholder.label);
|
g_box.append(&placeholder.label);
|
||||||
g_box.append(&close);
|
g_box.append(&close);
|
||||||
|
|
||||||
|
// Hide widget on `Escape` key pressed
|
||||||
|
g_box.add_controller({
|
||||||
|
use gtk::{gdk::Key, glib::Propagation};
|
||||||
|
let c = gtk::EventControllerKey::new();
|
||||||
|
c.connect_key_pressed({
|
||||||
|
let g_box = g_box.clone();
|
||||||
|
move |_, k, _, _| {
|
||||||
|
if k == Key::Escape {
|
||||||
|
g_box.set_visible(false)
|
||||||
|
}
|
||||||
|
Propagation::Stop
|
||||||
|
}
|
||||||
|
});
|
||||||
|
c
|
||||||
|
});
|
||||||
|
|
||||||
// Connect events
|
// Connect events
|
||||||
close.connect_clicked({
|
close.connect_clicked({
|
||||||
let form = form.clone();
|
let form = form.clone();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue