reveal

kenny 2021-11-15T01:15:52.050700Z

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?

kenny 2021-11-15T15:45:53.054100Z

@vlaaad any idea on this?

vlaaad 2021-11-15T15:47:28.054300Z

I'm boarding a plane right now :D

✈️ 1
vlaaad 2021-11-15T15:47:38.054500Z

Will look at it a bit later...

🙏🏻 1
vlaaad 2021-11-15T21:27:17.055200Z

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

vlaaad 2021-11-15T21:27:58.055400Z

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

vlaaad 2021-11-15T21:28:21.055600Z

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"}]}}})))

kenny 2021-11-15T21:31:49.056200Z

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?

vlaaad 2021-11-15T21:32:14.056400Z

you mean adding snippet to the examples?

vlaaad 2021-11-15T21:32:23.056600Z

or clojure.test integration?

kenny 2021-11-15T21:33:33.056800Z

First one

kenny 2021-11-15T21:33:47.057Z

Here: https://github.com/vlaaad/reveal/tree/master/examples

vlaaad 2021-11-15T21:34:43.057200Z

Sure, I can do that

kenny 2021-11-15T21:36:20.057400Z

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

vlaaad 2021-11-15T21:49:16.057900Z

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

kenny 2021-11-15T21:54:56.058100Z

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

kenny 2021-11-15T22:07:20.058500Z

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

kenny 2021-11-15T01:16:20.051200Z

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"}]}})))

vlaaad 2021-11-16T09:09:01.059700Z

Oh, backspace isn't documented there..

vlaaad 2021-11-16T09:09:29.059900Z

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

kenny 2021-11-15T01:18:32.052800Z

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"}]}}

vlaaad 2021-11-15T21:25:33.055Z

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

kenny 2021-11-15T21:30:03.055800Z

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.

kenny 2021-11-15T21:30:33.056Z

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

kenny 2021-11-15T01:44:20.053100Z

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