From 48c41df0548bc2615009ce3a892f0fb802980bf9 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Tue, 29 Oct 2024 12:59:34 +0100 Subject: [PATCH] :tada: Rename selected layer via shortcut and context menu option --- CHANGES.md | 2 ++ frontend/src/app/main/data/workspace.cljs | 16 ++++++++++++++++ .../src/app/main/data/workspace/shortcuts.cljs | 5 ++++- .../src/app/main/ui/workspace/context_menu.cljs | 11 +++++++++++ frontend/translations/en.po | 4 ++++ frontend/translations/es.po | 5 +++++ 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 3d2938f6e..d150bddba 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,9 +17,11 @@ - Viewer role for team members [Taiga #1056 & #6590](https://tree.taiga.io/project/penpot/us/1056 & https://tree.taiga.io/project/penpot/us/6590) - File history versions management [Taiga](https://tree.taiga.io/project/penpot/us/187?milestone=411120) +- Rename selected layer via keyboard shortcut and context menu option [Taiga #8882](https://tree.taiga.io/project/penpot/us/8882) ### :bug: Bugs fixed + ## 2.3.1 ### :bug: Bugs fixed diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 4fb840c68..64f2550f0 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -100,6 +100,7 @@ (declare ^:private workspace-initialized) (declare ^:private libraries-fetched) +(declare go-to-layout) ;; --- Initialize Workspace @@ -810,6 +811,21 @@ (d/not-empty? hover-guides) (rx/of (dwgu/remove-guides hover-guides))))))) + +;; --- Start renaming selected shape + +(defn start-rename-selected + "Rename selected shape." + [] + (ptk/reify ::start-rename-selected + ptk/WatchEvent + (watch [_ state _] + (let [selected (wsh/lookup-selected state) + id (first selected)] + (when (= (count selected) 1) + (rx/of (go-to-layout :layers) + (start-rename-shape id))))))) + ;; --- Shape Vertical Ordering (def valid-vertical-locations diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index 1bf35f699..3e87114af 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -129,9 +129,12 @@ :subsections [:edit] :fn #(st/emit! esc-pressed)} - ;; MODIFY LAYERS + :rename {:tooltip (ds/alt "N") + :command "alt+n" + :subsections [:edit] + :fn #(emit-when-no-readonly (dw/start-rename-selected))} :group {:tooltip (ds/meta "G") :command (ds/c-mod "g") diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index d3e0e3122..2cdc3eebb 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -226,6 +226,16 @@ :on-click do-toggle-thumbnail}]) [:& menu-separator]]))) +(mf/defc context-menu-rename + [{:keys [shapes]}] + (let [do-rename #(st/emit! (dw/start-rename-selected))] + (when (= (count shapes) 1) + [:* + [:& menu-separator] + [:& menu-entry {:title (tr "workspace.shape.menu.rename") + :shortcut (sc/get-tooltip :rename) + :on-click do-rename}]]))) + (mf/defc context-menu-group [{:keys [shapes]}] @@ -501,6 +511,7 @@ [:> context-menu-layer-position props] [:> context-menu-flip props] [:> context-menu-thumbnail props] + [:> context-menu-rename props] [:> context-menu-group props] [:> context-focus-mode-menu props] [:> context-menu-path props] diff --git a/frontend/translations/en.po b/frontend/translations/en.po index 8a26dcf90..a28edd422 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -5956,6 +5956,10 @@ msgstr "Bring to front" msgid "workspace.shape.menu.go-main" msgstr "Go to main component file" +#: src/app/main/ui/workspace/context_menu.cljs:234 +msgid "workspace.shape.menu.rename" +msgstr "Rename" + #: src/app/main/ui/workspace/context_menu.cljs:261 msgid "workspace.shape.menu.group" msgstr "Group" diff --git a/frontend/translations/es.po b/frontend/translations/es.po index 893b3a263..62a3bf10b 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -5934,6 +5934,11 @@ msgstr "Mover al frente" msgid "workspace.shape.menu.go-main" msgstr "Ir al archivo del componente principal" +#: src/app/main/ui/workspace/context_menu.cljs:234 +msgid "workspace.shape.menu.rename" +msgstr "Renombrar" + + #: src/app/main/ui/workspace/context_menu.cljs:261 msgid "workspace.shape.menu.group" msgstr "Agrupar"