mirror of
https://github.com/storytold/craft-libs.git
synced 2026-10-31 07:39:23 +00:00
keymap: show that an app with sets stores only Profiles and loads the active set
This commit is contained in:
1 parent
0039a5c866
commit
339aaa41df
2 files changed
+28
-5
No files matched your search
+23
-3
@@ -95,7 +95,7 @@ stay in the entry when the command is edited, unless the edit leaves it without
|
||||
`Keymap::problems` lists them.
|
||||
|
||||
```rust
|
||||
use craft_keymap::{Binding, Keymap, Overrides, Platform, Policy, Profiles, Scopes};
|
||||
use craft_keymap::{Binding, Keymap, Overrides, Platform, Policy, Scopes};
|
||||
use craft_settings::{Location, Settings, SettingsStore};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -104,7 +104,6 @@ use serde::{Deserialize, Serialize};
|
||||
struct Prefs {
|
||||
#[serde(with = "craft_keymap::keymap::overrides_list")]
|
||||
shortcuts: Overrides,
|
||||
shortcut_sets: Profiles,
|
||||
}
|
||||
|
||||
impl Settings for Prefs {
|
||||
@@ -140,9 +139,30 @@ store.update(|p| p.shortcuts = keymap.overrides().clone());
|
||||
|
||||
`Profiles` holds the user's named sets of overrides and which one is active. The app's built-in
|
||||
sets (`&[(&str, Overrides)]`, the first one the default) are passed to each call and never change.
|
||||
Put `Profiles` next to the `Overrides` in the app's settings type. The sets, and each set's
|
||||
An app with sets stores only `Profiles`, in place of the `Overrides` field above: the keymap's
|
||||
overrides are the active set's, and the dialog's OK stores them there. The sets, and each set's
|
||||
overrides, are stored as arrays, so a deleted set or entry leaves a craft-settings file.
|
||||
|
||||
```rust
|
||||
use craft_keymap::{Keymap, Platform, Profiles, Scopes};
|
||||
use craft_settings::{Location, SettingsStore};
|
||||
|
||||
#[derive(Serialize, Deserialize, Default, Clone, PartialEq)]
|
||||
#[serde(default)]
|
||||
struct Prefs {
|
||||
shortcut_sets: Profiles,
|
||||
}
|
||||
|
||||
// `builtins` is the app's &[(&str, Overrides)], the first set the default.
|
||||
let (mut store, _report) = SettingsStore::<Prefs>::open(Location::Auto);
|
||||
let mut sets = store.get().shortcut_sets.clone();
|
||||
sets.reconcile(&builtins);
|
||||
let keymap = Keymap::new(catalog, Scopes::new(), Platform::current()).with_overrides(sets.active_overrides(&builtins).clone());
|
||||
|
||||
// The dialog edits `sets` and `keymap`. On Outcome::Ok (or Changed, to save live):
|
||||
store.update(|p| p.shortcut_sets = sets.clone());
|
||||
```
|
||||
|
||||
- `names`, `get`, `active_name`, `active_overrides` (hand them to `Keymap::set_overrides`).
|
||||
- `select` switches sets; `duplicate(from, to)` copies a built-in or user set; `save_as`,
|
||||
`rename` and `delete` work on user sets only.
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
//! Without the attribute, overrides with at most one text per command are written as a table.
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use craft_keymap::{Binding, Keymap, Overrides, Platform, Policy, Profiles, Scopes};
|
||||
//! use craft_keymap::{Binding, Keymap, Overrides, Platform, Policy, Scopes};
|
||||
//! use craft_settings::{Location, Settings, SettingsStore};
|
||||
//! use serde::{Deserialize, Serialize};
|
||||
//!
|
||||
@@ -81,7 +81,6 @@
|
||||
//! struct Prefs {
|
||||
//! #[serde(with = "craft_keymap::keymap::overrides_list")]
|
||||
//! shortcuts: Overrides,
|
||||
//! shortcut_sets: Profiles,
|
||||
//! }
|
||||
//!
|
||||
//! impl Settings for Prefs {
|
||||
@@ -100,6 +99,10 @@
|
||||
//! store.update(|p| p.shortcuts = keymap.overrides().clone());
|
||||
//! ```
|
||||
//!
|
||||
//! An app with named sets stores only [`Profiles`] in place of the `Overrides` field and builds
|
||||
//! the keymap from the active set:
|
||||
//! `with_overrides(prefs.shortcut_sets.active_overrides(&builtins).clone())`.
|
||||
//!
|
||||
//! # Importing a shortcut set
|
||||
//!
|
||||
//! The app's reader builds a [`ForeignSet`]; [`plan`] matches it without changing anything, so a
|
||||
|
||||
Reference in new issue
Block a user