 
 (defn close! [^Scene scene]
   (when-let [path (:selection @pref-state)]
-    (let [file (io/file path)
-          new-path (if (.isDirectory file)
-                     path
-                     (.getCanonicalPath (.getParentFile file)))
-          project-tree (.lookup scene "#project_tree")]
-      (e/remove-editors! path runtime-state)
-      (p/update-project-tree-selection! project-tree new-path))
-    (p/remove-project! path runtime-state)))
+    (when (should-remove? scene path)
+      (let [file (io/file path)
+            new-path (if (.isDirectory file)
+                       path
+                       (.getCanonicalPath (.getParentFile file)))
+            project-tree (.lookup scene "#project_tree")]
+        (e/remove-editors! path runtime-state)
+        (p/update-project-tree-selection! project-tree new-path))
+      (p/remove-project! path runtime-state))))
 
 (defn -onClose [this ^ActionEvent event]
   (-> event .getSource .getScene close!))


; remove

(defn remove! [^Scene scene]
  (let [{:keys [project-set selection]} @pref-state
        message (if (contains? project-set selection)

                 (.initOwner (.getWindow scene))
                 (.initModality Modality/WINDOW_MODAL))
        project-tree (.lookup scene "#project_tree")]
    (when (and (-> dialog .showAndWait (.orElse nil) (= ButtonType/OK))
               (should-remove? scene selection))
      (p/remove-from-project-tree! pref-state selection)
      (e/remove-editors! selection runtime-state)
      (p/update-project-tree! pref-state project-tree))))
