refactor: capture Escape in subscription
If the event status of a key event is captured by a widget, the libcosmic tab subscription will ignore it, but we can manually capture it in cosmic-files for its dialogs and handle it ourselves. Alternatively, the subscription could capture events regardless of status, and include it as an argument to on_escape.
This commit is contained in:
parent
1a465ffd7a
commit
a2f81cdcf0
2 changed files with 266 additions and 265 deletions
513
Cargo.lock
generated
513
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -10,15 +10,15 @@ use cosmic::{
|
||||||
core::SmolStr,
|
core::SmolStr,
|
||||||
event,
|
event,
|
||||||
futures::{self, SinkExt},
|
futures::{self, SinkExt},
|
||||||
keyboard::{Event as KeyEvent, Key, Modifiers},
|
keyboard::{Event as KeyEvent, Key, Modifiers, key::Named},
|
||||||
stream, window,
|
stream, window,
|
||||||
},
|
},
|
||||||
iced_core::widget::operation,
|
iced_core::widget::operation,
|
||||||
theme,
|
theme,
|
||||||
widget::{
|
widget::{
|
||||||
self,
|
self, Operation,
|
||||||
menu::{key_bind::Modifier, Action as MenuAction, KeyBind},
|
menu::{Action as MenuAction, KeyBind, key_bind::Modifier},
|
||||||
segmented_button, Operation,
|
segmented_button,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use notify_debouncer_full::{
|
use notify_debouncer_full::{
|
||||||
|
|
@ -416,6 +416,7 @@ enum Message {
|
||||||
DialogCancel,
|
DialogCancel,
|
||||||
DialogComplete,
|
DialogComplete,
|
||||||
DialogUpdate(DialogPage),
|
DialogUpdate(DialogPage),
|
||||||
|
Escape,
|
||||||
Filename(String),
|
Filename(String),
|
||||||
Filter(usize),
|
Filter(usize),
|
||||||
Key(Modifiers, Key, Option<SmolStr>),
|
Key(Modifiers, Key, Option<SmolStr>),
|
||||||
|
|
@ -1346,6 +1347,7 @@ impl Application for App {
|
||||||
self.dialog_pages[0] = dialog_page;
|
self.dialog_pages[0] = dialog_page;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::Escape => return self.on_escape(),
|
||||||
Message::Filename(new_filename) => {
|
Message::Filename(new_filename) => {
|
||||||
// Select based on filename
|
// Select based on filename
|
||||||
self.tab.select_name(&new_filename);
|
self.tab.select_name(&new_filename);
|
||||||
|
|
@ -1977,7 +1979,13 @@ impl Application for App {
|
||||||
..
|
..
|
||||||
}) => match status {
|
}) => match status {
|
||||||
event::Status::Ignored => Some(Message::Key(modifiers, key, text)),
|
event::Status::Ignored => Some(Message::Key(modifiers, key, text)),
|
||||||
event::Status::Captured => None,
|
event::Status::Captured => {
|
||||||
|
if key == Key::Named(Named::Escape) {
|
||||||
|
Some(Message::Escape)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
|
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
|
||||||
Some(Message::ModifiersChanged(modifiers))
|
Some(Message::ModifiersChanged(modifiers))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue