Skip to content

Commit

Permalink
Add quit confirmation dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaaad committed Jul 24, 2020
1 parent ec49fdd commit 45b2deb
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 46 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ![logo](src/logo-32.png) Reveal: Read Eval Visualize Loop for Clojure
# ![logo](src/vlaaad/reveal/logo-32.png) Reveal: Read Eval Visualize Loop for Clojure

![demo](doc/demo.gif)

Expand Down Expand Up @@ -112,6 +112,8 @@ alive.
- for full experience we should fork `System/out` and `System/err`, and re-bind roots of `*out*` and `*err*` — is it
a good idea?
- multiple accordions
- more actions:
- view files ending with `.html` as web pages
- improve datafy/nav support
- remember window position and size
- popup might appear in weird locations
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion src/vlaaad/reveal/font.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#(.invoke meth % (into-array Object [])))))

(def ^javafx.scene.text.Font font
(javafx.scene.text.Font/loadFont (io/input-stream (io/resource "FantasqueSansMono-Regular.ttf")) 14.5))
(javafx.scene.text.Font/loadFont
(io/input-stream
(io/resource "vlaaad/reveal/FantasqueSansMono-Regular.ttf")) 14.5))

(let [metrics (.getFontMetrics (.getFontLoader (Toolkit/getToolkit)) font)]
(def ^double ^:const line-height (Math/ceil (.getLineHeight metrics)))
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
17 changes: 14 additions & 3 deletions src/vlaaad/reveal/style.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require [cljfx.css :as css]
[vlaaad.reveal.font :as font]))

(def cell-height 25)
(def scroll-bar-size 10)
(def util-color "#888")
(def symbol-color "#aec1d0")
Expand All @@ -21,14 +20,15 @@
(def keyword-color "#a55cfc")
(def search-color "#aec1d0")
(def search-shade-color (str search-color "55"))
(def default-padding 5)

