 
 ;; The main app
 
+(defn reset-document-state! [app]
+  (om/update! app :input "")
+  (om/update! app :title "")
+  (om/update! app :last-title "")
+  (om/update! app :last-input ""))
+
+(defn new-document [app]
+  (reset-document-state! app))
+
 (defn change-document [app title]
   (let [input (p/get-document title)]
     (om/update! app :input input)

  
(defn remove-document [app title]
  (p/remove-document title)
  (om/update! app :titles (p/get-all-titles)))

(defn dispatch [command params app]
  (case command
    :save   (save-document app)
    :rename (rename-document app params)
    :remove (remove-document app params)
    :change (change-document app params)))

(defn listen [el type app]
  (events/listen el type


;; New document

(defn new-document-click [app]
  (put! (:channel @app) [:new nil]))

(defn new-button [app owner]
  (reify
    om/IRender
    (render [_]
      (dom/span #js {:id "new-document"
                     :onClick #(new-document-click app)} "+"))))

;; Left menu

