add keyboard shortcuts for common operations

akkartik
Feb 21, 2024, 2:45 PM
YR7AXEYBLB7Y4OZKPX4REW5JD5VOCSKMAC2TR5N75UJEG72XJUQAC

Dependencies

  • [2] ZGPYJMP3 bugfix: crash when saving to empty file
  • [3] DZLFYLDU manually save settings on change to loaded filenames
  • [4] AZMYKWMH resolve conflicts
  • [5] OGDDLU5B close all menus when tapping any button
  • [6] W3RRTO4P extract a second helper for buttons
  • [7] 6DJMOJKE support event handlers
  • [8] PRE6XPRN responsively increase/decrease font height
  • [9] 4QFVRJ5U get rid of pane transition animations
  • [10] X2YWEIZS bugfix: missing variable in a button
  • [11] W4EQ6IW4 simplify state management for menus
  • [12] 5MEJ7XNH lay out buttons based on device dimensions
  • [13] I27BLL75 new car.quit callback for user scripts
  • [14] PN6VP3LV escape hatch when print is overridden
  • [15] 4GX6NAY4 some very basic animations for switching panes
  • [16] RK2ASPN7 add lots of buttons to the toolbar
  • [17] 6VPJTZFS reset file system state with everything else
  • [18] HVXZLNCC send errors from event handlers to output editor
  • [19] SIJ5I4NZ extract a helper for buttons
  • [20] FIUQJVL2 first draft of load/save buttons
  • [21] JV27LDDK sliders for font size and color settings
  • [22] GAKJROFZ ahh, got the background color sliders working
  • [23] NV4WC3K4 new example: interactivity
  • [24] V2G455IR clean up a debug print
  • [25] GWLETNMW Mike's suggested button layout
  • [26] I52S4E5F running `print` now appends to output editor
  • [*] R5QXEHUI somebody stop me
  • [*] ZM7NOBRM new fork: carousel shell

