load stashed files

I'm scaling down my ambitions. Stashed files can't have notes attached.
I think that encourages a higher scale of development on such apps than
is currently justified, given you're liable to lose all your work if you
upgrade LÖVE.

New plan: just name stashed files with a numeric suffix.

The remaining open question is now around unstash. Should unstash copy
or move?
This commit is contained in:
Kartik K. Agaram 2024-03-17 14:38:42 -07:00
parent fc75f62d17
commit bd82e5ecbb
10 changed files with 42 additions and 15 deletions

View File

@ -18,7 +18,7 @@ draw_editor_border = function()
filename = filename..' *'
end
local tx2 = tx1 + App.width(filename)
if Current_pane.stash_note then
if Current_pane.is_stash then
App.color(Stash_color)
elseif has_local_modifications(Current_pane.filename) then
App.color(Local_modifications_color)

View File

@ -16,7 +16,7 @@ draw_menu = function()
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.stash_note then
if not Current_pane.is_stash then
x, y = stash_button(x, y, r)
end
x, y = revert_button(x, y, r)

View File

@ -31,7 +31,7 @@ draw_file_dialog = function()
-- on the first frame after dialog is enabled
Directory_contents = directory_contents(Directory)
end
local y = add_files_to_dialog(Directory_contents, Menu_left+10, Menu_bottom+10, local_modifications_color)
local y = add_files_to_dialog(Menu_left+10, Menu_bottom+10)
if Stash_directory_contents == nil then
-- on the first frame after dialog is enabled
Stash_directory_contents = directory_contents(Stash_directory)
@ -40,6 +40,5 @@ draw_file_dialog = function()
App.color{r=1, g=1, b=1}
g.print('stashed files:', Menu_left+10, y)
y = y+Line_height+5
y = add_files_to_dialog(Stash_directory_contents, Menu_left+10, y,
function(filename) return Stash_color end)
y = add_stash_files_to_dialog(Menu_left+10, y)
end

View File

@ -1,6 +1,7 @@
one_time_save = function()
print('saving to '..Current_pane.filename)
Current_pane.editor_state.filename = Directory..Current_pane.filename
local dir = Current_pane.is_stash and Stash_directory or Directory
Current_pane.editor_state.filename = dir..Current_pane.filename
save_to_disk(Current_pane.editor_state)
-- Don't autosave yet; undo isn't accessible in mobile devices.
Current_pane.editor_state.filename = nil

View File

@ -1,12 +1,16 @@
one_time_load = function()
print('loading '..Current_pane.filename)
if Current_pane.is_stash then
print('loading '..Current_pane.filename..' from stash')
else
print('loading '..Current_pane.filename)
end
edit.clear(Current_pane.editor_state)
Current_pane.editor_state.filename = Directory..Current_pane.filename
local dir = Current_pane.is_stash and Stash_directory or Directory
Current_pane.editor_state.filename = dir..Current_pane.filename
load_from_disk(Current_pane.editor_state)
Text.redraw_all(Current_pane.editor_state)
-- Disable autosave; undo isn't accessible in mobile devices.
Current_pane.editor_state.filename = nil
-- Clear some other recent state
Current_pane.stash_note = nil
Current_pane.editor_state.next_save = nil
end

View File

@ -5,6 +5,7 @@ press_save_button = function()
File_dialog_callback = function(filename)
if filename == '' then return end
Current_pane.filename = filename
assert(not Current_pane.is_stash)
one_time_save()
-- Load new filename in future sessions.
-- On mobile devices, we can't depend on on.save_settings() triggering on quit.

View File

@ -1,13 +1,14 @@
press_load_button = function()
Show_menu = nil
Show_file_dialog = true
File_dialog_callback = function(filename)
File_dialog_callback = function(filename, is_stash)
if filename == '' then
-- clear filename
Current_pane.filename = nil
return
end
Current_pane.filename = filename
Current_pane.is_stash = is_stash
one_time_load()
-- Load new filename in future sessions.
-- On mobile devices, we can't depend on on.save_settings() triggering on quit.

View File

@ -7,5 +7,5 @@ stash_pane = function(pane)
local success, error = love.filesystem.write(dest, contents)
if not success then return print_to_output(error) end
love.filesystem.remove(src)
pane.stash_note = ''
pane.is_stash = true
end

View File

@ -1,5 +1,5 @@
add_files_to_dialog = function(contents, x,y, colorfn)
for _,filename in ipairs(contents) do
add_files_to_dialog = function(x,y)
for _,filename in ipairs(Directory_contents) do
if filename:find(File_dialog_input_text) then
local w = Font:getWidth(filename) + 10
if x ~= Menu_left+10 and x+w > Safe_width-Menu_left-10 then
@ -10,12 +10,11 @@ add_files_to_dialog = function(contents, x,y, colorfn)
end
end
styled_button(filename, x,y, function()
-- TODO: File_dialog_callback needs to somehow know to load stashed files.
File_dialog_callback(filename)
reset_file_dialog_state()
end,
--[[tooltip text]] nil,
colorfn(filename))
local_modifications_color(filename))
x = x+w+10
end
end

View File

@ -0,0 +1,22 @@
add_stash_files_to_dialog = function(x,y)
for _,filename in ipairs(Stash_directory_contents) do
if filename:find(File_dialog_input_text) then
local w = Font:getWidth(filename) + 10
if x ~= Menu_left+10 and x+w > Safe_width-Menu_left-10 then
x = Menu_left+10
y = y+Line_height+10
if y > Safe_height-Menu_bottom-10 then
break
end
end
styled_button(filename, x,y, function()
File_dialog_callback(filename, --[[is stash?]] true)
reset_file_dialog_state()
end,
--[[tooltip text]] nil,
Stash_color)
x = x+w+10
end
end
return y
end