mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Command dialogs: restrict edits to their target document
This commit is contained in:
5 files changed
+68
-5
No files matched your search
@@ -988,7 +988,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.paramDialog",
|
||||
"Command Dialog",
|
||||
"",
|
||||
"{command, label?, params} open a parameter dialog for any command. For edit.findReplace it opens Find and Replace (dialog `findReplace`), which stays open: fields find, replace, matchCase, wholeWord, backwards, hiddenLayers, lockedLayers, and action, which ui.dialog.confirm runs: find (the next match, edit.findNext, shown in the dialog with its place among the matches), replace (the match found, edit.replaceMatch), replaceFind (both), replaceAll (edit.findReplace) or done (close). After each one action is find again. Replace and Replace & Find change a match that find reached with the find text and options as they are now, and find one otherwise. The dialog opens on the last search, with the fields params gives in its place (a null field gives none; a field of the wrong type is an error, and ui.dialog.confirm then runs no action), and Edit › Find Next goes on from it in the same document while the dialog is closed",
|
||||
"{command, label?, params} open a parameter dialog for any command. For commands other than edit.findReplace, params.__doc may be an unsigned document uid: the dialog previews and confirms only while that document is active, and OK after a document switch closes it without running the command. An invalid __doc is an error; omitting it keeps the existing behavior. For edit.findReplace it opens Find and Replace (dialog `findReplace`), which stays open: fields find, replace, matchCase, wholeWord, backwards, hiddenLayers, lockedLayers, and action, which ui.dialog.confirm runs: find (the next match, edit.findNext, shown in the dialog with its place among the matches), replace (the match found, edit.replaceMatch), replaceFind (both), replaceAll (edit.findReplace) or done (close). After each one action is find again. Replace and Replace & Find change a match that find reached with the find text and options as they are now, and find one otherwise. The dialog opens on the last search, with the fields params gives in its place (a null field gives none; a field of the wrong type is an error, and ui.dialog.confirm then runs no action), and Edit › Find Next goes on from it in the same document while the dialog is closed",
|
||||
),
|
||||
(
|
||||
"ui.recolorDialog",
|
||||
|
||||
@@ -44,6 +44,8 @@ struct Open {
|
||||
preview: LivePreview,
|
||||
/// Set Role Swatch: the role the Swatch row was last filled for.
|
||||
filled_for: Option<String>,
|
||||
/// The document whose objects the dialog edits, when its caller supplies `__doc`.
|
||||
doc: Option<u64>,
|
||||
/// Names this dialog's own open among reopenings of the same command, for its OK and Cancel.
|
||||
token: Arc<()>,
|
||||
}
|
||||
@@ -66,10 +68,16 @@ impl Setting {
|
||||
}
|
||||
|
||||
/// Opens the parameter dialog of `command`, headed `label`, on `params` (a menu item's own values, `__params` for the
|
||||
/// fixed ones and `__rowGutterLinked` for Area Type Options' linked Row Gutter).
|
||||
/// fixed ones, `__rowGutterLinked` for Area Type Options' linked Row Gutter, and `__doc` for a document uid).
|
||||
pub(crate) fn open(app: &mut VectorcraftApp, command: &str, label: &str, mut params: Map<String, Value>) -> Result<Value, String> {
|
||||
let doc = match params.remove("__doc") {
|
||||
None => None,
|
||||
Some(value) => Some(value.as_u64().ok_or("`__doc` must be a document id")?),
|
||||
};
|
||||
let ctx = app.ui_ctx.clone().ok_or("no window")?;
|
||||
if let Some(old) = app.command_dialog.open.take() {
|
||||
if let Some(old) = app.command_dialog.open.take()
|
||||
&& on_document(app, &old)
|
||||
{
|
||||
old.preview.cancel(app);
|
||||
}
|
||||
let fixed = match params.remove("__params") {
|
||||
@@ -104,6 +112,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, command: &str, label: &str, mut par
|
||||
previews,
|
||||
preview: LivePreview::default(),
|
||||
filled_for: None,
|
||||
doc,
|
||||
token,
|
||||
});
|
||||
Ok(Value::Null)
|
||||
@@ -121,6 +130,9 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) {
|
||||
}
|
||||
|
||||
fn step(app: &mut VectorcraftApp, open: &mut Open) {
|
||||
if !on_document(app, open) {
|
||||
return;
|
||||
}
|
||||
let Some(dialogs) = app.dialogs() else { return };
|
||||
let id = open.id;
|
||||
let seen = dialogs.with(|h| h.get_by_id::<HostedParamDialog>(id).map(|d| (d.fields().clone(), d.is_previewing())));
|
||||
@@ -165,6 +177,9 @@ fn step(app: &mut VectorcraftApp, open: &mut Open) {
|
||||
/// error keeps it open with the reason under its rows.
|
||||
fn confirm(app: &mut VectorcraftApp, token: &Arc<()>, fields: &DialogFields) -> Result<Value, String> {
|
||||
let open = app.command_dialog.open.take_if(|o| Arc::ptr_eq(&o.token, token)).ok_or("the dialog is gone")?;
|
||||
if !on_document(app, &open) {
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
let params = command_params(&open.command, &open.opening, Setting::of(app));
|
||||
let value = call(&open.command, &open.fixed, open.linked, form::json_of(¶ms, fields));
|
||||
let result = if open.previews {
|
||||
@@ -185,11 +200,17 @@ fn confirm(app: &mut VectorcraftApp, token: &Arc<()>, fields: &DialogFields) ->
|
||||
|
||||
/// Cancel: rolls back the preview of the dialog `token` names.
|
||||
fn cancel(app: &mut VectorcraftApp, token: &Arc<()>) {
|
||||
if let Some(open) = app.command_dialog.open.take_if(|o| Arc::ptr_eq(&o.token, token)) {
|
||||
if let Some(open) = app.command_dialog.open.take_if(|o| Arc::ptr_eq(&o.token, token))
|
||||
&& on_document(app, &open)
|
||||
{
|
||||
open.preview.cancel(app);
|
||||
}
|
||||
}
|
||||
|
||||
fn on_document(app: &VectorcraftApp, open: &Open) -> bool {
|
||||
open.doc.is_none_or(|uid| app.session.active().is_some_and(|st| st.uid == uid))
|
||||
}
|
||||
|
||||
/// The rows of `command`'s dialog: one per value it opens with that the command takes, in `order(command)` first and
|
||||
/// the rest by name, Area Type Options' Text Flow last.
|
||||
fn command_params(command: &str, opening: &Map<String, Value>, setting: Setting) -> Vec<Param> {
|
||||
@@ -742,6 +763,41 @@ mod tests {
|
||||
|
||||
/// The choices this dialog lists for Rasterize, Create Gradient Mesh and Repeat Options are the
|
||||
/// values their commands take (#8020, #7991): each one runs, and every language with complete
|
||||
#[test]
|
||||
fn document_scoped_dialog_confirms_only_in_its_opening_document() {
|
||||
for (scoped, switch) in [(true, false), (true, true), (false, true)] {
|
||||
let mut app = windowed();
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
let mut params = json!({"x": 10, "y": 10, "width": 20, "height": 20}).as_object().unwrap().clone();
|
||||
if scoped {
|
||||
params.insert("__doc".into(), json!(app.session.active().unwrap().uid));
|
||||
}
|
||||
open(&mut app, "shape.rectangle", "Rectangle", params).unwrap();
|
||||
pump(&mut app);
|
||||
if switch {
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
}
|
||||
answer_ok(&mut app);
|
||||
assert!(app.command_dialog.open.is_none());
|
||||
assert_eq!(app.session.active().unwrap().selection.is_empty(), scoped && switch);
|
||||
if switch {
|
||||
assert!(app.session.set_active(0));
|
||||
assert!(app.session.active().unwrap().selection.is_empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn document_scoped_dialog_rejects_an_invalid_document_id() {
|
||||
for doc in [json!(null), json!("1"), json!(-1), json!(1.5)] {
|
||||
let mut app = windowed();
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
let params = json!({"width": 20, "height": 20, "__doc": doc}).as_object().unwrap().clone();
|
||||
assert!(open(&mut app, "shape.rectangle", "Rectangle", params).is_err(), "{doc}");
|
||||
assert!(app.command_dialog.open.is_none());
|
||||
}
|
||||
}
|
||||
|
||||
/// menus has a row for each label.
|
||||
#[test]
|
||||
fn choice_fields_list_the_values_their_commands_take() {
|
||||
|
||||
@@ -989,7 +989,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.paramDialog",
|
||||
"Command Dialog",
|
||||
"",
|
||||
"{command, label?, params} open a parameter dialog for any command. For edit.findReplace it opens Find and Replace (dialog `findReplace`), which stays open: fields find, replace, matchCase, wholeWord, backwards, hiddenLayers, lockedLayers, and action, which ui.dialog.confirm runs: find (the next match, edit.findNext, shown in the dialog with its place among the matches), replace (the match found, edit.replaceMatch), replaceFind (both), replaceAll (edit.findReplace) or done (close). After each one action is find again. Replace and Replace & Find change a match that find reached with the find text and options as they are now, and find one otherwise. The dialog opens on the last search, with the fields params gives in its place (a null field gives none; a field of the wrong type is an error, and ui.dialog.confirm then runs no action), and Edit › Find Next goes on from it in the same document while the dialog is closed",
|
||||
"{command, label?, params} open a parameter dialog for any command. For commands other than edit.findReplace, params.__doc may be an unsigned document uid: the dialog previews and confirms only while that document is active, and OK after a document switch closes it without running the command. An invalid __doc is an error; omitting it keeps the existing behavior. For edit.findReplace it opens Find and Replace (dialog `findReplace`), which stays open: fields find, replace, matchCase, wholeWord, backwards, hiddenLayers, lockedLayers, and action, which ui.dialog.confirm runs: find (the next match, edit.findNext, shown in the dialog with its place among the matches), replace (the match found, edit.replaceMatch), replaceFind (both), replaceAll (edit.findReplace) or done (close). After each one action is find again. Replace and Replace & Find change a match that find reached with the find text and options as they are now, and find one otherwise. The dialog opens on the last search, with the fields params gives in its place (a null field gives none; a field of the wrong type is an error, and ui.dialog.confirm then runs no action), and Edit › Find Next goes on from it in the same document while the dialog is closed",
|
||||
),
|
||||
(
|
||||
"ui.recolorDialog",
|
||||
|
||||
@@ -12389,6 +12389,11 @@ the dialog on the last search, with the fields its `params` give in its place. A
|
||||
the wrong type is an error that leaves the dialog closed. Once it is open, `ui.dialog.confirm` with a field of the
|
||||
wrong type runs no action and returns the error.
|
||||
|
||||
For other command dialogs, `params.__doc` can supply a document uid. The dialog previews and confirms only while
|
||||
that document is active. Confirming after a document switch closes the dialog without running its command.
|
||||
Canceling or replacing that dialog does not cancel an interaction in another document. A supplied `__doc` must be
|
||||
an unsigned integer; omitting it preserves the command dialog's existing behavior.
|
||||
|
||||
|
||||
## Justification options
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
|
||||
## Feature submission evidence
|
||||
|
||||
- Command dialogs can keep the uid of the document they edit. Their preview, confirmation, and cancellation do not change another active document. Tests cover confirmation in the original and another document, unscoped dialogs, and invalid document ids.
|
||||
|
||||
Variables panel row context menus (2026-11-20, G12): Right-click highlights the clicked variable without changing the canvas selection and offers Select Bound Object, Variable Options…, Unbind Variable, the four Make Dynamic actions, and Delete Variable. Shift+F10 opens the same menu for the focused row; Escape dismisses it. Row actions target that variable; dynamic actions use the canvas selection. Lock and selection checks disable unavailable actions. Headless pointer/accessibility tests cover opening the menu, highlighting, bound-object selection, deletion in one undo step and restoration, and disabled actions. Scores and estimates unchanged.
|
||||
|
||||
Actions panel item context menus (2026-11-20): Right-clicking an Action Set row selects it and presents a context menu with New Action…, New Set…, Duplicate Set, Delete Set, and Set Options…. Right-clicking an Action row selects it and presents a context menu with Play, Record, Duplicate, Delete, Action Options…, and Batch…. Duplicate on an action duplicates that action and selects the duplicate; Delete removes it. Headless tests in `crates/ui-egui/src/panels/actions.rs`: `right_clicking_an_action_set_selects_it_and_presents_set_context_options`, `right_clicking_an_action_selects_it_and_presents_action_options`, and `clicking_duplicate_on_an_action_duplicates_that_action_in_the_set`. Scores and estimates unchanged.
|
||||
|
||||
Reference in new issue
Block a user