start implementing stashed files

We can create them and see them on the file dialogs, but not yet load
them back.

I want stashed files to remember the original filename. I think that
implies the ability to add a note to them. But I don't yet know how to
represent the note on disk.

And this creates cascading questions, like should editing a stash file
continue to modify it or create a new version? How to create a new
version? Should unstash copy or move?
This commit is contained in:
Kartik K. Agaram 2024-03-17 13:51:10 -07:00
parent ec7f0bbe6e
commit fc75f62d17
13 changed files with 79 additions and 24 deletions

View File

@ -18,7 +18,9 @@ draw_editor_border = function()
filename = filename..' *'
end
local tx2 = tx1 + App.width(filename)
if has_local_modifications(Current_pane.filename) then
if Current_pane.stash_note then
App.color(Stash_color)
elseif has_local_modifications(Current_pane.filename) then
App.color(Local_modifications_color)
end
love.graphics.print(filename, tx1, y1-15+5)

View File

@ -16,6 +16,9 @@ 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
x, y = stash_button(x, y, r)
end
x, y = revert_button(x, y, r)
end
x, y = new_pane_button(x, y, r)
@ -30,4 +33,4 @@ draw_menu = function()
if Show_menu == 'settings' then
draw_settings_menu()
end
end
end

View File

@ -29,26 +29,17 @@ draw_file_dialog = function()
5,5)
if Directory_contents == nil then
-- on the first frame after dialog is enabled
refresh_directory_contents()
Directory_contents = directory_contents(Directory)
end
local x, y = Menu_left+10, Menu_bottom+10
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
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)
reset_file_dialog_state()
end,
--[[tooltip text]] nil,
local_modifications_color(filename))
x = x+w+10
end
local y = add_files_to_dialog(Directory_contents, Menu_left+10, Menu_bottom+10, local_modifications_color)
if Stash_directory_contents == nil then
-- on the first frame after dialog is enabled
Stash_directory_contents = directory_contents(Stash_directory)
end
y = y+Line_height+20
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)
end

View File

@ -6,4 +6,7 @@ one_time_load = function()
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

@ -1,3 +1,3 @@
revert_button = function(x,y, r)
return overflowable_button('revert', x, y, r, press_revert_button, --[[final button?]] false)
return overflowable_button('revert', x, y, r, press_revert_button)
end

View File

@ -1 +1 @@
Local_modifications_color = {r=0.8, g=0, b=0}
Local_modifications_color = {r=0.7, g=0, b=0}

1
0182-Stash_color Normal file
View File

@ -0,0 +1 @@
Stash_color = {r=0, g=0.3, b=0.6}

3
0183-stash_button Normal file
View File

@ -0,0 +1,3 @@
stash_button = function(x,y, r)
return overflowable_button('stash', x, y, r, press_stash_button)
end

1
0184-Stash_directory Normal file
View File

@ -0,0 +1 @@
Stash_directory = 'stash/'

11
0185-stash_pane Normal file
View File

@ -0,0 +1,11 @@
stash_pane = function(pane)
local src = Directory..pane.filename
local contents, error = love.filesystem.read(src)
if not contents then return print_to_output(error) end
love.filesystem.createDirectory(Stash_directory)
local dest = Stash_directory..pane.filename
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 = ''
end

5
0186-press_stash_button Normal file
View File

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

12
0187-directory_contents Normal file
View File

@ -0,0 +1,12 @@
directory_contents = function(directory)
contents = {}
local filenames = App.files(directory)
for _,filename in ipairs(filenames) do
local file_info = App.file_info(directory..filename)
if file_info.type == 'file' then
table.insert(contents, filename)
end
end
table.sort(contents)
return contents
end

23
0188-add_files_to_dialog Normal file
View File

@ -0,0 +1,23 @@
add_files_to_dialog = function(contents, x,y, colorfn)
for _,filename in ipairs(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()
-- 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))
x = x+w+10
end
end
return y
end