Skip to content

Commit

Permalink
Load file now confirms loss of unsaved changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CFiggers committed Aug 2, 2022
1 parent aec5e53 commit f9a6382
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/joule.janet
Original file line number Diff line number Diff line change
Expand Up @@ -739,12 +739,15 @@

### File I/O ###

(varfn confirm-lose-changes [])

(defn load-file [filename]
(let [erows (string/split "\n" (try (slurp filename)
([e f] (spit filename "")
(slurp filename))))]
(edset :filename filename
:erows erows)))
(slurp filename))))
callback |(edset :filename filename
:erows erows)]
(confirm-lose-changes callback)))

(defn ask-filename-modal []
(modal "Filename?" :input |(edset :filename (editor-state :modalinput))))
Expand Down Expand Up @@ -853,29 +856,32 @@

# TODO: Implement user config dotfile

(defn confirm-lose-changes [callback]
(do (case (string/ascii-lower (editor-state :modalinput))
"yes" (callback)
"n" (send-status-msg "Tip: Ctrl + s to Save.")
"no" (send-status-msg "Tip: Ctrl + s to Save.")
"s" (if (save-file)
(callback)
(send-status-msg "Tip: Ctrl + s to Save."))
"save" (if (save-file)
(callback)
(send-status-msg "Tip: Ctrl + s to Save."))
(send-status-msg "Tip: Ctrl + s to Save."))))
(varfn confirm-lose-changes [callback]
(let [dispatch
|(do (case (string/ascii-lower (editor-state :modalinput))
"yes" (callback)
"n" (send-status-msg "Tip: Ctrl + s to Save.")
"no" (send-status-msg "Tip: Ctrl + s to Save.")
"s" (if (save-file)
(callback)
(send-status-msg "Tip: Ctrl + s to Save."))
"save" (if (save-file)
(callback)
(send-status-msg "Tip: Ctrl + s to Save.")))
(send-status-msg "Tip: Ctrl + s to Save."))]
(if (< 0 (editor-state :dirty))
(do (modal "Are you sure? Unsaved changes will be lost. (yes/No/save)"
:input
dispatch)
(edset :dirty 0))
(callback))))

(varfn close-file [kind]
(let [callback (case kind
:quit |(set quit true)
:close |(do (reset-editor-state)
(send-status-msg "File closed.")))]
(if (< 0 (editor-state :dirty))
(modal "Are you sure? Unsaved changes will be lost. (yes/No/save)"
:input
|(confirm-lose-changes callback))
(callback))))
(confirm-lose-changes callback)))

(defn load-config []
)
Expand Down

0 comments on commit f9a6382

Please sign in to comment.