diff --git a/frontend/src/app/main/data/workspace/path/state.cljs b/frontend/src/app/main/data/workspace/path/state.cljs index 6b54b74d2..00d626435 100644 --- a/frontend/src/app/main/data/workspace/path/state.cljs +++ b/frontend/src/app/main/data/workspace/path/state.cljs @@ -6,8 +6,39 @@ (ns app.main.data.workspace.path.state (:require + [app.common.data.macros :as dm] + [app.common.files.helpers :as cph] [app.common.svg.path.shapes-to-path :as upsp])) +(defn path-editing? + "Returns true if we're editing a path or creating a new one." + [state] + (let [workspace-local (dm/get-in state [:workspace-local]) + drawing (dm/get-in state [:workspace-drawing]) + {:keys [selected edition]} workspace-local + edit-path? (dm/get-in workspace-local [:edit-path edition]) + + drawing-obj (:object drawing) + + shape (or drawing-obj (-> selected first)) + shape-id (:id shape) + + single? (= (count selected) 1) + editing? (and (some? shape-id) (some? edition) (= shape-id edition)) + + ;; we need to check if we're drawing a new object + ;; but we're not using the pencil tool. + draw-path? (and (some? drawing-obj) + (cph/path-shape? drawing-obj) + (not= :curve (:tool drawing))) + + path-edition? (or (and single? editing? + (and (not (cph/text-shape? shape)) + (not (cph/frame-shape? shape)))) + draw-path? + edit-path?)] + path-edition?)) + (defn get-path-id "Retrieves the currently editing path id" [state] diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 617d628b3..81b83efe2 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -196,46 +196,6 @@ (def context-menu (l/derived :context-menu workspace-local)) -(defn path-editing? - "Returns true if we're editing a path or creating a new one." - [state] - (let [selected (dm/get-in state [:workspace-local :selected]) - edition (dm/get-in state [:workspace-local :edition]) - - edit-path? (dm/get-in state [:workspace-local :edit-path edition]) - - drawing (dm/get-in state [:workspace-drawing]) - drawing-obj (:object drawing) - - shape (or drawing-obj (-> selected first)) - shape-id (:id shape) - - single? (= (count selected) 1) - editing? (and (some? shape-id) (some? edition) (= shape-id edition)) - - ;; we need to check if we're drawing a new object - ;; but we're not using the pencil tool. - draw-path? (and (some? drawing-obj) - (cph/path-shape? drawing-obj) - (not= :curve (:tool drawing))) - - path-edition? (or (and single? editing? - (and (not (cph/text-shape? shape)) - (not (cph/frame-shape? shape)))) - draw-path? - edit-path?)] - - path-edition?)) - -(def toolbar-hidden - (l/derived - (fn [state] - (let [visibility (dm/get-in state [:workspace-local :hide-toolbar]) - editing? (path-editing? state) - hidden? (if editing? true visibility)] - hidden?)) - st/state)) - ;; page item that it is being edited (def editing-page-item (l/derived :page-item workspace-local)) diff --git a/frontend/src/app/main/ui/workspace/top_toolbar.cljs b/frontend/src/app/main/ui/workspace/top_toolbar.cljs index 26d056fe4..e0160222d 100644 --- a/frontend/src/app/main/ui/workspace/top_toolbar.cljs +++ b/frontend/src/app/main/ui/workspace/top_toolbar.cljs @@ -7,12 +7,14 @@ (ns app.main.ui.workspace.top-toolbar (:require-macros [app.main.style :as stl]) (:require + [app.common.data.macros :as dm] [app.common.geom.point :as gpt] [app.common.media :as cm] [app.main.data.events :as ev] [app.main.data.workspace :as dw] [app.main.data.workspace.common :as dwc] [app.main.data.workspace.media :as dwm] + [app.main.data.workspace.path.state :as pst] [app.main.data.workspace.shortcuts :as sc] [app.main.refs :as refs] [app.main.store :as st] @@ -22,6 +24,7 @@ [app.util.dom :as dom] [app.util.i18n :as i18n :refer [tr]] [app.util.timers :as ts] + [okulary.core :as l] [rumext.v2 :as mf])) (mf/defc image-upload @@ -63,6 +66,15 @@ :ref ref :on-selected on-selected}]]])) +(def toolbar-hidden + (l/derived + (fn [state] + (let [visibility (dm/get-in state [:workspace-local :hide-toolbar]) + editing? (pst/path-editing? state) + hidden? (if editing? true visibility)] + hidden?)) + st/state)) + (mf/defc top-toolbar {::mf/wrap [mf/memo] ::mf/wrap-props false} @@ -73,7 +85,7 @@ read-only? (mf/use-ctx ctx/workspace-read-only?) rulers? (mf/deref refs/rulers?) - hide-toolbar? (mf/deref refs/toolbar-hidden) + hide-toolbar? (mf/deref toolbar-hidden) interrupt (mf/use-fn #(st/emit! :interrupt))