diff --git a/0011-on.initialize b/0011-on.initialize index 836ad84..d2500a7 100644 --- a/0011-on.initialize +++ b/0011-on.initialize @@ -1,4 +1,5 @@ on.initialize = function() + App.mkdir(Directory) populate_missing_handlers() love.graphics.setFont(love.graphics.newFont(Font_height)) Line_height = math.floor(Font_height*1.3) diff --git a/0012-on.draw b/0012-on.draw index 9e195f5..66c789a 100644 --- a/0012-on.draw +++ b/0012-on.draw @@ -1,5 +1,10 @@ on.draw = function() Global_state.button_handlers = {} + -- modal dialog + if Show_file_dialog then + draw_file_dialog() + return + end Overflow_button = nil love.graphics.setBackgroundColor(Background_color.r, Background_color.g, Background_color.b) draw_canvas() diff --git a/0013-on.keychord_press b/0013-on.keychord_press index ba8d8c6..6d3f36e 100644 --- a/0013-on.keychord_press +++ b/0013-on.keychord_press @@ -1,4 +1,8 @@ on.keychord_press = function(chord, key) + if Show_file_dialog then + Show_file_dialog = false + return + end if chord == 'C-=' then update_font_settings(Current_pane.editor_state.font_height+2) elseif chord == 'C--' then diff --git a/0020-draw_editor_border b/0020-draw_editor_border index 78f2c68..40d3157 100644 --- a/0020-draw_editor_border +++ b/0020-draw_editor_border @@ -1,11 +1,26 @@ draw_editor_border = function() - App.color(Normal_color) + App.color{r=0.5, g=0.5, b=0.5} local x1 = Current_pane.editor_state.left-5-Line_number_padding local y1 = Current_pane.editor_state.top-5 local x2 = Current_pane.editor_state.right+5 local y2 = Current_pane.editor_state.bottom+5 -- upper border - love.graphics.line(x1,y1, x2,y1) + if Current_pane.filename then + -- title in between if it exists + local old_font = love.graphics.getFont() + if Title_font == nil then + Title_font = love.graphics.newFont(15) -- 20 pixels between menu and upper border - 5 + end + love.graphics.setFont(Title_font) + local tx1 = Current_pane.editor_state.left + local tx2 = tx1 + App.width(Current_pane.filename) + love.graphics.print(Current_pane.filename, tx1, y1-15+5) + love.graphics.setFont(old_font) + love.graphics.line(x1,y1, tx1-5,y1) + love.graphics.line(math.min(tx2+5,x2), y1, x2,y1) + else + love.graphics.line(x1,y1, x2,y1) + end love.graphics.line(x1,y1, x1,y1+10) love.graphics.line(x2,y1, x2,y1+10) -- lower border diff --git a/0021-draw_menu b/0021-draw_menu index 5e14ef5..5768646 100644 --- a/0021-draw_menu +++ b/0021-draw_menu @@ -28,6 +28,8 @@ draw_menu = function() else x, y = show_code_button(x, y, r) end + x, y = save_button(x, y, r) + x, y = load_button(x, y, r) x, y = copy_button(x, y, r) x, y = paste_button(x, y, r) x, y = clear_pane_button(x, y, r) diff --git a/0115-Title_font b/0115-Title_font new file mode 100644 index 0000000..ce624a7 --- /dev/null +++ b/0115-Title_font @@ -0,0 +1,2 @@ +-- Lua Carousel is almost entirely in a single (adjustable) font, but we make one exception to squeeze in a file name +Title_font = nil \ No newline at end of file diff --git a/0116-save_button b/0116-save_button new file mode 100644 index 0000000..df64ec0 --- /dev/null +++ b/0116-save_button @@ -0,0 +1,16 @@ +save_button = function(x, y, r) + return overflowable_button('save', x, y, r, + function() + print('save') + if Current_pane.filename == nil then + Directory_contents = nil -- refresh from file system + Show_file_dialog = true + File_dialog_callback = function(filename) + Current_pane.filename = filename + one_time_save() + end + else + one_time_save() + end + end) +end \ No newline at end of file diff --git a/0117-load_button b/0117-load_button new file mode 100644 index 0000000..d1dcd39 --- /dev/null +++ b/0117-load_button @@ -0,0 +1,11 @@ +load_button = function(x, y, r) + return overflowable_button('load', x, y, r, + function() + Directory_contents = nil -- refresh from file system + Show_file_dialog = true + File_dialog_callback = function(filename) + Current_pane.filename = filename + one_time_load() + end + end) +end \ No newline at end of file diff --git a/0119-draw_file_dialog b/0119-draw_file_dialog new file mode 100644 index 0000000..e7c679e --- /dev/null +++ b/0119-draw_file_dialog @@ -0,0 +1,30 @@ +draw_file_dialog = function() + App.color(Menu_background) + love.graphics.rectangle('fill', + Menu_left+5, + Menu_bottom+5, + Safe_width-Menu_left-10, + Safe_height-Menu_bottom-10) + if Directory_contents == nil then + -- on the first frame after dialog is enabled + refresh_directory_contents() + end + local x, y = Menu_left+10, Menu_bottom+10 + for _,filename in ipairs(Directory_contents) do + local w = App.width(filename) + 10 + if x == Menu_left+10 or x+w < Safe_width-Menu_left-10 then + styled_button(filename, x,y, function() + File_dialog_callback(filename) + Show_file_dialog = false + File_dialog_callback = nil + end) + x = x+w+10 + else + x = Menu_left+10 + y = y+Line_height+10 + if y > Safe_height-Menu_bottom-10 then + break + end + end + end +end \ No newline at end of file diff --git a/0120-Show_file_dialog b/0120-Show_file_dialog new file mode 100644 index 0000000..8e4b35c --- /dev/null +++ b/0120-Show_file_dialog @@ -0,0 +1 @@ +Show_file_dialog = false \ No newline at end of file diff --git a/0121-Directory b/0121-Directory new file mode 100644 index 0000000..280f973 --- /dev/null +++ b/0121-Directory @@ -0,0 +1 @@ +Directory = love.filesystem.getSourceBaseDirectory()..'/carousel_data/' \ No newline at end of file diff --git a/0122-Directory_contents b/0122-Directory_contents new file mode 100644 index 0000000..43dfbca --- /dev/null +++ b/0122-Directory_contents @@ -0,0 +1,2 @@ +-- filenames inside directory +Directory_contents = nil \ No newline at end of file diff --git a/0123-refresh_directory_contents b/0123-refresh_directory_contents new file mode 100644 index 0000000..6038db4 --- /dev/null +++ b/0123-refresh_directory_contents @@ -0,0 +1,10 @@ +refresh_directory_contents = function() + Directory_contents = {} + local files_info = nativefs.getDirectoryItemsInfo(Directory) + for _,file_info in ipairs(files_info) do + if file_info.type == 'file' then + table.insert(Directory_contents, file_info.name) + end + end + table.sort(Directory_contents) +end \ No newline at end of file diff --git a/0125-File_dialog_callback b/0125-File_dialog_callback new file mode 100644 index 0000000..8f9e5f1 --- /dev/null +++ b/0125-File_dialog_callback @@ -0,0 +1,2 @@ +-- Function that is called when a 'filename' is selected from the file dialog, e.g. to load from or save to a file. +File_dialog_callback = nil \ No newline at end of file diff --git a/0126-one_time_save b/0126-one_time_save new file mode 100644 index 0000000..8ad78d1 --- /dev/null +++ b/0126-one_time_save @@ -0,0 +1,7 @@ +one_time_save = function() + print('saving to '..Current_pane.filename) + Current_pane.editor_state.filename = Directory..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 +end \ No newline at end of file diff --git a/0127-one_time_load b/0127-one_time_load new file mode 100644 index 0000000..a74e3ad --- /dev/null +++ b/0127-one_time_load @@ -0,0 +1,8 @@ +one_time_load = function() + print('loading '..Current_pane.filename) + Current_pane.editor_state.filename = Directory..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 +end \ No newline at end of file