 (ns gui.main)
 
 ;; Menu Bar
+(defn handler-save
+  "Saves the content of the currently active tab in the node."
+  [_]
+  (when (tab-marked-new?)
+    (let [formula (.getText (current-editor))
+          node-list (get (zipmap (vals @*node-tabs*) (keys @*node-tabs*)) (:index (selection editor-tabs)))
+          project-node (second node-list)
+          node (last node-list)]
+      (if (nil? node)
+        (alert "No node.")
+        (do 
+          (set! (.content node) formula)
+          (change-project-list (.children tree-of-projects))
+          (save-project project-node)
+          (tab-demark-new))))))
+
 (defn handler-close-selcted-project
   [_]
   (change-project-list (apply list (remove #(= (second (selection project-tree)) %) (.children tree-of-projects)))))


(defn handler-add-new-proposition
  [_]
  (let [node (second(selection project-tree))
        name (-> (dialog :content
                         (vertical-panel :items ["Enter the proposition name" (text :id :name)])
                         :option-type :ok-cancel
                         :type :question
                         :success-fn (fn [p] (text (select (to-root p) [:#name])))) pack! show!)]
    (println name))) ;; TODO: hier weiter arbeiten!!! ;)
  
;; Project Tree
(defn- handler-tree

          (-> q-diag pack! show!))
        (remove-tab tab-index)))))

;; Listener
(defn tab-mark-new-listener
 "Listener function that should be called when a text in an editor changes.
