forked from xomachine/TASC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.lua
187 lines (174 loc) · 4.52 KB
/
gui.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
--------------------
-- GUI modification
--------------------
local _M = {}
local backend = require("textadept-spellchecker.backend")
local check = require("textadept-spellchecker.check")
local live = require("textadept-spellchecker.livechecking")
local config = require("textadept-spellchecker.config")
------------------------
-- On/Off spellchecking
------------------------
local on_off_msgs = {
[config.OFF] = _L["_SCON"],
[config.ON] = _L["_SCOFF"],
}
local on_off_live_msgs = {
[config.OFF] = _L["_LSCON"],
[config.ON] = _L["_LSCOFF"],
}
local function renew()
backend.kill_checker()
check.frame()
config:save()
end
local function toggle_spellchecking(current_check_state, fixed_live_state)
if current_check_state == config.ON then
current_check_state = config.OFF
check.shutdown()
live.shutdown()
else
current_check_state = config.ON
check.connect_events()
if fixed_live_state == config.ON then
live.init()
end
end
-- Changing messages and status in menu
textadept.menu.menubar[#textadept.menu.menubar-1][1][1] = on_off_msgs[current_check_state]
textadept.menu.menubar[#textadept.menu.menubar-1][2][1] = on_off_live_msgs[fixed_live_state]
config.checking = current_check_state
config.live = fixed_live_state
config:save()
end
local function toggle_live_spellchecking(current_live_state)
if current_live_state == config.ON then
current_live_state = config.OFF
live.shutdown()
else
current_live_state = config.ON
live.init()
end
-- Changing messages and status in menu
textadept.menu.menubar[#textadept.menu.menubar-1][2][1] = on_off_live_msgs[current_live_state]
config.live = current_live_state
config:save()
end
---------------------
-- Backend selection
---------------------
local function new_backend()
local input_box = {
title = _L["ENTER_SC_BACKEND"],
informative_text = _L["ENTER_SC_BACKEND_INFO"],
button2 = _L["_Cancel"],
float = true,
}
local status, command = ui.dialogs.inputbox(input_box)
if status == 1 then
if backend.check_backend(command) then
table.insert(backend.AVAILABLE_CHECKERS, command)
return command
else
ui.dialogs.ok_msgbox({
title = _L["PROBLEM"],
text = string.format(_L["NOT_BACKEND"], command),
no_cancel = true
})
end
end
return nil
end
local function backend_selector()
local backend_select_dialog = {
title = _L["SELECT_BACKEND"],
text = _L["SELECT_BACKEND_INFO"],
float = true,
button2 = _L["_Cancel"],
button3 = _L["_NOTINLIST"],
items = backend.AVAILABLE_CHECKERS,
select = config.CURRENT_CHECKER
}
local status = 0
local status, checker = ui.dialogs.dropdown(backend_select_dialog)
if status == 2 then
checker = nil
elseif status == 3 then
checker = new_backend()
end
if checker and checker ~= config.CURRENT_CHECKER then
config.CURRENT_CHECKER = checker or config.CURRENT_CHECKER
renew()
end
end
------------------------
-- Dictionary selection
------------------------
local function dictionary_selector()
local input_box = {
title = _L["ENTER_DICT"],
informative_text = _L["ENTER_DICT_INFO"],
button2 = _L["_Cancel"],
float = true,
text = config.dicts,
}
local status, dict = ui.dialogs.inputbox(input_box)
if status == 1 then
local status = backend.check_dict(dict)
if status == true then
config.dicts = dict
renew()
else
ui.dialogs.ok_msgbox({
title = _L["PROBLEM"],
text = string.format(_L["NOT_DICT"], dict, backend.AVAILABLE_CHECKERS[config.CURRENT_CHECKER]),
no_cancel = true
})
end
end
end
-------------
-- Root menu
-------------
function _M.init()
local spellcheck_menu = {
title = _L["S_PELLCHECK"],
{
on_off_msgs[config.checking or config.ON],
function() toggle_spellchecking(config.checking or config.ON, config.live or config.OFF) end
},
{
on_off_live_msgs[config.live or config.OFF],
function() toggle_live_spellchecking(config.live or config.OFF) end
},
{""},
{
_L["_CHECKFRAME"],
check.frame
},
{
_L["_CHECKFILE"],
check.file
},
{""},
{
_L["_CLEARCURRENT"],
function() check.clear(buffer) end
},
{
_L["_CLEARALL"],
check.clear_all
},
{""},
{
_L["_BACKENDSELECT"],
backend_selector
},
{
_L["_DICTSELECT"],
dictionary_selector
},
}
table.insert(textadept.menu.menubar, #textadept.menu.menubar, spellcheck_menu)
end
return _M