1
1
(in-ns 'cljfx.dev)
2
2
3
3
(require '[cljfx.component :as component]
4
+ '[cljfx.coerce :as coerce]
4
5
'[cljfx.fx.parent :as fx.parent]
5
6
'[cljfx.prop :as prop]
6
7
'[cljfx.mutator :as mutator]
171
172
(def ^:private ext-with-parent-props
172
173
(fx/make-ext-with-props fx.parent/props))
173
174
174
- (defn- inspector-handle-root-event [state {:keys [fx/event]}]
175
+ (defn- inspector-handle-root-event [state {:keys [fx/event shortcut ]}]
175
176
(if (instance? KeyEvent event)
176
177
(let [^KeyEvent event event]
177
178
(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)
180
181
state)
181
182
state))
182
183
state))
309
310
e
310
311
(.dispatchEvent dispatcher e next)))))))
311
312
312
- (defn- inspector-root-view [{:keys [components showing type->id path]}]
313
+ (defn- inspector-root-view [{:keys [components showing type->id path inspector-shortcut ]}]
313
314
(let [^Scene scene (->> components
314
315
(tree-seq :children #(vals (:children %)))
315
316
(keep :component )
316
317
(map component/instance)
317
318
(some #(when (instance? Scene %) %)))
318
- root (some-> scene .getRoot)]
319
+ root (some-> scene .getRoot)
320
+ shortcut (coerce/key-combination inspector-shortcut)]
319
321
(if root
320
322
{: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}}
322
325
:desc (cond-> {:fx/type inspector-popup-view
323
326
:auto-hide true
324
327
:hide-on-escape true
378
381
m
379
382
(apply update-in m k f args))))
380
383
381
- (defn- wrap-lifecycle [fx-type type->lifecycle type->id]
384
+ (defn- wrap-lifecycle [fx-type type->lifecycle type->id inspector-shortcut ]
382
385
(let [lifecycle (or (type->lifecycle fx-type) fx-type)]
383
386
(reify lifecycle/Lifecycle
384
387
(create [_ desc opts]
385
388
(let [component-info {:id (gensym " component" ) :type fx-type}
386
389
old-stack (::stack opts)
387
390
stack (conj old-stack component-info)
388
391
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!))
392
394
opts (assoc opts ::stack stack ::state state)]
393
395
(try
394
396
(ensure-valid-desc desc fx-type type->lifecycle type->id)
422
424
(try
423
425
(lifecycle/delete lifecycle (:child component) opts)
424
426
(catch Exception ex (re-throw-with-stack type->id ex stack))))))))
425
-
426
- ; ; TODO
427
- ; ; make shortcut configurable
0 commit comments