Fork me on GitHub
#reveal
<
2021-11-15
>
kenny01:11:52

I have an action that uses a :tree-view. After executing the action, the tree view opens, but I can no longer use my escape key to close the results panel. If I click the escape key, nothing happens whereas I expect the results panel to close. I'm guessing it has something to do with the "Editing" mode of a https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TreeView.html, but I'm not sure. Any idea what causes this and how I might disable it to get Reveal's usual behavior of closing the result panel on the escape key press?

kenny01:11:20

Example treeview action:

(rx/defaction ::example-tree-view [x]
  (when (::example-tree-view x)
    (fn []
      {:fx/type :tree-view
       :root    {:fx/type  :tree-item
                 :value    "Inbox"
                 :children [{:fx/type :tree-item
                             :value   "Email 1"}]}})))

kenny15:11:53

@U47G49KHQ any idea on this?

vlaaad15:11:28

I'm boarding a plane right now :D

✈️ 1
vlaaad15:11:38

Will look at it a bit later...

1
vlaaad21:11:17

This is a problem with default tree view behavior consuming not only escape key press, but also ctrl+up/left/right that is used by reveal results panel for navigation between different results

vlaaad21:11:58

the workaround is to re-configure tree view so it does not handle escape and ctrl+left/up/right at all

vlaaad21:11:21

Here is how to do it:

(require '[vlaaad.reveal.ext :as rx]
         '[cljfx.api :as fx])

(import '[javafx.scene.input KeyEvent KeyCode]
        '[javafx.scene.control TreeView]
        '[javafx.event EventDispatcher])

(defn- init-tree-view! [^TreeView tree-view]
  (let [dispatcher (.getEventDispatcher tree-view)]
    (.setEventDispatcher tree-view
                         (reify EventDispatcher
                           (dispatchEvent [_ e next]
                             (if (and (instance? KeyEvent e)
                                      (or (and
                                            (.isShortcutDown ^KeyEvent e)
                                            (#{KeyCode/UP KeyCode/DOWN KeyCode/LEFT KeyCode/RIGHT} (.getCode ^KeyEvent e)))
                                          (= KeyCode/ESCAPE (.getCode ^KeyEvent e))))
                               e
                               (.dispatchEvent dispatcher e next)))))))

(rx/defaction ::example-tree-view [x]
   (when (::example-tree-view x)
     (fn []
       {:fx/type fx/ext-on-instance-lifecycle
        :on-created init-tree-view!
        :desc {:fx/type :tree-view
               :root {:fx/type :tree-item
                      :value "Inbox"
                      :children [{:fx/type :tree-item
                                  :value "Email 1"}]}}})))

kenny21:11:49

Thank you for that snippet. That will make working on the clojure.test integration sooooo much easier. Might I suggest adding it to the https://github.com/vlaaad/reveal/tree/master/examples?

vlaaad21:11:14

you mean adding snippet to the examples?

vlaaad21:11:23

or clojure.test integration?

kenny21:11:33

First one

vlaaad21:11:43

Sure, I can do that

kenny21:11:20

Awesome. You would laugh at how often I had to restart reveal because I just wanted to results panel closed 😅

vlaaad21:11:16

Heh. You can always click on results panel title (e.g. (example-tree-view {...})) and then use backspace to close selected tab

kenny21:11:56

TIL. Thank you. How could I have discovered that myself?

kenny22:11:20

I may be missing it, but doesn't that just document the ECS key to close the tab?

vlaaad09:11:01

Oh, backspace isn't documented there..

vlaaad09:11:29

I should create one universal shortcut that shows all available shortcuts...

kenny01:11:32

Separately, I noticed that the tree view has some odd styling issues. The toggle arrow seems to appear & disappear for the below tree-view (see screenshot with missing toggle)

{:fx/type :tree-view
 :root    {:fx/type  :tree-item
           :value    "Inbox"
           :children [{:fx/type :tree-item
                       :value   "Email 1"}]}}

kenny01:11:20

Clicking a row also does not visibly select the row. Perhaps a styling thing?

vlaaad21:11:33

It's a styling issue! I made some improvements to tree-view styling before for paid version and now imported those changes to free version, please update to 1.3.228 to get better tree-view styling

kenny21:11:03

Oh awesome! Thanks for verifying -- I'm still really new to cljfx, but knowing that should help me debug oddities like that in the future.

kenny21:11:33

(happy to switch to the paid version once I can actually switch my repl over to reveal 🙂 )