add keyboard shortcuts for common operations
This commit is contained in:
parent
e81d371d87
commit
56268f09a4
|
@ -9,8 +9,17 @@ on.keychord_press = function(chord, key)
|
|||
update_font_settings(Current_pane.editor_state.font_height-2)
|
||||
elseif chord == 'C-0' then
|
||||
update_font_settings(20)
|
||||
elseif not Show_code and chord == 'f3' then
|
||||
press_show_button()
|
||||
elseif Show_code then
|
||||
if Current_pane.editor_state.cursor_x then
|
||||
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
|
||||
-- send keys to editor if cursor is visible
|
||||
edit.keychord_press(Current_pane.editor_state, chord, key)
|
||||
end
|
||||
|
|
|
@ -1,31 +1,5 @@
|
|||
run_button = function(x, y)
|
||||
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)
|
||||
styled_button('run', x,y, press_run_button)
|
||||
local w = Font:getWidth('run')+10
|
||||
return x+w+10, y
|
||||
end
|
||||
end
|
|
@ -4,12 +4,6 @@ previous_pane_button = function()
|
|||
App.color{r=0.4,g=0.4,b=0.4}
|
||||
love.graphics.polygon('fill', Menu_left+5, App.screen.height/2, Menu_left+25, App.screen.height/2-10, Menu_left+25, App.screen.height/2+10)
|
||||
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 {}
|
||||
end,
|
||||
onpress1 = press_previous_pane_button,
|
||||
})
|
||||
end
|
||||
end
|
|
@ -4,12 +4,6 @@ next_pane_button = function(r)
|
|||
App.color{r=0.4,g=0.4,b=0.4}
|
||||
love.graphics.polygon('fill', r-25, App.screen.height/2-10, r-25, App.screen.height/2+10, r-5, App.screen.height/2)
|
||||
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 {}
|
||||
end,
|
||||
onpress1 = press_next_pane_button,
|
||||
})
|
||||
end
|
||||
end
|
|
@ -1,7 +1,3 @@
|
|||
show_code_button = function(x, y, r)
|
||||
return overflowable_button('show', x, y, r,
|
||||
function()
|
||||
Show_menu = nil
|
||||
Show_code = true
|
||||
end)
|
||||
end
|
||||
return overflowable_button('show', x, y, r, press_show_button)
|
||||
end
|
|
@ -1,7 +1,3 @@
|
|||
hide_code_button = function(x, y, r)
|
||||
return overflowable_button('hide', x, y, r,
|
||||
function()
|
||||
Show_menu = nil
|
||||
Show_code = false
|
||||
end)
|
||||
end
|
||||
return overflowable_button('hide', x, y, r, press_hide_button)
|
||||
end
|
|
@ -1,12 +1,5 @@
|
|||
stop_button = function(x, y)
|
||||
styled_button('stop', x,y,
|
||||
function()
|
||||
if car.quit then
|
||||
call_protected(car.quit)
|
||||
end
|
||||
Show_menu = nil
|
||||
clear_handlers()
|
||||
end)
|
||||
styled_button('stop', x,y, press_stop_button)
|
||||
local w = Font:getWidth('stop')+10
|
||||
return x+w+10, y
|
||||
end
|
||||
end
|
|
@ -1,19 +1,3 @@
|
|||
save_button = function(x, y, r)
|
||||
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)
|
||||
return overflowable_button('save', x, y, r, press_save_button)
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
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
|
|
@ -0,0 +1,7 @@
|
|||
press_stop_button = function()
|
||||
if car.quit then
|
||||
call_protected(car.quit)
|
||||
end
|
||||
Show_menu = nil
|
||||
clear_handlers()
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
press_show_button = function()
|
||||
Show_menu = nil
|
||||
Show_code = true
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
press_hide_button = function()
|
||||
Show_menu = nil
|
||||
Show_code = false
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
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
|
|
@ -0,0 +1,16 @@
|
|||
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
|
|
@ -0,0 +1,7 @@
|
|||
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
|
|
@ -0,0 +1,7 @@
|
|||
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
|
Loading…
Reference in New Issue