indent
[lines.love.git] / commands.lua
blob1bc2b0d8f4c785c3758e93d5cf5f04544e8c4bda
1 Menu_background_color = {r=0.6, g=0.8, b=0.6}
2 Menu_border_color = {r=0.6, g=0.7, b=0.6}
3 Menu_command_color = {r=0.2, g=0.2, b=0.2}
4 Menu_highlight_color = {r=0.5, g=0.7, b=0.3}
6 function source.draw_menu_bar()
7 if App.run_tests then return end -- disable in tests
8 App.color(Menu_background_color)
9 love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_status_bar_height)
10 App.color(Menu_border_color)
11 love.graphics.rectangle('line', 0,0, App.screen.width, Menu_status_bar_height)
12 App.color(Menu_command_color)
13 Menu_cursor = 5
14 if Show_file_navigator then
15 source.draw_file_navigator()
16 return
17 end
18 add_hotkey_to_menu('ctrl+e: run')
19 if Focus == 'edit' then
20 add_hotkey_to_menu('ctrl+g: switch file')
21 if Show_log_browser_side then
22 add_hotkey_to_menu('ctrl+l: hide log browser')
23 else
24 add_hotkey_to_menu('ctrl+l: show log browser')
25 end
26 if Editor_state.expanded then
27 add_hotkey_to_menu('alt+b: collapse debug prints')
28 else
29 add_hotkey_to_menu('alt+b: expand debug prints')
30 end
31 add_hotkey_to_menu('alt+d: create/edit debug print')
32 add_hotkey_to_menu('ctrl+f: find in file')
33 add_hotkey_to_menu('alt+left alt+right: prev/next word')
34 elseif Focus == 'log_browser' then
35 -- nothing yet
36 else
37 assert(false, 'unknown focus "'..Focus..'"')
38 end
39 add_hotkey_to_menu('ctrl+z ctrl+y: undo/redo')
40 add_hotkey_to_menu('ctrl+x ctrl+c ctrl+v: cut/copy/paste')
41 add_hotkey_to_menu('ctrl+= ctrl+- ctrl+0: zoom')
42 end
44 function add_hotkey_to_menu(s)
45 local s_text = to_text(s)
46 local width = App.width(s_text)
47 if Menu_cursor + width > App.screen.width - 5 then
48 return
49 end
50 App.color(Menu_command_color)
51 App.screen.draw(s_text, Menu_cursor,5)
52 Menu_cursor = Menu_cursor + width + 30
53 end
55 function source.draw_file_navigator()
56 if File_navigation.num_lines == nil then
57 File_navigation.num_lines = source.num_lines_for_file_navigator()
58 end
59 App.color(Menu_background_color)
60 love.graphics.rectangle('fill', 0,Menu_status_bar_height, App.screen.width, File_navigation.num_lines * Editor_state.line_height)
61 local x,y = 5, Menu_status_bar_height
62 for i,filename in ipairs(File_navigation.candidates) do
63 if filename == 'source' then
64 App.color(Menu_border_color)
65 love.graphics.line(Menu_cursor-10,2, Menu_cursor-10,Menu_status_bar_height-2)
66 end
67 x,y = add_file_to_menu(x,y, filename, i == File_navigation.index)
68 if Menu_cursor >= App.screen.width - 5 then
69 break
70 end
71 end
72 end
74 function source.num_lines_for_file_navigator()
75 local result = 1
76 local x = 5
77 for i,filename in ipairs(File_navigation.candidates) do
78 local width = App.width(to_text(filename))
79 if x + width > App.screen.width - 5 then
80 result = result+1
81 x = 5 + width
82 else
83 x = x + width + 30
84 end
85 end
86 return result
87 end
89 function add_file_to_menu(x,y, s, cursor_highlight)
90 local s_text = to_text(s)
91 local width = App.width(s_text)
92 if x + width > App.screen.width - 5 then
93 y = y + Editor_state.line_height
94 x = 5
95 end
96 if cursor_highlight then
97 App.color(Menu_highlight_color)
98 love.graphics.rectangle('fill', x-5,y-2, width+5*2,Editor_state.line_height+2*2)
99 end
100 App.color(Menu_command_color)
101 App.screen.draw(s_text, x,y)
102 x = x + width + 30
103 return x,y
106 function keychord_pressed_on_file_navigator(chord, key)
107 if chord == 'escape' then
108 Show_file_navigator = false
109 elseif chord == 'return' then
110 local candidate = guess_source(File_navigation.candidates[File_navigation.index]..'.lua')
111 source.switch_to_file(candidate)
112 Show_file_navigator = false
113 elseif chord == 'left' then
114 if File_navigation.index > 1 then
115 File_navigation.index = File_navigation.index-1
117 elseif chord == 'right' then
118 if File_navigation.index < #File_navigation.candidates then
119 File_navigation.index = File_navigation.index+1