mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-30 18:13:53 +01:00
Ctrl+Q quits from a text field, a dialog and a floating panel's window
As before the move to the craft-ui runtime, Ctrl+Q asks the main window to close whatever has the keyboard there, so unsaved work is asked about. In a floating panel's own window, where the key closed only that window, it asks in the same way. The runtime's Quit command runs the key.
This commit is contained in:
1 parent
736e86a961
commit
da7c19d803
2 files changed
+12
-7
No files matched your search
@@ -16,7 +16,7 @@ use craft_host::target::ShellInfo;
|
||||
use craft_host::{AppInfo, Host};
|
||||
use craft_keymap::{Chord, Key, Overrides};
|
||||
use craft_ui::fonts::{I18nScripts, SystemFonts, UiFonts};
|
||||
use craft_ui::runtime::commands::{CommandInput, CommandSet as _, NavCommand, QuitCommand};
|
||||
use craft_ui::runtime::commands::{CommandInput, CommandSet as _, NavCommand};
|
||||
use craft_ui::runtime::env::{RootEnv, Scale};
|
||||
use craft_ui::runtime::focus::{self, EditSet, FocusTarget, KeyUse};
|
||||
use craft_ui::runtime::frame::{FrameInput, FrameOutput};
|
||||
@@ -90,15 +90,14 @@ pub(crate) fn host() -> Arc<Host> {
|
||||
)
|
||||
}
|
||||
|
||||
/// MaterialCraft quits with its own `ui.quit` (File > Exit, Ctrl+Q), which its shortcuts read from egui, so the
|
||||
/// framework's `window.quit` is unbound. So are its F6 and Shift+F6 pane moves: Preferences > Shortcuts assigns any
|
||||
/// chord to a node. Overrides are keyed by command id, which the command set gives.
|
||||
/// Preferences > Shortcuts assigns any chord to a node, so the runtime's F6 and Shift+F6 pane moves are unbound.
|
||||
/// Overrides are keyed by command id, which the command set gives.
|
||||
fn command_overrides() -> Arc<Overrides> {
|
||||
static OVERRIDES: OnceLock<Arc<Overrides>> = OnceLock::new();
|
||||
OVERRIDES
|
||||
.get_or_init(|| {
|
||||
let mut overrides = Overrides::new();
|
||||
for id in [QuitCommand::Quit.id(), NavCommand::NextPane.id(), NavCommand::PreviousPane.id()] {
|
||||
for id in [NavCommand::NextPane.id(), NavCommand::PreviousPane.id()] {
|
||||
overrides.insert(id, Vec::new());
|
||||
}
|
||||
Arc::new(overrides)
|
||||
@@ -117,7 +116,7 @@ impl MaterialCraftApp {
|
||||
}
|
||||
|
||||
/// The root values of this frame. MaterialCraft registers no commands with the runtime (it unbinds the framework's
|
||||
/// quit and pane moves, [`command_overrides`]) and lets it toggle no chrome, so the output carries nothing it acts on. While one of MaterialCraft's own egui modals shows in the
|
||||
/// pane moves, [`command_overrides`]) and lets it toggle no chrome, so the output carries nothing it acts on. While one of MaterialCraft's own egui modals shows in the
|
||||
/// root window, the runtime blocks the panels floated into windows of their own.
|
||||
pub(crate) fn frame_input(&mut self, ctx: &egui::Context, _output: FrameOutput, scale: f32) -> FrameInput {
|
||||
use crate::theme::Brightness;
|
||||
|
||||
@@ -503,7 +503,13 @@ pub fn shortcuts(app: &mut MaterialCraftApp, ctx: &egui::Context) {
|
||||
app.dispatcher.dispatch_filtered(i, &app.keymap, |hit| {
|
||||
let id = hit.command.id.as_str();
|
||||
let keeps_escape = id == "ui.cook.cancel" && (!app.cooker.busy() || gesture_in_progress || node_search_open || label_selected);
|
||||
modality.allows(id) && !(label_selected && matches!(id, "edit.copy" | "edit.cut")) && !unavailable_clipboard_commands.contains(&id) && !keeps_escape
|
||||
// The runtime's Quit runs Ctrl+Q, in the panels' own windows and from text fields too
|
||||
let runtime_quits = id == "ui.quit";
|
||||
modality.allows(id)
|
||||
&& !runtime_quits
|
||||
&& !(label_selected && matches!(id, "edit.copy" | "edit.cut"))
|
||||
&& !unavailable_clipboard_commands.contains(&id)
|
||||
&& !keeps_escape
|
||||
})
|
||||
});
|
||||
for hit in hits {
|
||||
|
||||
Reference in new issue
Block a user