From d24f16563fb99b515ba2d9f5101706e12af00913 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 21 Feb 2022 17:24:45 +0100 Subject: [PATCH] :sparkles: Use remove to delete guides --- frontend/src/app/main/data/workspace.cljs | 16 ++++++++--- .../src/app/main/data/workspace/guides.cljs | 27 +++++++++++++++++++ .../app/main/data/workspace/shortcuts.cljs | 5 ++-- .../app/main/ui/workspace/context_menu.cljs | 5 ++-- .../main/ui/workspace/viewport/guides.cljs | 4 ++- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index ad4339d28..ebbb1c692 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -747,14 +747,21 @@ ;; --- Delete Selected -(def delete-selected +(defn delete-selected "Deselect all and remove all selected shapes." + [] (ptk/reify ::delete-selected ptk/WatchEvent (watch [_ state _] - (let [selected (wsh/lookup-selected state)] - (rx/of (dwc/delete-shapes selected) - (dws/deselect-all)))))) + (let [selected (wsh/lookup-selected state) + hover-guides (get-in state [:workspace-guides :hover])] + (cond + (d/not-empty? selected) + (rx/of (dwc/delete-shapes selected) + (dws/deselect-all)) + + (d/not-empty? hover-guides) + (rx/of (dwgu/remove-guides hover-guides))))))) ;; --- Shape Vertical Ordering @@ -2068,4 +2075,5 @@ ;; Guides (d/export dwgu/update-guides) (d/export dwgu/remove-guide) +(d/export dwgu/set-hover-guide) diff --git a/frontend/src/app/main/data/workspace/guides.cljs b/frontend/src/app/main/data/workspace/guides.cljs index 473d03df0..3fce84bf2 100644 --- a/frontend/src/app/main/data/workspace/guides.cljs +++ b/frontend/src/app/main/data/workspace/guides.cljs @@ -41,6 +41,12 @@ (defn remove-guide [guide] (us/verify ::csp/guide guide) (ptk/reify ::remove-guide + ptk/UpdateEvent + (update [_ state] + (let [sdisj (fnil disj #{})] + (-> state + (update-in [:workspace-guides :hover] sdisj (:id guide))))) + ptk/WatchEvent (watch [it state _] (let [page (wsh/lookup-page state) @@ -53,6 +59,16 @@ (pcb/set-page-option :guides new-guides))] (rx/of (dwc/commit-changes changes)))))) +(defn remove-guides + [ids] + (ptk/reify ::remove-guides + ptk/WatchEvent + (watch [_ state _] + (let [page (wsh/lookup-page state) + guides (get-in page [:options :guides] {}) + guides (-> (select-keys guides ids) (vals))] + (rx/from (->> guides (mapv #(remove-guide %)))))))) + (defn move-frame-guides "Move guides that are inside a frame when that frame is moved" [ids] @@ -86,3 +102,14 @@ (filter (comp frame-ids? :frame-id)) (map build-move-event) (rx/from)))))) + +(defn set-hover-guide + [id hover?] + (ptk/reify ::set-hover-guide + ptk/UpdateEvent + (update [_ state] + (let [sconj (fnil conj #{}) + sdisj (fnil disj #{})] + (if hover? + (update-in state [:workspace-guides :hover] sconj id) + (update-in state [:workspace-guides :hover] sdisj id)))))) diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index ec42b727a..64fcba629 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -190,7 +190,8 @@ :cut {:tooltip (ds/meta "X") :command (ds/c-mod "x") - :fn #(st/emit! (dw/copy-selected) dw/delete-selected)} + :fn #(st/emit! (dw/copy-selected) + (dw/delete-selected))} :paste {:tooltip (ds/meta "V") :disabled true @@ -199,7 +200,7 @@ :delete {:tooltip (ds/supr) :command ["del" "backspace"] - :fn #(st/emit! dw/delete-selected)} + :fn #(st/emit! (dw/delete-selected))} :bring-forward {:tooltip (ds/meta ds/up-arrow) :command (ds/c-mod "up") diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index 5f07b7dc9..f020dc1e4 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -103,7 +103,8 @@ (mf/defc context-menu-edit [] (let [do-copy (st/emitf (dw/copy-selected)) - do-cut (st/emitf (dw/copy-selected) dw/delete-selected) + do-cut (st/emitf (dw/copy-selected) + (dw/delete-selected)) do-paste (st/emitf dw/paste) do-duplicate (st/emitf (dw/duplicate-selected false))] [:* @@ -406,7 +407,7 @@ (mf/defc context-menu-delete [] - (let [do-delete (st/emitf dw/delete-selected)] + (let [do-delete (st/emitf (dw/delete-selected))] [:& menu-entry {:title (tr "workspace.shape.menu.delete") :shortcut (sc/get-tooltip :delete) :on-click do-delete}])) diff --git a/frontend/src/app/main/ui/workspace/viewport/guides.cljs b/frontend/src/app/main/ui/workspace/viewport/guides.cljs index 2a179628c..6aebf468a 100644 --- a/frontend/src/app/main/ui/workspace/viewport/guides.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/guides.cljs @@ -36,7 +36,7 @@ (defn use-guide "Hooks to support drag/drop for existing guides and new guides" - [on-guide-change get-hover-frame zoom {:keys [position axis frame-id]}] + [on-guide-change get-hover-frame zoom {:keys [id position axis frame-id]}] (let [dragging-ref (mf/use-ref false) start-ref (mf/use-ref nil) start-pos-ref (mf/use-ref nil) @@ -52,11 +52,13 @@ on-pointer-enter (mf/use-callback (fn [] + (st/emit! (dw/set-hover-guide id true)) (swap! state assoc :hover true))) on-pointer-leave (mf/use-callback (fn [] + (st/emit! (dw/set-hover-guide id false)) (swap! state assoc :hover false))) on-pointer-down