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:
parent
ab11782662
commit
6c65b5dcdb
|
@ -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)
|
||||
end
|
||||
x, y = revert_button(x, y, r)
|
||||
elseif can_be_unstashed(Current_pane) then
|
||||
x, y = unstash_button(x, y, r)
|
||||
end
|
||||
end
|
||||
x, y = new_pane_button(x, y, r)
|
||||
x, y = delete_pane_button(x, y, r)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
unstash_button = function(x,y, r)
|
||||
return overflowable_button('unstash', x, y, r, press_unstash_button)
|
||||
end
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,3 @@
|
|||
unstash_filename = function(filename)
|
||||
return filename:gsub('%..*', '')
|
||||
end
|
|
@ -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
|
Loading…
Reference in New Issue