                          #_[[(:scroll-pane (get-editor)) "wrap, span 2, w 100%, h 75%"]
                            [(:scroll-pane @repl-input-window) "w 50%, h 25%"]
                            [(:scrollable @repl-output-window) "w 50%, h 25%"]])
-        f (frame :title "Brevis - UI" :width 1024 :height 768 #_:minimum-size #_[800 :by 600] :menubar menus)]
+        f (frame :title "Brevis" :width 1024 :height 768 #_:minimum-size #_[800 :by 600] 
+                 :menubar menus :on-close :nothing #_:exit)]
+    (listen f
+            #{:window-closed :window-closing}
+            a-exit)
     (listen (:project-tree @project-browser) #_(select f [:#project-tree]) :selection
             (fn [e]
               (if-let [dir (last (selection e))]

(defn make-ui
  "Make a multi-widget UI."
  []
  (let [a-new (action :handler a-new :name "New" :tip "Create a new file.")
        a-open (action :handler a-open :name "Open" :tip "Open a file")
        a-save (action :handler a-save :name "Save" :tip "Save the current file.")
        a-exit (action :handler a-exit :name "Exit" :tip "Exit the editor.")
        a-copy (action :handler a-copy :name "Copy" :tip "Copy selected text to the clipboard.")
        a-paste (action :handler a-paste :name "Paste" :tip "Paste text from the clipboard.")
        a-cut (action :handler a-cut :name "Cut" :tip "Cut text to the clipboard.")
        a-save-as (action :handler a-save-as :name "Save As" :tip "Save the current file.")
        a-eval-file (action :handler a-eval-file :name "Evaluate" :tip "Evaluate the current file.")
        a-restart-brevis
        (action :handler (fn [e]
                           (System/exit 1))
                :name "Restart Brevis"
                :tip "Completely restarts the application")
        a-projects (map #(action :handler (make-a-active-project %)
                                 :name (str (:group %) "/" (:name %))
                                 :tip (str (:group %) "/" (:name %)))
                        (:projects @current-profile))
        menus (menubar
                :items [(menu :text "File" :items [a-new a-open a-save a-save-as a-exit])
                        (menu :text "Edit" :items [a-copy a-cut a-paste])
                        (menu :text "Run" :items [a-eval-file])
                        (menu :text "Projects" :items (into [] a-projects))
                        (menu :text "Git" :items [])
                        (menu :text "Brevis" :items [a-restart-brevis]) 
                        #_(menu :text "My Project" :items [(action :handler (fn [e] nil) :name "Open a project")
                                                          (action :handler (fn [e] nil) :name "in")
                                                          (action :handler (fn [e] nil) :name "projects menu")])])

      (spit selected
            (get-text-from-tab tab-idx)))))

(declare save-IDE-state)
(defn a-exit  [e]   
  (save-IDE-state)
  (System/exit 0))
(defn a-copy  [e] (.copy (:text-area (get-editor))))
(defn a-cut   [e] (.cut (:text-area (get-editor))))
(defn a-paste [e] (.paste (:text-area (get-editor))))
