mirror of
https://github.com/penpot/penpot.git
synced 2025-02-11 01:28:30 -05:00
Refactor tool management as generic flags on workspace.
This commit is contained in:
parent
2a580ccf8b
commit
0abc29451a
6 changed files with 18 additions and 12 deletions
|
@ -44,12 +44,14 @@
|
|||
|
||||
(defn toggle-tool
|
||||
"Toggle the enabled flag of the specified tool."
|
||||
[toolname]
|
||||
[key]
|
||||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [key (keyword (str (name toolname) "-enabled"))]
|
||||
(update-in state [:workspace key] (fnil not false))))))
|
||||
(let [flags (get-in state [:workspace :flags])]
|
||||
(if (contains? flags key)
|
||||
(assoc-in state [:workspace :flags] (disj flags key))
|
||||
(assoc-in state [:workspace :flags] (conj flags key)))))))
|
||||
|
||||
(defn toggle-toolbox
|
||||
"Toggle the visibility flag of the specified toolbox."
|
||||
|
@ -174,6 +176,7 @@
|
|||
(-apply-update [_ state]
|
||||
(let [s {:project projectid
|
||||
:toolboxes #{}
|
||||
:flags #{}
|
||||
:drawing nil
|
||||
:selected #{}
|
||||
:page pageid}]
|
||||
|
|
|
@ -36,6 +36,10 @@
|
|||
(as-> (l/in [:workspace :toolboxes]) $
|
||||
(l/focus-atom $ st/state)))
|
||||
|
||||
(def ^:static flags-state
|
||||
(as-> (l/in [:workspace :flags]) $
|
||||
(l/focus-atom $ st/state)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Scroll Stream
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
|
@ -56,9 +56,9 @@
|
|||
(let [padding (* 0 zoom)
|
||||
ticks-mod (/ 100 zoom)
|
||||
step-size (/ 10 zoom)
|
||||
workspace (rum/react wb/workspace-state)
|
||||
flags (rum/react wb/flags-state)
|
||||
page (rum/react wb/page-state)
|
||||
enabled? (:grid-enabled workspace false)
|
||||
enabled? (contains? flags :workspace/grid)
|
||||
vertical-ticks (range (- 0 wb/document-start-y)
|
||||
(- (:width page) wb/document-start-y)
|
||||
step-size)
|
||||
|
|
|
@ -24,14 +24,14 @@
|
|||
(defn header-render
|
||||
[own]
|
||||
(let [page (rum/react wb/page-state)
|
||||
workspace (rum/react wb/workspace-state)
|
||||
flags (rum/react wb/flags-state)
|
||||
toggle #(rs/emit! (dw/toggle-tool %))]
|
||||
(html
|
||||
[:header#workspace-bar.workspace-bar
|
||||
[:div.main-icon
|
||||
(nav/link (r/route-for :dashboard/projects) i/logo-icon)]
|
||||
[:div.project-tree-btn
|
||||
{:on-click (partial toggle :pagesbar)}
|
||||
{:on-click (partial toggle :workspace/pagesmngr)}
|
||||
i/project-tree
|
||||
[:span (:name page)]]
|
||||
[:div.workspace-options
|
||||
|
@ -57,8 +57,8 @@
|
|||
i/ruler]
|
||||
[:li.tooltip.tooltip-bottom
|
||||
{:alt "Grid (Ctrl + G)"
|
||||
:class (when (:grid-enabled workspace) "selected")
|
||||
:on-click (partial toggle :grid)}
|
||||
:class (when (contains? flags :workspace/grid) "selected")
|
||||
:on-click (partial toggle :workspace/grid)}
|
||||
i/grid]
|
||||
[:li.tooltip.tooltip-bottom
|
||||
{:alt "Align (Ctrl + A)"}
|
||||
|
|
|
@ -116,11 +116,11 @@
|
|||
(defn pagesmngr-render
|
||||
[own]
|
||||
(let [local (:rum/local own)
|
||||
workspace (rum/react wb/workspace-state)
|
||||
flags (rum/react wb/flags-state)
|
||||
project (rum/react wb/project-state)]
|
||||
(html
|
||||
[:div#project-bar.project-bar
|
||||
(when-not (:pagesbar-enabled workspace false)
|
||||
(when-not (contains? flags :workspace/pagesmngr)
|
||||
{:class "toggle"})
|
||||
(if (:edit @local)
|
||||
(page-form local)
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
[uxbox.ui.workspace.base :as wb]
|
||||
[uxbox.ui.workspace.toolboxes :as toolboxes]))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Aside
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
Loading…
Add table
Reference in a new issue