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:
parent
ec7f0bbe6e
commit
fc75f62d17
|
@ -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)
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -1 +1 @@
|
|||
Local_modifications_color = {r=0.8, g=0, b=0}
|
||||
Local_modifications_color = {r=0.7, g=0, b=0}
|
|
@ -0,0 +1 @@
|
|||
Stash_color = {r=0, g=0.3, b=0.6}
|
|
@ -0,0 +1,3 @@
|
|||
stash_button = function(x,y, r)
|
||||
return overflowable_button('stash', x, y, r, press_stash_button)
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
Stash_directory = 'stash/'
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue