From c9ef64eb7a552a09de24e221f3b0874e05dcdc5f Mon Sep 17 00:00:00 2001 From: Simon Desloges Date: Sat, 10 Jul 2021 20:01:37 -0400 Subject: [PATCH] Implement Select All/Deselect All layers (#242) * Implement select all layers shortcut * Adjust menu entry for Select All Layers * Avoid selecting the root of the document when selecting all layers * Implement deselect all layers * Fix formatting * Add extensions.json so VS Code recommends useful extensions * Add rust-analyzer as the default Rust formatter --- .vscode/extensions.json | 3 +++ .vscode/settings.json | 3 ++- .../components/widgets/inputs/MenuBarInput.vue | 10 ++++++++++ client/web/wasm/src/document.rs | 14 ++++++++++++++ .../src/document/document_message_handler.rs | 18 +++++++++++++++--- core/editor/src/input/input_mapper.rs | 2 ++ 6 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..06e99e1d1 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["matklad.rust-analyzer", "dbaeumer.vscode-eslint", "octref.vetur", "formulahendry.auto-close-tag"] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 393af3659..578dfa120 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,8 @@ { "[rust]": { "editor.formatOnSave": true, - "editor.formatOnPaste": true + "editor.formatOnPaste": true, + "editor.defaultFormatter": "matklad.rust-analyzer", }, "[typescript, javascript, json, vue]": { "editor.codeActionsOnSave": { diff --git a/client/web/src/components/widgets/inputs/MenuBarInput.vue b/client/web/src/components/widgets/inputs/MenuBarInput.vue index 46c2aa118..0bc2731be 100644 --- a/client/web/src/components/widgets/inputs/MenuBarInput.vue +++ b/client/web/src/components/widgets/inputs/MenuBarInput.vue @@ -119,6 +119,16 @@ const menuEntries: MenuListEntries = [ ref: undefined, children: [[{ label: "Menu not yet populated" }]], }, + { + label: "Layer", + ref: undefined, + children: [ + [ + { label: "Select All", shortcut: ["Ctrl", "A"], action: async () => (await wasm).select_all_layers() }, + { label: "Deselect All", shortcut: ["Ctrl", "Alt", "A"], action: async () => (await wasm).deselect_all_layers() }, + ], + ], + }, { label: "View", ref: undefined, diff --git a/client/web/wasm/src/document.rs b/client/web/wasm/src/document.rs index 70cdf049d..039277178 100644 --- a/client/web/wasm/src/document.rs +++ b/client/web/wasm/src/document.rs @@ -113,6 +113,20 @@ pub fn undo() -> Result<(), JsValue> { EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::Undo)).map_err(convert_error) } +/// Select all layers +#[wasm_bindgen] +pub fn select_all_layers() -> Result<(), JsValue> { + EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::SelectAllLayers)).map_err(convert_error) +} + +/// Select all layers +#[wasm_bindgen] +pub fn deselect_all_layers() -> Result<(), JsValue> { + EDITOR_STATE + .with(|editor| editor.borrow_mut().handle_message(DocumentMessage::DeselectAllLayers)) + .map_err(convert_error) +} + /// Export the document #[wasm_bindgen] pub fn export_document() -> Result<(), JsValue> { diff --git a/core/editor/src/document/document_message_handler.rs b/core/editor/src/document/document_message_handler.rs index 106a506c9..d4c6190f9 100644 --- a/core/editor/src/document/document_message_handler.rs +++ b/core/editor/src/document/document_message_handler.rs @@ -13,6 +13,8 @@ use std::collections::VecDeque; pub enum DocumentMessage { DispatchOperation(DocumentOperation), SelectLayers(Vec>), + SelectAllLayers, + DeselectAllLayers, DeleteLayer(Vec), DeleteSelectedLayers, DuplicateSelectedLayers, @@ -275,7 +277,6 @@ impl MessageHandler for DocumentMessageHand responses.push_back(DocumentOperation::PasteLayer { layer: layer.clone(), path: vec![] }.into()) } } - SelectLayers(paths) => { self.clear_selection(); for path in paths { @@ -284,6 +285,17 @@ impl MessageHandler for DocumentMessageHand // TODO: Correctly update layer panel in clear_selection instead of here responses.extend(self.handle_folder_changed(Vec::new())); } + SelectAllLayers => { + let all_layer_paths = self.active_document().layer_data.keys().filter(|path| !path.is_empty()).cloned().collect::>(); + for path in all_layer_paths { + responses.extend(self.select_layer(&path)); + } + } + DeselectAllLayers => { + self.clear_selection(); + let children = self.active_document_mut().layer_panel(&[]).expect("The provided Path was not valid"); + responses.push_back(FrontendMessage::ExpandFolder { path: vec![], children }.into()); + } Undo => { // this is a temporary fix and will be addressed by #123 if let Some(id) = self.active_document().document.root.as_folder().unwrap().list_layers().last() { @@ -344,9 +356,9 @@ impl MessageHandler for DocumentMessageHand } fn actions(&self) -> ActionList { if self.active_document().layer_data.values().any(|data| data.selected) { - actions!(DocumentMessageDiscriminant; Undo, DeleteSelectedLayers, DuplicateSelectedLayers, RenderDocument, ExportDocument, NewDocument, CloseActiveDocument, NextDocument, PrevDocument, MouseMove, TranslateUp, TranslateDown, CopySelectedLayers, PasteLayers, ) + actions!(DocumentMessageDiscriminant; Undo, SelectAllLayers, DeselectAllLayers, DeleteSelectedLayers, DuplicateSelectedLayers, RenderDocument, ExportDocument, NewDocument, CloseActiveDocument, NextDocument, PrevDocument, MouseMove, TranslateUp, TranslateDown, CopySelectedLayers, PasteLayers, ) } else { - actions!(DocumentMessageDiscriminant; Undo, RenderDocument, ExportDocument, NewDocument, CloseActiveDocument, NextDocument, PrevDocument, MouseMove, TranslateUp, TranslateDown, PasteLayers) + actions!(DocumentMessageDiscriminant; Undo, SelectAllLayers, DeselectAllLayers, RenderDocument, ExportDocument, NewDocument, CloseActiveDocument, NextDocument, PrevDocument, MouseMove, TranslateUp, TranslateDown, PasteLayers) } } } diff --git a/core/editor/src/input/input_mapper.rs b/core/editor/src/input/input_mapper.rs index d8fb62afb..fb797242a 100644 --- a/core/editor/src/input/input_mapper.rs +++ b/core/editor/src/input/input_mapper.rs @@ -170,6 +170,8 @@ impl Default for Mapping { entry! {action=ToolMessage::SwapColors, key_down=KeyX, modifiers=[KeyShift]}, // Document Actions entry! {action=DocumentMessage::Undo, key_down=KeyZ, modifiers=[KeyControl]}, + entry! {action=DocumentMessage::DeselectAllLayers, key_down=KeyA, modifiers=[KeyControl, KeyAlt]}, + entry! {action=DocumentMessage::SelectAllLayers, key_down=KeyA, modifiers=[KeyControl]}, entry! {action=DocumentMessage::DeleteSelectedLayers, key_down=KeyDelete}, entry! {action=DocumentMessage::DeleteSelectedLayers, key_down=KeyX}, entry! {action=DocumentMessage::DeleteSelectedLayers, key_down=KeyBackspace},