diff --git a/src/uxbox/ui/core.cljs b/src/uxbox/ui/core.cljs index eb8897570..2b8526697 100644 --- a/src/uxbox/ui/core.cljs +++ b/src/uxbox/ui/core.cljs @@ -5,9 +5,17 @@ ;; Actions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defonce actions-lock (atom :nothing)) (defonce actions-s (rx/bus)) -(defn emit-action! +(defn acquire-action! [type] - (rx/push! actions-s type)) + (when-let [result (compare-and-set! actions-lock :nothing type)] + ;; (println "acquire-action!" type) + (rx/push! actions-s type))) +(defn release-action! + [type] + (when-let [result (compare-and-set! actions-lock type :nothing)] + ;; (println "release-action!" type) + (rx/push! actions-s :nothing))) diff --git a/src/uxbox/ui/shapes/icon.cljs b/src/uxbox/ui/shapes/icon.cljs index 5f74d9b1c..f6978815e 100644 --- a/src/uxbox/ui/shapes/icon.cljs +++ b/src/uxbox/ui/shapes/icon.cljs @@ -38,7 +38,7 @@ (and (not selected?) (empty? selected)) (do (dom/stop-propagation event) - (uuc/emit-action! :shape/movement) + (uuc/acquire-action! :shape/movement) (rs/emit! (dw/select-shape id))) (and (not selected?) (not (empty? selected))) @@ -52,7 +52,7 @@ :else (do (dom/stop-propagation event) - (uuc/emit-action! :shape/movement)))))) + (uuc/acquire-action! :shape/movement)))))) (defn on-mouse-up [event {:keys [id group] :as shape}] @@ -63,7 +63,7 @@ :else (do (dom/stop-propagation event) - (uuc/emit-action! :nothing)))) + (uuc/release-action! :shape/movement)))) (declare handlers) diff --git a/src/uxbox/ui/shapes/text.cljs b/src/uxbox/ui/shapes/text.cljs index fd1d53eb9..b0b41e214 100644 --- a/src/uxbox/ui/shapes/text.cljs +++ b/src/uxbox/ui/shapes/text.cljs @@ -31,7 +31,7 @@ (and (not selected?) (empty? selected)) (do (dom/stop-propagation event) - (uuc/emit-action! :shape/movement) + (uuc/acquire-action! :shape/movement) (rs/emit! (dw/select-shape id))) (and (not selected?) (not (empty? selected))) @@ -45,7 +45,7 @@ :else (do (dom/stop-propagation event) - (uuc/emit-action! :shape/movement)))))) + (uuc/acquire-action! :shape/movement)))))) (defn on-mouse-up [event {:keys [id group] :as shape}] @@ -56,7 +56,7 @@ :else (do (dom/stop-propagation event) - (uuc/emit-action! :nothing)))) + (uuc/release-action! :shape/movement)))) (defn- text-component-did-mount [own] @@ -64,12 +64,14 @@ (let [container (mx/get-ref-dom own "container") local (:rum/local own)] (swap! local assoc :edition true) + (uuc/acquire-action! ::edition) (set! (.-contentEditable container) true) (.setAttribute container "contenteditable" "true") (.focus container))) (on-blur [ev] (let [container (mx/get-ref-dom own "container") local (:rum/local own)] + (uuc/release-action! ::edition) (swap! local assoc :edition false) (set! (.-contentEditable container) false) (.removeAttribute container "contenteditable")))] diff --git a/src/uxbox/ui/workspace/canvas.cljs b/src/uxbox/ui/workspace/canvas.cljs index eaea85f34..f44e3e7fb 100644 --- a/src/uxbox/ui/workspace/canvas.cljs +++ b/src/uxbox/ui/workspace/canvas.cljs @@ -84,11 +84,12 @@ (when-not (empty? (:selected workspace)) (rs/emit! (dw/deselect-all))) (if-let [shape (:drawing workspace)] - (uuc/emit-action! :draw/shape) - (uuc/emit-action! :draw/selrect))) + (uuc/acquire-action! :draw/shape) + (uuc/acquire-action! :draw/selrect))) (on-mouse-up [event] (dom/stop-propagation event) - (uuc/emit-action! :nothing))] + (uuc/release-action! :draw/shape) + (uuc/release-action! :draw/selrect))] (html [:svg.viewport {:width uuwb/viewport-width :height uuwb/viewport-height @@ -124,11 +125,11 @@ (on-key-down [event] (when (kbd/space? event) - (uuc/emit-action! :scroll/viewport))) + (uuc/acquire-action! :scroll/viewport))) (on-key-up [event] (when (kbd/space? event) - (uuc/emit-action! :nothing))) + (uuc/release-action! :scroll/viewport))) (on-mousemove [event] (let [wpt (gpt/point (.-clientX event)