unstash a stashed file

Current design choices:
* Unstashing doesn't delete the file. You have to bump down to the
  scratch screen for that.
* Can't unstash if the file already has local modifications. Decide
  whether to revert or stash them.
This commit is contained in:
Kartik K. Agaram 2024-03-17 15:22:53 -07:00
parent ab11782662
commit 6c65b5dcdb
6 changed files with 34 additions and 3 deletions

View File

@ -15,11 +15,13 @@ draw_menu = function()
x, y = load_button(x, y, r)
x, y = paste_button(x, y, r)
x, y = copy_button(x, y, r)
if Current_pane.filename and has_local_modifications(Current_pane.filename) then
if not Current_pane.is_stash then
if Current_pane.filename then
if has_local_modifications(Current_pane.filename) then
x, y = stash_button(x, y, r)
x, y = revert_button(x, y, r)
elseif can_be_unstashed(Current_pane) then
x, y = unstash_button(x, y, r)
end
x, y = revert_button(x, y, r)
end
x, y = new_pane_button(x, y, r)
x, y = delete_pane_button(x, y, r)

3
0191-unstash_button Normal file
View File

@ -0,0 +1,3 @@
unstash_button = function(x,y, r)
return overflowable_button('unstash', x, y, r, press_unstash_button)
end

View File

@ -0,0 +1,5 @@
press_unstash_button = function()
-- disable local modifications to a file without deleting it or saving the pane
Show_menu = nil
unstash_pane(Current_pane)
end

12
0193-unstash_pane Normal file
View File

@ -0,0 +1,12 @@
unstash_pane = function(pane)
local src = Stash_directory..pane.filename
local contents, error = love.filesystem.read(src)
if not contents then return print_to_output(error) end
love.filesystem.createDirectory(Directory)
local filename = unstash_filename(pane.filename)
local dest = Directory..filename
local success, error = love.filesystem.write(dest, contents)
if not success then return print_to_output(error) end
pane.filename = filename
pane.is_stash = nil
end

3
0194-unstash_filename Normal file
View File

@ -0,0 +1,3 @@
unstash_filename = function(filename)
return filename:gsub('%..*', '')
end

6
0195-can_be_unstashed Normal file
View File

@ -0,0 +1,6 @@
can_be_unstashed = function(pane)
if not pane.is_stash then return end
assert(pane.filename)
local filename = unstash_filename(pane.filename)
return not nativefs.getInfo(App.save_dir..Directory..filename)
end