Skip to content

Commit

Permalink
Centralize bookmarks system
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmonettas committed Jan 26, 2024
1 parent 2075c6b commit 477188f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 28 additions & 9 deletions src-dbg/flow_storm/debugger/state.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?))
Expand Down Expand Up @@ -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
Expand All @@ -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}]
Expand Down Expand Up @@ -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 ;;
Expand Down
56 changes: 29 additions & 27 deletions src-dbg/flow_storm/debugger/ui/flows/bookmarks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
8 changes: 2 additions & 6 deletions src-dbg/flow_storm/debugger/ui/flows/code.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))))

Expand Down
6 changes: 5 additions & 1 deletion src-dbg/flow_storm/debugger/ui/flows/screen.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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?]]
Expand Down Expand Up @@ -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")]
Expand Down
6 changes: 6 additions & 0 deletions src-dbg/flow_storm/debugger/ui/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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 []
Expand All @@ -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)
Expand Down

0 comments on commit 477188f

Please sign in to comment.