Merge pull request #2478 from aiongg/menu-gate-memo-key

menu: Gate and ModalRules key the runtime's command gate
This commit is contained in:
aiongg authored and GitHub committed 2026-11-19 22:36:31 -05:00
commit 7efbe8bb61
3 files changed
+22 -3

No files matched your search

+3
View File
@@ -137,6 +137,9 @@ const NO_GLOBAL_STATE_PREFIXES: &[&str] = &[
const NO_GLOBAL_STATE: &[(&str, &str)] = &[
// The trait's home crate: it implements `MemoProps` by hand for std and framework value types.
("crates/ui-contract/src/contract/memo.rs", "MemoProps"),
// Settled fact: `ModalRules` holds a closure the derive cannot take; it keys on its plain fields and the revision
// the app moves with every rule change, which stands for the closure.
("crates/menu/src/modal.rs", "MemoProps"),
// Settled fact: constant font bytes, decompressed once from compile-time input and immutable after init.
("crates/ui-contract/src/fonts/defaults.rs", "HACK"),
("crates/ui-contract/src/fonts/defaults.rs", "EGUI_ICONS"),
+4 -2
View File
@@ -5,6 +5,7 @@ use std::collections::HashSet;
use std::sync::{Arc, Mutex, MutexGuard, PoisonError};
use craft_keymap::{Chord, CommandRef, Key, Mods};
use craft_ui::contract::MemoProps;
use craft_ui::runtime::windows::{KeyEquivalent, WindowAction, WindowHost};
use crate::layout::{Clash, Layout};
@@ -45,8 +46,9 @@ pub enum ClipboardKeys {
Raw,
}
/// What may run from the menus this frame, set by the app.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
/// What may run from the menus this frame, set by the app. As props of the runtime's command gate, every flag feeds
/// the key.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, MemoProps)]
#[non_exhaustive]
pub struct Gate {
/// A modal dialog is open.
+15 -1
View File
@@ -12,6 +12,7 @@ use std::fmt;
use std::sync::Arc;
use craft_keymap::CommandRef;
use craft_ui::contract::{MemoKey, MemoProps};
use crate::driver::Gate;
use crate::model::{Builtin, Item};
@@ -49,7 +50,8 @@ pub struct ModalRules {
/// run. `None`: no pending operation.
pub pending: Option<PendingRule>,
/// The caller's count of rule changes. A rule holds a closure and cannot be compared, so the
/// caller says when the rules changed; the menu skips the resync while it stays the same.
/// caller says when the rules changed; the menu skips the resync, and the runtime's command gate keeps its answers,
/// while it stays the same.
pub revision: u64,
}
@@ -86,6 +88,18 @@ impl ModalRules {
}
}
/// As props of the runtime's command gate: the plain fields and [`ModalRules::revision`], which stands for the
/// [`ModalRules::pending`] closure. The derive cannot take the closure, and the revision is the caller's count of rule
/// changes, so equal keys mean equal rules as long as the caller moves it with every change.
impl MemoProps for ModalRules {
fn key(&self, key: &mut MemoKey) {
let ModalRules { in_dialogs, workspace, pending: _, revision } = self;
in_dialogs.key(key);
workspace.key(key);
revision.key(key);
}
}
impl fmt::Debug for ModalRules {
// new: `PendingRule` is a closure; print whether one is set.
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {