Adds edition shortcut and context menu item

This commit is contained in:
alonso.torres 2021-02-12 12:12:39 +01:00 committed by Andrés Moya
parent 6c2b5ff0c7
commit d86dc608b0
7 changed files with 64 additions and 11 deletions

View file

@ -5,7 +5,8 @@
### New features ### New features
- Bounce & Complaint handling. - Bounce & Complaint handling.
- Disable groups interactions when holding "Ctrl" key (deep selection)
- New action in context menu to "edit" some shapes (binded to key "Enter")
### Bugs fixed ### Bugs fixed

View file

@ -4841,5 +4841,11 @@
"en" : "Flip vertical", "en" : "Flip vertical",
"es" : "Voltear vertical" "es" : "Voltear vertical"
} }
},
"workspace.shape.menu.edit" : {
"translations" : {
"en" : "Edit",
"es" : "Editar"
}
} }
} }

View file

@ -24,6 +24,7 @@
(def mac-shift "\u21E7") (def mac-shift "\u21E7")
(def mac-control "\u2303") (def mac-control "\u2303")
(def mac-esc "\u238B") (def mac-esc "\u238B")
(def mac-enter "\u23CE")
(def left-arrow "\u2190") (def left-arrow "\u2190")
(def up-arrow "\u2191") (def up-arrow "\u2191")
@ -73,3 +74,7 @@
mac-esc mac-esc
"Escape")) "Escape"))
(defn enter []
(if (cfg/check-platform? :macos)
mac-enter
"Enter"))

View file

