From 477188f2766c493f844b730e4d58605e34a61b57 Mon Sep 17 00:00:00 2001 From: Juan Monetta Date: Fri, 26 Jan 2024 18:59:13 -0300 Subject: [PATCH] Centralize bookmarks system --- CHANGELOG.md | 1 + src-dbg/flow_storm/debugger/state.clj | 37 +++++++++--- .../debugger/ui/flows/bookmarks.clj | 56 ++++++++++--------- src-dbg/flow_storm/debugger/ui/flows/code.clj | 8 +-- .../flow_storm/debugger/ui/flows/screen.clj | 6 +- src-dbg/flow_storm/debugger/ui/main.clj | 6 ++ 6 files changed, 71 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a43b0426..2a6f1630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Add thread-ids everywhere thread-names show - Show form line next to form namespace if known - New stepper buttong layout + - Centralize bookmarks system (one bookmark system for all flows and threads) ### Bugs fixed diff --git a/src-dbg/flow_storm/debugger/state.clj b/src-dbg/flow_storm/debugger/state.clj index 0bed4eff..573c261d 100644 --- a/src-dbg/flow_storm/debugger/state.clj +++ b/src-dbg/flow_storm/debugger/state.clj @@ -47,7 +47,6 @@ (s/def :thread.ui.callstack-tree-hidden-fns/ref (s/keys :req-un [:flow-storm/fn-name :flow-storm/fn-ns])) (s/def :thread.ui/callstack-tree-hidden-fns (s/coll-of :thread.ui.callstack-tree-hidden-fns/ref)) -(s/def :thread/bookmarks (s/map-of int? string?)) (s/def :navigation-history/history (s/coll-of :flow-storm/timeline-entry)) (s/def :thread/navigation-history (s/keys :req-un [:navigation-history/head-pos @@ -57,8 +56,7 @@ :thread/curr-timeline-entry :thread/navigation-history] :opt [:thread/curr-frame - :thread.ui/callstack-tree-hidden-fns - :thread/bookmarks])) + :thread.ui/callstack-tree-hidden-fns])) (s/def :flow/threads (s/map-of :thread/id :flow/thread)) (s/def :flow/id (s/nilable int?)) @@ -145,6 +143,9 @@ :config/runtime-host :config/debug-mode?])) +(s/def :bookmark/id (s/tuple :flow/id :thread/id int?)) +(s/def ::bookmarks (s/map-of :bookmark/id string?)) + (s/def ::state (s/keys :req-un [:flow/flows :flow/threads-info :printer/printers @@ -156,7 +157,8 @@ ::connection-status ::local-mode? ::runtime-config - ::debugger-config] + ::debugger-config + ::bookmarks] :opt-un [:ui/selected-flow-id])) (defn initial-state [{:keys [theme styles local? port repl-type debugger-host ws-port runtime-host] :as config}] @@ -430,13 +432,30 @@ ;;;;;;;;;;;;;;; (defn add-bookmark [flow-id thread-id idx text] - (swap! state assoc-in [:flows flow-id :flow/threads thread-id :thread/bookmarks idx] text)) + (swap! state assoc-in [:bookmarks [flow-id thread-id idx]] text)) (defn remove-bookmark [flow-id thread-id idx] - (swap! state update-in [:flows flow-id :flow/threads thread-id :thread/bookmarks] dissoc idx)) - -(defn all-bookmarks [flow-id thread-id] - (get-in @state [:flows flow-id :flow/threads thread-id :thread/bookmarks])) + (swap! state update-in [:bookmarks] dissoc [flow-id thread-id idx])) + +(defn remove-bookmarks [flow-id] + (swap! state update-in [:bookmarks] + (fn [bookmarks] + (reduce-kv (fn [bks [fid :as bkey] btext] + (if (= fid flow-id) + bks + (assoc bks bkey btext))) + {} + bookmarks)))) + +(defn all-bookmarks [] + (reduce-kv (fn [bks [flow-id thread-id idx] text] + (conj bks + {:flow-id flow-id + :thread-id thread-id + :idx idx + :text text})) + [] + (get-in @state [:bookmarks]))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Pending tasks sub-system ;; diff --git a/src-dbg/flow_storm/debugger/ui/flows/bookmarks.clj b/src-dbg/flow_storm/debugger/ui/flows/bookmarks.clj index 46d38242..533c2f2b 100644 --- a/src-dbg/flow_storm/debugger/ui/flows/bookmarks.clj +++ b/src-dbg/flow_storm/debugger/ui/flows/bookmarks.clj @@ -2,72 +2,74 @@ (:require [flow-storm.debugger.state :as dbg-state :refer [store-obj obj-lookup]] [flow-storm.debugger.ui.utils :as ui-utils - :refer [icon-button table-view label v-box]] + :refer [icon-button table-view label]] [clojure.string :as str] [flow-storm.utils :refer [log-error]]) (:import [javafx.scene Scene] [javafx.stage Stage] [javafx.scene.input MouseButton])) -(defn update-bookmarks [flow-id thread-id] - (when-let [[{:keys [clear add-all]}] (obj-lookup flow-id thread-id "bookmarks_table_data")] - (let [bookmarks (dbg-state/all-bookmarks flow-id thread-id)] +(defn update-bookmarks [] + (when-let [[{:keys [clear add-all]}] (obj-lookup "bookmarks_table_data")] + (let [bookmarks (dbg-state/all-bookmarks)] (clear) - (add-all (mapv (fn [[b-idx b-text]] - [{:idx b-idx, :cell-type :text, :text (str b-idx)} - {:idx b-idx, :cell-type :text, :text b-text } - {:idx b-idx, :cell-type :actions }]) + (add-all (mapv (fn [b] + [(assoc b :cell-type :text, :text (str (:flow-id b))) + (assoc b :cell-type :text, :text (str (:thread-id b))) + (assoc b :cell-type :text, :text (str (:idx b))) + (assoc b :cell-type :text) + (assoc b :cell-type :actions)]) bookmarks))))) (defn bookmark-add [flow-id thread-id idx] (let [text (ui-utils/ask-text-dialog {:header "Add bookmark" :body "Bookmark name:"})] (dbg-state/add-bookmark flow-id thread-id idx text) - (update-bookmarks flow-id thread-id))) + (update-bookmarks))) -(defn- create-bookmarks-pane [flow-id thread-id] - (let [cell-factory (fn [_ {:keys [cell-type idx text]}] +(defn remove-bookmarks [flow-id] + (dbg-state/remove-bookmarks flow-id) + (update-bookmarks)) + +(defn- create-bookmarks-pane [] + (let [cell-factory (fn [_ {:keys [cell-type idx text flow-id thread-id]}] (case cell-type :text (label text) :actions (icon-button :icon-name "mdi-delete-forever" :on-click (fn [] (dbg-state/remove-bookmark flow-id thread-id idx) - (update-bookmarks flow-id thread-id))))) + (update-bookmarks))))) {:keys [table-view-pane] :as tv-data} (table-view - {:columns ["Idx" "Bookmarks" ""] - :columns-width-percs [0.1 0.8 0.1] + {:columns ["FlowId" "ThreadId" "Idx" "Bookmarks" ""] + :columns-width-percs [0.1 0.1 0.1 0.6 0.1] :cell-factory-fn cell-factory :resize-policy :constrained :on-click (fn [mev sel-items _] (when (and (= MouseButton/PRIMARY (.getButton mev)) (= 2 (.getClickCount mev))) - (let [idx (-> sel-items first first :idx) + (let [{:keys [flow-id thread-id idx]} (ffirst sel-items) goto-loc (requiring-resolve 'flow-storm.debugger.ui.flows.screen/goto-location)] (goto-loc {:flow-id flow-id :thread-id thread-id :idx idx})))) :selection-mode :multiple - :search-predicate (fn [[_ bookmark-text] search-str] - (str/includes? bookmark-text search-str))}) - th-info (dbg-state/get-thread-info thread-id)] - (store-obj flow-id thread-id "bookmarks_table_data" tv-data) - (doto (v-box [(label (format "Bookmarks for thread: %s" (ui-utils/thread-label (:thread/id th-info) - (:thread/name th-info)))) - table-view-pane]) - (.setSpacing 10)))) + :search-predicate (fn [[_ _ _ bookmark-text] search-str] + (str/includes? bookmark-text search-str))})] + (store-obj "bookmarks_table_data" tv-data) + table-view-pane)) -(defn show-bookmarks [flow-id thread-id] +(defn show-bookmarks [] (try - (let [scene (Scene. (create-bookmarks-pane flow-id thread-id) 800 400) + (let [scene (Scene. (create-bookmarks-pane) 800 400) stage (doto (Stage.) - (.setTitle (str "FlowStorm bookmarks for thread - " thread-id)) + (.setTitle "FlowStorm bookmarks ") (.setScene scene))] (dbg-state/register-and-init-stage! stage) (-> stage .show)) - (update-bookmarks flow-id thread-id) + (update-bookmarks) (catch Exception e (log-error "UI Thread exception" e)))) diff --git a/src-dbg/flow_storm/debugger/ui/flows/code.clj b/src-dbg/flow_storm/debugger/ui/flows/code.clj index a4c8bf94..c34a99f1 100644 --- a/src-dbg/flow_storm/debugger/ui/flows/code.clj +++ b/src-dbg/flow_storm/debugger/ui/flows/code.clj @@ -576,11 +576,7 @@ (.setSpacing 2.0)))) (defn- create-bookmarks-and-nav-pane [flow-id thread-id] - (let [open-book-btn (ui-utils/icon-button :icon-name "mdi-book" - :on-click (fn [] - (bookmarks/show-bookmarks flow-id thread-id)) - :tooltip "Open bookmarks") - bookmark-btn (ui-utils/icon-button :icon-name "mdi-bookmark" + (let [bookmark-btn (ui-utils/icon-button :icon-name "mdi-bookmark" :on-click (fn [] (bookmarks/bookmark-add flow-id @@ -604,7 +600,7 @@ :ns (:ns execution-expr)}))) :disable (not execution-expression?))] (doto (h-box [undo-nav-btn redo-nav-btn - bookmark-btn open-book-btn + bookmark-btn re-run-flow-btn]) (.setSpacing 2.0)))) diff --git a/src-dbg/flow_storm/debugger/ui/flows/screen.clj b/src-dbg/flow_storm/debugger/ui/flows/screen.clj index ce65a2d1..49ccafe3 100644 --- a/src-dbg/flow_storm/debugger/ui/flows/screen.clj +++ b/src-dbg/flow_storm/debugger/ui/flows/screen.clj @@ -3,6 +3,7 @@ [flow-storm.debugger.ui.flows.general :as ui-general] [flow-storm.debugger.ui.flows.call-tree :as flow-tree] [flow-storm.debugger.ui.flows.functions :as flow-fns] + [flow-storm.debugger.ui.flows.bookmarks :as bookmarks] [flow-storm.debugger.runtime-api :as runtime-api :refer [rt-api]] [flow-storm.debugger.ui.utils :as ui-utils :refer [event-handler label icon tab-pane tab list-view icon-button h-box v-box key-combo-match?]] @@ -36,7 +37,10 @@ (runtime-api/discard-flow rt-api flow-id) ;; remove it from the ui - (remove-flow flow-id)) + (remove-flow flow-id) + + ;; remove all bookmarks associated to this flow + (bookmarks/remove-bookmarks flow-id)) (defn update-threads-list [flow-id] (let [[{:keys [add-all clear] :as lv-data}] (obj-lookup flow-id "flow_threads_list")] diff --git a/src-dbg/flow_storm/debugger/ui/main.clj b/src-dbg/flow_storm/debugger/ui/main.clj index ff9a3f0f..cd0ac43a 100644 --- a/src-dbg/flow_storm/debugger/ui/main.clj +++ b/src-dbg/flow_storm/debugger/ui/main.clj @@ -29,6 +29,7 @@ [flow-storm.debugger.ui.docs.screen :as docs-screen] [flow-storm.debugger.ui.timeline.screen :as timeline-screen] [flow-storm.debugger.ui.printer.screen :as printer-screen] + [flow-storm.debugger.ui.flows.bookmarks :as bookmarks] [flow-storm.debugger.runtime-api :as runtime-api :refer [rt-api]] [flow-storm.debugger.state :as dbg-state :refer [obj-lookup store-obj]] [flow-storm.utils :as utils :refer [log log-error]] @@ -184,6 +185,10 @@ unblock-threads-btn (icon-button :icon-name "mdi-run" :tooltip "Unblock all blocked threads if any (Ctrl-u)" :on-click (fn [] (runtime-api/unblock-all-threads rt-api))) + open-book-btn (ui-utils/icon-button :icon-name "mdi-book" + :on-click (fn [] + (bookmarks/show-bookmarks)) + :tooltip "Open bookmarks") quick-jump-textfield (doto (h-box [(label "Quick jump:") (ui-utils/autocomplete-textfield (fn [] @@ -199,6 +204,7 @@ task-cancel-btn record-btn unblock-threads-btn + open-book-btn quick-jump-textfield]] (store-obj "task-cancel-btn" task-cancel-btn)