(def style
(css/register ::main
{".reveal"
{"-ui" {:-fx-background-color background-color}
"-popup" {:-fx-background-color popup-color
:-fx-spacing 5
:-fx-padding 5
:-fx-spacing default-padding
:-fx-padding default-padding
"-scroll-pane" {:-fx-hbar-policy :never
:-fx-min-height 0}
"-item" {:-fx-font-family font-family
Expand Down Expand Up @@ -98,6 +98,17 @@
".label" {:-fx-text-fill symbol-color
:-fx-font-family font-family
:-fx-font-size font-size}
".button" {:-fx-text-fill util-color
:-fx-font-family font-family
:-fx-font-size font-size
:-fx-background-color :transparent
:-fx-background-radius 0
:-fx-border-width 1
:-fx-border-color unfocused-selection-color
":hover" {:-fx-text-fill symbol-color}
":focused" {:-fx-background-color selection-color
:-fx-text-fill symbol-color
:-fx-border-color :transparent}}
".cell" {:-fx-text-fill symbol-color
:-fx-background-color :transparent}
;; scroll bars
Expand Down
134 changes: 93 additions & 41 deletions src/vlaaad/reveal/ui.clj
Original file line number Diff line number Diff line change
Expand Up @@ -160,45 +160,89 @@
:desc {:fx/type fx/ext-get-ref
:ref focused-view-id}}]}))

(defn- view [{:keys [queue showing view-order views focused-view-index]}]
(defmethod event/handle ::confirm-exit [*state {:keys [^Event fx/event]}]
(.consume event)
(swap! *state assoc :confirm-exit-showing true))

(defmethod event/handle ::cancel-quit [*state _]
(swap! *state dissoc :confirm-exit-showing))

(defmethod event/handle ::quit [*state _]
((:dispose (swap! *state dissoc :confirm-exit-showing))))

(defn- confirm-exit-dialog [_]
{:fx/type :stage
:showing true
:owner {:fx/type fx/ext-get-ref :ref ::stage}
:on-close-request {::event/type ::cancel-quit}
:modality :window-modal
:title "Quit Reveal?"
:scene {:fx/type :scene
:stylesheets [(:cljfx.css/url style/style)]
:accelerators {[:escape] {::event/type ::cancel-quit}}
:root {:fx/type :v-box
:style-class "reveal-ui"
:spacing style/default-padding
:padding style/default-padding
:children [{:fx/type :label
:text "Are you sure you want to quit Reveal?"}
{:fx/type :h-box
:spacing 5
:alignment :center-right
:children [{:fx/type :button
:on-action {::event/type ::cancel-quit}
:text "Cancel"}
{:fx/type ext-focused-by-default
:desc {:fx/type :button
:on-action {::event/type ::quit}
:text "Quit"}}]}]}}})

(defn- view [{:keys [queue showing view-order views focused-view-index confirm-exit-showing]}]
{:fx/type fx/ext-let-refs
:refs (into {} (map (juxt key #(-> % val :desc)) views))
:desc
{:fx/type :stage
:title "Reveal"
;; todo ask if user wants to quit repl (default) or exit jvm
:on-close-request #(.consume ^Event %)
:showing showing
:width 400
:height 500
:icons ["logo-16.png" "logo-32.png" "logo-64.png" "logo-256.png" "logo-512.png"]
:on-focused-changed {::event/type ::on-window-focused-changed}
:scene {:fx/type :scene
:stylesheets [(:cljfx.css/url style/style)]
:root {:fx/type :grid-pane
:style-class "reveal-ui"
:column-constraints [{:fx/type :column-constraints
:hgrow :always}]
:row-constraints (if focused-view-index
[{:fx/type :row-constraints
:percent-height 50}
{:fx/type :row-constraints
:percent-height 50}]
[{:fx/type :row-constraints
:percent-height 100}])
:children
(cond-> [{:fx/type view/queue
:grid-pane/row 0
:grid-pane/column 0
:queue queue
:id :output}]
focused-view-index
(conj {:fx/type tabs-view
:grid-pane/row 1
:grid-pane/column 0
:views views
:view-order view-order
:focused-view-index focused-view-index}))}}}})
:desc {:fx/type fx/ext-let-refs
:refs {::stage {:fx/type :stage
:title "Reveal"
:on-close-request {::event/type ::confirm-exit}
:showing showing
:width 400
:height 500
:icons ["vlaaad/reveal/logo-16.png"
"vlaaad/reveal/logo-32.png"
"vlaaad/reveal/logo-64.png"
"vlaaad/reveal/logo-256.png"
"vlaaad/reveal/logo-512.png"]
:on-focused-changed {::event/type ::on-window-focused-changed}
:scene {:fx/type :scene
:stylesheets [(:cljfx.css/url style/style)]
:root {:fx/type :grid-pane
:style-class "reveal-ui"
:column-constraints [{:fx/type :column-constraints
:hgrow :always}]
:row-constraints (if focused-view-index
[{:fx/type :row-constraints
:percent-height 50}
{:fx/type :row-constraints
:percent-height 50}]
[{:fx/type :row-constraints
:percent-height 100}])
:children
(cond-> [{:fx/type view/queue
:grid-pane/row 0
:grid-pane/column 0
:queue queue
:id :output}]
focused-view-index
(conj {:fx/type tabs-view
:grid-pane/row 1
:grid-pane/column 0
:views views
:view-order view-order
:focused-view-index focused-view-index}))}}}}
:desc {:fx/type fx/ext-let-refs
:refs (when confirm-exit-showing
{::confirm-exit {:fx/type confirm-exit-dialog}})
:desc {:fx/type fx/ext-get-ref :ref ::stage}}}})

(defn oneduce
([xf x]
Expand Down Expand Up @@ -231,16 +275,24 @@
(defn make []
(let [*running! (agent true)
value-queue (ArrayBlockingQueue. 1024)
*state (atom {:queue value-queue :views {} :view-order [] :showing true})
*state (atom {:queue value-queue
:views {}
:view-order []
:showing true
:dispose (constantly nil)})
event-handler (event/->MapEventHandler *state)
renderer (fx/create-renderer
:opts {:fx.opt/map-event-handler event-handler}
:middleware (fx/wrap-map-desc #'view))]
:middleware (fx/wrap-map-desc #'view))
dispose! #(do
(fx/unmount-renderer *state renderer)
(send-via event/daemon-executor *running! stop-queue value-queue))]
(fx/mount-renderer *state renderer)
(swap! *state assoc :dispose dispose!)
(fn
([]
(fx/unmount-renderer *state renderer)
(send-via event/daemon-executor *running! stop-queue value-queue))
(dispose!)
nil)
([x]
(send-via event/daemon-executor *running! put-on-queue value-queue x)
x))))

0 comments on commit 45b2deb

Please sign in to comment.