@ -1089,6 +1089,31 @@
(rx/of (relocate-shapes selected parent-id to-index)))))) (rx/of (relocate-shapes selected parent-id to-index))))))
(defn start-editing-selected
[]
(ptk/reify ::start-editing-selected
ptk/WatchEvent
(watch [_ state stream]
(let [selected (get-in state [:workspace-local :selected])]
(if-not (= 1 (count selected))
(rx/empty)
(let [objects (dwc/lookup-page-objects state)
{:keys [id type shapes]} (get objects (first selected))]
(case type
:text
(rx/of (dwc/start-edition-mode id))
:group
(rx/of (dwc/select-shapes (into (d/ordered-set) [(last shapes)])))
:path
(rx/of (dwc/start-edition-mode id)
(dwdp/start-path-edit id))
:else (rx/empty))))))))
;; --- Change Page Order (D&D Ordering) ;; --- Change Page Order (D&D Ordering)
(defn relocate-page (defn relocate-page

View file

@ -255,7 +255,12 @@
:escape {:tooltip (ds/esc) :escape {:tooltip (ds/esc)
:command "escape" :command "escape"
:fn #(st/emit! (esc-pressed))}}) :fn #(st/emit! (esc-pressed))}
:start-editing {:tooltip (ds/enter)
:command "enter"
:fn #(st/emit! (dw/start-editing-selected))}
})
(defn get-tooltip [shortcut] (defn get-tooltip [shortcut]
(assert (contains? shortcuts shortcut) (str shortcut)) (assert (contains? shortcuts shortcut) (str shortcut))

View file

@ -24,6 +24,7 @@
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :refer [t] :as i18n] [app.util.i18n :refer [t] :as i18n]
[app.util.timers :as timers]
[beicon.core :as rx] [beicon.core :as rx]
[okulary.core :as l] [okulary.core :as l]
[potok.core :as ptk] [potok.core :as ptk]
@ -53,6 +54,10 @@
{:keys [id] :as shape} (:shape mdata) {:keys [id] :as shape} (:shape mdata)
selected (:selected mdata) selected (:selected mdata)
single? (= (count selected) 1)
multiple? (> (count selected) 1)
editable-shape? (#{:group :text :path} (:type shape))
current-file-id (mf/use-ctx ctx/current-file-id) current-file-id (mf/use-ctx ctx/current-file-id)
do-duplicate (st/emitf dw/duplicate-selected) do-duplicate (st/emitf dw/duplicate-selected)
@ -77,6 +82,9 @@
do-add-component (st/emitf dwl/add-component) do-add-component (st/emitf dwl/add-component)
do-detach-component (st/emitf (dwl/detach-component id)) do-detach-component (st/emitf (dwl/detach-component id))
do-reset-component (st/emitf (dwl/reset-component id)) do-reset-component (st/emitf (dwl/reset-component id))
do-start-editing (fn []
;; We defer the execution so the mouse event won't close the editor
(timers/schedule #(st/emit! (dw/start-editing-selected))))
do-update-component (st/emitf do-update-component (st/emitf
(dwc/start-undo-transaction) (dwc/start-undo-transaction)
(dwl/update-component id) (dwl/update-component id)
@ -99,7 +107,7 @@
:on-accept confirm-update-remote-component})) :on-accept confirm-update-remote-component}))
do-show-component (st/emitf (dw/go-to-layout :assets)) do-show-component (st/emitf (dw/go-to-layout :assets))
do-navigate-component-file (st/emitf (dwl/nav-to-component-file do-navigate-component-file (st/emitf (dwl/nav-to-component-file
(:component-file shape)))] (:component-file shape)))]
[:* [:*
[:& menu-entry {:title (t locale "workspace.shape.menu.copy") [:& menu-entry {:title (t locale "workspace.shape.menu.copy")
:shortcut (sc/get-tooltip :copy) :shortcut (sc/get-tooltip :copy)
@ -128,7 +136,7 @@
:on-click do-send-to-back}] :on-click do-send-to-back}]
[:& menu-separator] [:& menu-separator]
(when (> (count selected) 1) (when multiple?
[:* [:*
[:& menu-entry {:title (t locale "workspace.shape.menu.group") [:& menu-entry {:title (t locale "workspace.shape.menu.group")
:shortcut (sc/get-tooltip :group) :shortcut (sc/get-tooltip :group)
@ -138,7 +146,7 @@
:on-click do-mask-group}] :on-click do-mask-group}]
[:& menu-separator]]) [:& menu-separator]])
(when (>= (count selected) 1) (when (or single? multiple?)
[:* [:*
[:& menu-entry {:title (t locale "workspace.shape.menu.flip-vertical") [:& menu-entry {:title (t locale "workspace.shape.menu.flip-vertical")
:shortcut (sc/get-tooltip :flip-vertical) :shortcut (sc/get-tooltip :flip-vertical)
@ -148,7 +156,7 @@
:on-click do-flip-horizontal}] :on-click do-flip-horizontal}]
[:& menu-separator]]) [:& menu-separator]])
(when (and (= (count selected) 1) (= (:type shape) :group)) (when (and single? (= (:type shape) :group))
[:* [:*
[:& menu-entry {:title (t locale "workspace.shape.menu.ungroup") [:& menu-entry {:title (t locale "workspace.shape.menu.ungroup")
:shortcut (sc/get-tooltip :ungroup) :shortcut (sc/get-tooltip :ungroup)
@ -161,6 +169,11 @@
:shortcut (sc/get-tooltip :group) :shortcut (sc/get-tooltip :group)
:on-click do-mask-group}])]) :on-click do-mask-group}])])
(when (and single? editable-shape?)
[:& menu-entry {:title (t locale "workspace.shape.menu.edit")
:shortcut (sc/get-tooltip :start-editing)
:on-click do-start-editing}])
(if (:hidden shape) (if (:hidden shape)
[:& menu-entry {:title (t locale "workspace.shape.menu.show") [:& menu-entry {:title (t locale "workspace.shape.menu.show")
:on-click do-show-shape}] :on-click do-show-shape}]

View file

@ -182,11 +182,9 @@
(and self (.contains self target)) (and self (.contains self target))
(and cpicker (.contains cpicker target)) (and cpicker (.contains cpicker target))
(and palette (.contains palette target))) (and palette (.contains palette target)))
(do (if selecting?
(mf/set-ref-val! selecting-ref false)
(if selecting? (on-close)))))
(mf/set-ref-val! selecting-ref false)
(on-close))))))
on-mouse-down on-mouse-down
(fn [event] (fn [event]