Change contents

  • file addition: 0168-press_previous_pane_button (----------)
    [28.2]
    press_previous_pane_button = function()
    Show_menu = nil
    Current_pane.car = car
    Current_pane_index = Current_pane_index-1
    Current_pane = Panes[Current_pane_index]
    car = Current_pane.car or {}
    end
  • file addition: 0167-press_next_pane_button (----------)
    [28.2]
    press_next_pane_button = function()
    Show_menu = nil
    Current_pane.car = car
    Current_pane_index = Current_pane_index+1
    Current_pane = Panes[Current_pane_index]
    car = Current_pane.car or {}
    end
  • file addition: 0166-press_load_button (----------)
    [28.2]
    press_load_button = function()
    Show_menu = nil
    Show_file_dialog = true
    File_dialog_callback = function(filename)
    if filename == '' then
    -- clear filename
    Current_pane.filename = nil
    return
    end
    Current_pane.filename = filename
    one_time_load()
    -- Load new filename in future sessions.
    -- On mobile devices, we can't depend on on.save_settings() triggering on quit.
    love.filesystem.write('config', json.encode(settings()))
    end
    end
  • file addition: 0165-press_save_button (----------)
    [28.2]
    press_save_button = function()
    Show_menu = nil
    if Current_pane.filename == nil then
    Show_file_dialog = true
    File_dialog_callback = function(filename)
    if filename == '' then return end
    Current_pane.filename = filename
    one_time_save()
    -- Load new filename in future sessions.
    -- On mobile devices, we can't depend on on.save_settings() triggering on quit.
    love.filesystem.write('config', json.encode(settings()))
    end
    else
    one_time_save()
    end
    end
  • file addition: 0164-press_hide_button (----------)
    [28.2]
    press_hide_button = function()
    Show_menu = nil
    Show_code = false
    end
  • file addition: 0163-press_show_button (----------)
    [28.2]
    press_show_button = function()
    Show_menu = nil
    Show_code = true
    end
  • file addition: 0162-press_stop_button (----------)
    [28.2]
    press_stop_button = function()
    if car.quit then
    call_protected(car.quit)
    end
    Show_menu = nil
    clear_handlers()
    end
  • file addition: 0161-press_run_button (----------)
    [28.2]
    press_run_button = function()
    Show_menu = nil
    -- ## run: initialize
    clear_handlers()
    local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')
    Current_pane.canvas = love.graphics.newCanvas()
    love.graphics.setCanvas(Current_pane.canvas)
    love.graphics.push('all')
    love.graphics.setBackgroundColor(1,1,1)
    edit.clear(Current_pane.output_editor_state)
    print = print_to_output
    -- ## run
    local status, result = live.eval(buf, 'editor')
    -- ## run: save some stuff, clean up the rest
    print = Real_print
    if result then
    -- could be either output or error
    table.insert(Current_pane.output_editor_state.lines, {data=tostring(result)})
    end
    if #Current_pane.output_editor_state.lines == 0 then
    table.insert(Current_pane.output_editor_state.lines, {data=''})
    end
    Text.redraw_all(Current_pane.output_editor_state)
    love.graphics.pop()
    love.graphics.setCanvas()
    end
  • replacement in 0116-save_button at line 2
    [5.2791][5.2791:2849](),[5.2849][5.60:79](),[5.79][5.2866:2906](),[5.105][5.2866:2906](),[5.2866][5.2866:2906](),[5.2964][5.2964:3038](),[5.3038][2.0:39](),[2.39][5.3038:3097](),[5.3038][5.3038:3097](),[5.3097][3.253:446](),[3.446][5.3097:3147](),[5.3097][5.3097:3147]()
    return overflowable_button('save', x, y, r,
    function()
    Show_menu = nil
    if Current_pane.filename == nil then
    Show_file_dialog = true
    File_dialog_callback = function(filename)
    if filename == '' then return end
    Current_pane.filename = filename
    one_time_save()
    -- Load new filename in future sessions.
    -- On mobile devices, we can't depend on on.save_settings() triggering on quit.
    love.filesystem.write('config', json.encode(settings()))
    end
    else
    one_time_save()
    end
    end)
    [5.2791]
    [3.447]
    return overflowable_button('save', x, y, r, press_save_button)
  • replacement in 0106-stop_button at line 2
    [5.1362][5.132:173](),[5.173][5.0:56](),[5.56][5.188:207](),[5.173][5.188:207](),[5.207][5.223:250](),[5.223][5.223:250]()
    styled_button('stop', x,y,
    function()
    if car.quit then
    call_protected(car.quit)
    end
    Show_menu = nil
    clear_handlers()
    end)
    [5.1362]
    [4.760]
    styled_button('stop', x,y, press_stop_button)
  • replacement in 0106-stop_button at line 5
    [5.1469][4.797:801]()
    end
    [5.1469]
    end
  • replacement in 0065-hide_code_button at line 2
    [5.3098][5.918:976](),[5.976][5.472:491](),[5.491][5.5069:5090](),[5.575][5.5069:5090](),[5.976][5.5069:5090](),[5.5069][5.5069:5090](),[5.5090][5.977:984](),[5.984][5.492:496]()
    return overflowable_button('hide', x, y, r,
    function()
    Show_menu = nil
    Show_code = false
    end)
    end
    [5.3098]
    return overflowable_button('hide', x, y, r, press_hide_button)
    end
  • replacement in 0064-show_code_button at line 2
    [5.109][5.985:1043](),[5.1043][5.497:516](),[5.516][5.5508:5528](),[5.626][5.5508:5528](),[5.1043][5.5508:5528](),[5.5508][5.5508:5528](),[5.5528][5.1044:1051](),[5.1051][5.517:521]()
    return overflowable_button('show', x, y, r,
    function()
    Show_menu = nil
    Show_code = true
    end)
    end
    [5.109]
    return overflowable_button('show', x, y, r, press_show_button)
    end
  • edit in 0060-next_pane_button at line 6
    [5.6541][5.6541:6572](),[5.6572][5.547:566](),[5.566][5.1388:1414](),[5.728][5.1388:1414](),[5.6572][5.1388:1414](),[5.1414][5.6572:6661](),[5.6572][5.6572:6661](),[5.6661][5.1415:1447]()
    end,
    onpress1 = function()
    Show_menu = nil
    Current_pane.car = car
    Current_pane_index = Current_pane_index+1
    Current_pane = Panes[Current_pane_index]
    car = Current_pane.car or {}
  • edit in 0060-next_pane_button at line 7
    [5.6668]
    [5.6668]
    onpress1 = press_next_pane_button,
  • replacement in 0060-next_pane_button at line 9
    [5.6672][5.567:571]()
    end
    [5.6672]
    end
  • edit in 0059-previous_pane_button at line 6
    [5.7084][5.7084:7115](),[5.7115][5.572:591](),[5.591][5.1448:1474](),[5.779][5.1448:1474](),[5.7115][5.1448:1474](),[5.1474][5.7115:7204](),[5.7115][5.7115:7204](),[5.7204][5.1475:1507]()
    end,
    onpress1 = function()
    Show_menu = nil
    Current_pane.car = car
    Current_pane_index = Current_pane_index-1
    Current_pane = Panes[Current_pane_index]
    car = Current_pane.car or {}
  • edit in 0059-previous_pane_button at line 7
    [5.7211]
    [5.7211]
    onpress1 = press_previous_pane_button,
  • replacement in 0059-previous_pane_button at line 9
    [5.7215][5.592:596]()
    end
    [5.7215]
    end
  • replacement in 0051-run_button at line 2
    [5.3980][5.764:804](),[5.804][5.597:616](),[5.616][5.329:354](),[5.804][5.329:354](),[5.830][5.329:354](),[5.329][5.329:354](),[5.354][5.1072:1092](),[5.1092][5.354:591](),[5.354][5.354:591](),[5.591][5.0:43](),[5.43][5.1093:1141](),[5.795][5.795:835](),[5.835][5.1142:1193](),[5.1193][5.876:925](),[5.876][5.876:925](),[5.925][5.193:215](),[5.215][5.972:1354](),[5.972][5.972:1354](),[5.1354][5.805:812]()
    styled_button('run', x,y,
    function()
    Show_menu = nil
    -- ## run: initialize
    clear_handlers()
    local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')
    Current_pane.canvas = love.graphics.newCanvas()
    love.graphics.setCanvas(Current_pane.canvas)
    love.graphics.push('all')
    love.graphics.setBackgroundColor(1,1,1)
    edit.clear(Current_pane.output_editor_state)
    print = print_to_output
    -- ## run
    local status, result = live.eval(buf, 'editor')
    -- ## run: save some stuff, clean up the rest
    print = Real_print
    if result then
    -- could be either output or error
    table.insert(Current_pane.output_editor_state.lines, {data=tostring(result)})
    end
    if #Current_pane.output_editor_state.lines == 0 then
    table.insert(Current_pane.output_editor_state.lines, {data=''})
    end
    Text.redraw_all(Current_pane.output_editor_state)
    love.graphics.pop()
    love.graphics.setCanvas()
    end)
    [5.3980]
    [4.981]
    styled_button('run', x,y, press_run_button)
  • replacement in 0051-run_button at line 5
    [5.4086][4.1017:1021]()
    end
    [5.4086]
    end
  • edit in 0013-on.keychord_press at line 12
    [5.2244]
    [5.2669]
    elseif not Show_code and chord == 'f3' then
    press_show_button()
  • replacement in 0013-on.keychord_press at line 15
    [5.2692][5.2692:2737]()
    if Current_pane.editor_state.cursor_x then
    [5.2692]
    [5.2737]
    if chord == 'C-left' then press_previous_pane_button()
    elseif chord == 'C-right' then press_next_pane_button()
    elseif chord == 'f1' then press_run_button()
    elseif chord == 'f2' then press_stop_button()
    elseif chord == 'f3' then press_hide_button()
    elseif chord == 'f4' then press_save_button()
    elseif chord == 'f5' then press_load_button()
    elseif Current_pane.editor_state.cursor_x then