This commit is contained in:
Florian Schroedl 2024-11-27 10:22:23 +01:00
parent 8772cdf423
commit ffe2abc992
4 changed files with 14 additions and 14 deletions

View file

@ -820,13 +820,13 @@
(apply-changes-local))) (apply-changes-local)))
(defn delete-token-set-path (defn delete-token-set-path
[changes token-set-path] [changes prefixed-full-set-path]
(assert-library! changes) (assert-library! changes)
(let [library-data (::library-data (meta changes)) (let [library-data (::library-data (meta changes))
prev-token-sets (some-> (get library-data :tokens-lib) prev-token-sets (some-> (get library-data :tokens-lib)
(ctob/get-path-sets token-set-path))] (ctob/get-sets-at-prefix-path prefixed-full-set-path))]
(-> changes (-> changes
(update :redo-changes conj {:type :del-token-set-path :path token-set-path}) (update :redo-changes conj {:type :del-token-set-path :path prefixed-full-set-path})
(update :undo-changes conj {:type :add-token-sets :token-sets prev-token-sets}) (update :undo-changes conj {:type :add-token-sets :token-sets prev-token-sets})
(apply-changes-local)))) (apply-changes-local))))

View file

@ -387,7 +387,7 @@ When `before-set-name` is nil, move set to bottom")
(get-set-tree [_] "get a nested tree of all sets in the library") (get-set-tree [_] "get a nested tree of all sets in the library")
(get-in-set-tree [_ path] "get `path` in nested tree of all sets in the library") (get-in-set-tree [_ path] "get `path` in nested tree of all sets in the library")
(get-sets [_] "get an ordered sequence of all sets in the library") (get-sets [_] "get an ordered sequence of all sets in the library")
(get-path-sets [_ path] "get an ordered sequence of sets at `path` in the library") (get-sets-at-prefix-path [_ path] "get an ordered sequence of sets at `path` in the library")
(get-ordered-set-names [_] "get an ordered sequence of all sets names in the library") (get-ordered-set-names [_] "get an ordered sequence of all sets names in the library")
(get-set [_ set-name] "get one set looking for name") (get-set [_ set-name] "get one set looking for name")
(get-neighbor-set-name [_ set-name index-offset] "get neighboring set name offset by `index-offset`")) (get-neighbor-set-name [_ set-name index-offset] "get neighboring set name offset by `index-offset`"))
@ -644,18 +644,18 @@ When `before-set-name` is nil, move set to bottom")
this token-sets)) this token-sets))
(update-set [this set-name f] (update-set [this set-name f]
(let [path (set-full-name->prefixed-full-path set-name) (let [prefixed-full-path (set-full-name->prefixed-full-path set-name)
set (get-in sets path)] set (get-in sets prefixed-full-path)]
(if set (if set
(let [set' (-> (make-token-set (f set)) (let [set' (-> (make-token-set (f set))
(assoc :modified-at (dt/now))) (assoc :modified-at (dt/now)))
path' (get-token-set-prefixed-path set') prefixed-full-path' (get-token-set-prefixed-path set')
name-changed? (not= (:name set) (:name set'))] name-changed? (not= (:name set) (:name set'))]
(check-token-set! set') (check-token-set! set')
(if name-changed? (if name-changed?
(TokensLib. (-> sets (TokensLib. (-> sets
(d/oassoc-in-before path path' set') (d/oassoc-in-before prefixed-full-path prefixed-full-path' set')
(d/dissoc-in path)) (d/dissoc-in prefixed-full-path))
(walk/postwalk (walk/postwalk
(fn [form] (fn [form]
(if (instance? TokenTheme form) (if (instance? TokenTheme form)
@ -663,7 +663,7 @@ When `before-set-name` is nil, move set to bottom")
form)) form))
themes) themes)
active-themes) active-themes)
(TokensLib. (d/oassoc-in sets path set') (TokensLib. (d/oassoc-in sets prefixed-full-path set')
themes themes
active-themes))) active-themes)))
this))) this)))
@ -710,7 +710,7 @@ When `before-set-name` is nil, move set to bottom")
(->> (tree-seq d/ordered-map? vals sets) (->> (tree-seq d/ordered-map? vals sets)
(filter (partial instance? TokenSet)))) (filter (partial instance? TokenSet))))
(get-path-sets [_ path] (get-sets-at-prefix-path [_ path]
(some->> (get-in sets (split-token-set-path path)) (some->> (get-in sets (split-token-set-path path))
(tree-seq d/ordered-map? vals) (tree-seq d/ordered-map? vals)
(filter (partial instance? TokenSet)))) (filter (partial instance? TokenSet))))

View file

@ -219,14 +219,14 @@
update-token-set-change update-token-set-change
(wtu/update-workspace-tokens)))))) (wtu/update-workspace-tokens))))))
(defn delete-token-set-path [token-set-path] (defn delete-token-set-path [prefixed-full-set-path]
(ptk/reify ::delete-token-set-path (ptk/reify ::delete-token-set-path
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [data (get state :workspace-data) (let [data (get state :workspace-data)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-library-data data) (pcb/with-library-data data)
(pcb/delete-token-set-path token-set-path))] (pcb/delete-token-set-path prefixed-full-set-path))]
(rx/of (rx/of
(dch/commit-changes changes) (dch/commit-changes changes)
(wtu/update-workspace-tokens)))))) (wtu/update-workspace-tokens))))))

View file

@ -38,7 +38,7 @@
[{:keys [tree-path]}] [{:keys [tree-path]}]
(let [{:keys [on-edit]} (sets-context/use-context) (let [{:keys [on-edit]} (sets-context/use-context)
edit-name (mf/use-fn #(on-edit tree-path)) edit-name (mf/use-fn #(on-edit tree-path))
delete-set (mf/use-fn #(st/emit! (wdt/delete-token-set-path tree-path)))] delete-set (mf/use-fn #(st/emit! (wdt/delete-token-set-prefix-full-path tree-path)))]
[:ul {:class (stl/css :context-list)} [:ul {:class (stl/css :context-list)}
[:& menu-entry {:title (tr "labels.rename") :on-click edit-name}] [:& menu-entry {:title (tr "labels.rename") :on-click edit-name}]
[:& menu-entry {:title (tr "labels.delete") :on-click delete-set}]])) [:& menu-entry {:title (tr "labels.delete") :on-click delete-set}]]))