Skip to content

Commit

Permalink
Change Exceptions from a ComboBox to MenuButton
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmonettas committed Mar 15, 2024
1 parent b34891e commit 36509f3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
- Multi-thread timeline

### Changes

- Change Exceptions from a ComboBox to MenuButton

### Bugs fixed

## 3.12.2 (05-03-2024)
Expand Down
27 changes: 17 additions & 10 deletions src-dbg/flow_storm/debugger/ui/flows/screen.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@
[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? combo-box-set-items]]
key-combo-match?]]
[flow-storm.debugger.state :as dbg-state :refer [store-obj obj-lookup clean-objs]])
(:import [javafx.scene.input MouseButton]
[javafx.scene.control SingleSelectionModel SplitPane Tab]
[javafx.geometry Orientation]
[javafx.beans.value ChangeListener]))

(declare create-or-focus-thread-tab)

(defn update-exceptions-combo []
(let [unwinds (dbg-state/get-fn-unwinds)
[ex-combo] (obj-lookup "exceptions-combo")
[ex-box] (obj-lookup "exceptions-box")]
(ui-utils/clear-classes ex-box)
(when (zero? (count unwinds))
(ui-utils/add-class ex-box "hidden-pane"))
(combo-box-set-items ex-combo unwinds)))
(declare update-exceptions-combo)

(defn remove-flow [flow-id]
(let [[flows-tabs-pane] (obj-lookup "flows_tabs_pane")
Expand Down Expand Up @@ -272,6 +264,21 @@
thread-id
(runtime-api/timeline-entry rt-api flow-id thread-id idx :at)))

(defn update-exceptions-combo []
(let [unwinds (dbg-state/get-fn-unwinds)
[{:keys [set-items]}] (obj-lookup "exceptions-menu-data")
[ex-box] (obj-lookup "exceptions-box")]
(ui-utils/clear-classes ex-box)
(when (zero? (count unwinds))
(ui-utils/add-class ex-box "hidden-pane"))
(set-items (mapv (fn [{:keys [flow-id thread-id idx fn-ns fn-name ex-type]}]
{:text (format "%d - %s/%s %s" idx fn-ns fn-name ex-type)
:on-click (fn [_]
(goto-location {:flow-id flow-id
:thread-id thread-id
:idx idx}))})
unwinds))))

(defn main-pane []
(let [t-pane (tab-pane {:closing-policy :all-tabs
:side :top})]
Expand Down
18 changes: 5 additions & 13 deletions src-dbg/flow_storm/debugger/ui/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
(:require [flow-storm.debugger.ui.utils
:as ui-utils
:refer [label icon-button event-handler h-box progress-indicator progress-bar tab tab-pane border-pane
key-combo-match? combo-box]]
key-combo-match? menu-button]]
[flow-storm.debugger.ui.flows.screen :as flows-screen]
[flow-storm.debugger.ui.flows.general :as ui-general]
[flow-storm.debugger.ui.browser.screen :as browser-screen]
Expand Down Expand Up @@ -204,17 +204,9 @@
(flows-screen/goto-location result)))}))}))
(runtime-api/all-fn-call-stats rt-api))))])
(.setAlignment Pos/CENTER_LEFT))
format-exception-item (fn [{:keys [idx fn-ns fn-name ex-type]}]
(format "%d - %s/%s %s" idx fn-ns fn-name ex-type))
exceptions-combo (combo-box {:on-change-fn (fn [_ {:keys [flow-id thread-id idx] :as to-item}]
(when to-item
(flows-screen/goto-location {:flow-id flow-id
:thread-id thread-id
:idx idx})))
:cell-factory-fn (fn [_ item] (doto (label (format-exception-item item))
(.setTooltip (ui-utils/tool-tip (or (:ex-message item) "")))))
:button-factory-fn (fn [_ item] (label (format-exception-item item)))})
exceptions-box (doto (h-box [(label "Exceptions:") exceptions-combo]

exceptions-menu-data (menu-button {:items []})
exceptions-box (doto (h-box [(:menu-button exceptions-menu-data)]
"hidden-pane")
(.setAlignment Pos/CENTER_LEFT))
tools [clear-btn
Expand All @@ -227,7 +219,7 @@

(store-obj "task-cancel-btn" task-cancel-btn)
(store-obj "exceptions-box" exceptions-box)
(store-obj "exceptions-combo" exceptions-combo)
(store-obj "exceptions-menu-data" exceptions-menu-data)
(store-obj "record-btn" record-btn)
(ToolBar. (into-array Node tools))))

Expand Down
22 changes: 21 additions & 1 deletion src-dbg/flow_storm/debugger/ui/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[flow-storm.debugger.state :as dbg-state :refer [store-obj obj-lookup]])
(:import [javafx.scene.control Button ContextMenu Label ListView SelectionMode ListCell MenuItem ScrollPane Tab
Alert ButtonType Alert$AlertType ProgressIndicator ProgressBar TextField TextArea TableView TableColumn TableCell TableRow
TabPane$TabClosingPolicy TabPane$TabDragPolicy TableColumn$CellDataFeatures TabPane Tooltip
TabPane$TabClosingPolicy TabPane$TabDragPolicy TableColumn$CellDataFeatures TabPane Tooltip MenuButton MenuItem
ComboBox CheckBox TextInputDialog]
[javafx.scene.input KeyCharacterCombination KeyCombination$Modifier KeyCombination]
[javafx.scene.layout HBox VBox BorderPane]
Expand Down Expand Up @@ -254,6 +254,26 @@

ta))

(defn menu-button [{:keys [items]}]
(let [mb (MenuButton. "Exceptions")
clear-items (fn [] (-> mb .getItems .clear))
add-item (fn [{:keys [text on-click] :as item}]
(let [mi (doto (MenuItem. text)
(.setOnAction (event-handler [_]
(on-click item))))]
(-> mb .getItems (.add mi))))
set-items (fn [new-items]
(clear-items)
(doseq [item new-items]
(add-item item)))]

(set-items items)

{:menu-button mb
:set-items set-items
:clear-items clear-items
:add-item add-item}))

(defn combo-box-set-items [^ComboBox cbox items]
(let [observable-list (FXCollections/observableArrayList)]
(.setItems cbox observable-list)
Expand Down

0 comments on commit 36509f3

Please sign in to comment.