Skip to content

Commit 26a7935

Browse files
committed
Make inspector shortcut configurable
1 parent 4eb3fbf commit 26a7935

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/cljfx/dev.clj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,18 @@
337337
stack to help with debugging.
338338
339339
Optional kv-args:
340-
type->lifecycle the type->lifecycle fn used in opts of your app
341-
type->id custom type->id if you need a way to get id from your
342-
custom lifecycles"
343-
[& {:keys [type->lifecycle type->id]
340+
type->lifecycle the type->lifecycle fn used in opts of your app
341+
type->id custom type->id if you need a way to get id from your
342+
custom lifecycles
343+
inspector-shortcut shortcut to open cljfx component inspector view, key
344+
combination, defaults to [:f12]"
345+
[& {:keys [type->lifecycle type->id inspector-shortcut]
344346
:or {type->lifecycle *type->lifecycle*
345-
type->id *type->id*}}]
347+
type->id *type->id*
348+
inspector-shortcut [:f12]}}]
346349
(let [f (memoize wrap-lifecycle)]
347350
(fn [type]
348-
(f type type->lifecycle type->id))))
351+
(f type type->lifecycle type->id inspector-shortcut))))
349352

350353
(def type->lifecycle
351354
"Default type->lifecycle that can be used in the cljfx UI app to improve error

src/cljfx/dev/validation.clj

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(in-ns 'cljfx.dev)
22

33
(require '[cljfx.component :as component]
4+
'[cljfx.coerce :as coerce]
45
'[cljfx.fx.parent :as fx.parent]
56
'[cljfx.prop :as prop]
67
'[cljfx.mutator :as mutator]
@@ -171,12 +172,12 @@
171172
(def ^:private ext-with-parent-props
172173
(fx/make-ext-with-props fx.parent/props))
173174

174-
(defn- inspector-handle-root-event [state {:keys [fx/event]}]
175+
(defn- inspector-handle-root-event [state {:keys [fx/event shortcut]}]
175176
(if (instance? KeyEvent event)
176177
(let [^KeyEvent event event]
177178
(if (= KeyEvent/KEY_PRESSED (.getEventType event))
178-
(condp = (.getCode event)
179-
KeyCode/F12 (update state :showing not)
179+
(if (.match ^KeyCombination shortcut event)
180+
(update state :showing not)
180181
state)
181182
state))
182183
state))
@@ -309,16 +310,18 @@
309310
e
310311
(.dispatchEvent dispatcher e next)))))))
311312

312-
(defn- inspector-root-view [{:keys [components showing type->id path]}]
313+
(defn- inspector-root-view [{:keys [components showing type->id path inspector-shortcut]}]
313314
(let [^Scene scene (->> components
314315
(tree-seq :children #(vals (:children %)))
315316
(keep :component)
316317
(map component/instance)
317318
(some #(when (instance? Scene %) %)))
318-
root (some-> scene .getRoot)]
319+
root (some-> scene .getRoot)
320+
shortcut (coerce/key-combination inspector-shortcut)]
319321
(if root
320322
{:fx/type ext-with-parent-props
321-
:props {:event-filter {:fn #'inspector-handle-root-event}}
323+
:props {:event-filter {:fn #'inspector-handle-root-event
324+
:shortcut shortcut}}
322325
:desc (cond-> {:fx/type inspector-popup-view
323326
:auto-hide true
324327
:hide-on-escape true
@@ -378,17 +381,16 @@
378381
m
379382
(apply update-in m k f args))))
380383

381-
(defn- wrap-lifecycle [fx-type type->lifecycle type->id]
384+
(defn- wrap-lifecycle [fx-type type->lifecycle type->id inspector-shortcut]
382385
(let [lifecycle (or (type->lifecycle fx-type) fx-type)]
383386
(reify lifecycle/Lifecycle
384387
(create [_ desc opts]
385388
(let [component-info {:id (gensym "component") :type fx-type}
386389
old-stack (::stack opts)
387390
stack (conj old-stack component-info)
388391
state (or (::state opts) (doto (atom {:components {}
389-
:type->id type->id}) init-state!
390-
;; mount here, add root node search / listener as view
391-
#_(->> (def --state))))
392+
:inspector-shortcut inspector-shortcut
393+
:type->id type->id}) init-state!))
392394
opts (assoc opts ::stack stack ::state state)]
393395
(try
394396
(ensure-valid-desc desc fx-type type->lifecycle type->id)
@@ -422,6 +424,3 @@
422424
(try
423425
(lifecycle/delete lifecycle (:child component) opts)
424426
(catch Exception ex (re-throw-with-stack type->id ex stack))))))))
425-
426-
;; TODO
427-
;; make shortcut configurable

0 commit comments

Comments
 (0)