-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.lua
162 lines (126 loc) · 3.19 KB
/
app.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
platform.apiLevel = '2.4'
-- luacheck: ignore class
-- luacheck: ignore platform
-- luacheck: ignore on
local advice = require 'advice'
local ui = require 'ui'
local config = require 'config.config'
require 'views.menu'
require 'views.edit'
require 'views.label'
require 'views.container'
require 'views.list'
require 'views.richedit'
require 'tableext'
require 'stringext'
local dlg_error = require 'dialog.error'
local rpn_controller = require 'rpn.controller'
local function draw_logo(gc, frame)
local center = frame:center()
gc:set_font(nil, "b", 80)
gc:draw_text("rpn", 0, 0, frame.width/2, frame.height, 1, 0)
gc:set_font(nil, "bi", 80)
gc:draw_text("spire", frame.width/2, 0, frame.width/2, frame.height, -1, 0)
end
local function build_main_view()
local edit_height = 20
local main_view = ui.container(ui.rel({ top = 0, bottom = 0, left = 0, right = 0 }))
main_view.style = 'none'
local edit = ui.edit(ui.rel { left = 0, right = 0, bottom = 0, height = edit_height })
main_view:add_child(edit)
local list = ui.list(ui.rel({ top = 0, bottom = edit_height, left = 0, right = 0 }))
if config.enable_splash then
list.draw_self = advice.after(list.draw_self, function(self, gc, dirty)
if not self.items or #self.items == 0 then
draw_logo(gc, self:frame())
end
end)
end
main_view:add_child(list)
local controller = rpn_controller.new(main_view, edit, list)
return main_view, controller
end
function on.construction()
-- luacheck: ignore toolpalette
toolpalette.enableCopy(true)
toolpalette.enableCut(true)
toolpalette.enablePaste(true)
local root = ui.push_modal()
local main_view, main_controller = build_main_view()
root.main = main_view
main_controller:initialize()
ui.set_focus(main_controller.edit)
end
function on.resize(w, h)
ui.resize(w, h)
end
function on.mouseDown(x, y)
ui.on_event('mouse_down', x, y)
end
function on.rightMouseDown(x, y)
ui.on_event('rmouse_down', x, y)
end
function on.escapeKey()
ui.on_event('escape')
end
function on.tabKey()
ui.on_event('tab')
end
function on.backtabKey()
ui.on_event('backtab')
end
function on.returnKey()
ui.on_event('return')
end
function on.arrowRight()
ui.on_event('right')
end
function on.arrowLeft()
ui.on_event('left')
end
function on.arrowUp()
ui.on_event('up')
end
function on.arrowDown()
ui.on_event('down')
end
function on.charIn(c)
ui.on_event('char', c)
end
function on.enterKey()
ui.on_event('enter_key')
end
function on.backspaceKey()
ui.on_event('backspace')
end
function on.clearKey()
ui.on_event('clear')
end
function on.contextMenuKey()
ui.on_event('ctx')
end
function on.contextMenu()
ui.on_event('ctx')
end
function on.help()
ui.on_event('help')
end
function on.cut()
ui.on_event('cut')
end
function on.copy()
ui.on_event('copy')
end
function on.paste()
ui.on_event('paste')
end
function on.paint(gc)
ui.paint(ui.GC(gc, 0, 0))
end
if platform.registerErrorHandler then
platform.registerErrorHandler(function(line, msg)
print(string.format('ERROR (line %d) %s', line or 0, msg or ''))
dlg_error.display('Internal Error', msg)
return true
end)
end