Skip to content

Commit 1a59663

Browse files
committed
feat: add switcher configuration
1 parent 4372b75 commit 1a59663

File tree

2 files changed

+148
-6
lines changed

2 files changed

+148
-6
lines changed

Lib/RabbitTrayMenu.ahk

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ SetupTrayMenu() {
3232
static rabbit_ico := Format("{}\Lib\rabbit.ico", A_ScriptDir)
3333
A_TrayMenu.Delete()
3434
if !IN_MAINTENANCE {
35-
; A_TrayMenu.Add("输入法设定")
35+
A_TrayMenu.Add("输入法设定", (*) => Configure())
3636
; A_TrayMenu.Add("用户词典管理")
3737
A_TrayMenu.Add("用户资料同步", (*) => Sync())
3838

@@ -69,6 +69,10 @@ SetupTrayMenu() {
6969
A_TrayMenu.Add("退出玉兔毫", (*) => ExitApp())
7070
}
7171

72+
Configure() {
73+
Run(Format("{} `"{}\RabbitDeployer.ahk`" configure 1", A_AhkPath, A_ScriptDir))
74+
ExitApp()
75+
}
7276
Sync() {
7377
Run(Format("{} `"{}\RabbitDeployer.ahk`" sync 1", A_AhkPath, A_ScriptDir))
7478
ExitApp()

RabbitDeployer.ahk

+143-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ RunDeployer(args) {
5656
opt := RABBIT_PARTIAL_MAINTENANCE
5757
default:
5858
res := conf.Run(command = "install")
59-
opt := RABBIT_PARTIAL_MAINTENANCE ; TODO: check if need maintenance
59+
opt := RABBIT_NO_MAINTENANCE
6060
}
6161

6262
if args.Length > 1 {
@@ -79,10 +79,25 @@ CreateFileIfNotExist(filename) {
7979
FileAppend("", filepath)
8080
}
8181

82-
ConfigureSwitcher(levers, switcher_settings, reconfigured) {
82+
ConfigureSwitcher(levers, switcher_settings, &reconfigured) {
83+
if !IsSet(reconfigured)
84+
reconfigured := false
8385
if not levers.load_settings(switcher_settings)
8486
return false
85-
;
87+
; To mimic a dialog
88+
result := {
89+
yes : false
90+
}
91+
dialog := SwitcherSettingsDialog(switcher_settings, result)
92+
dialog.Show()
93+
WinWaitClose(dialog)
94+
95+
if result.yes {
96+
if levers.save_settings(switcher_settings)
97+
reconfigured := true
98+
return true
99+
}
100+
return false
86101
}
87102

88103
class Configurator extends Class {
@@ -105,8 +120,14 @@ class Configurator extends Class {
105120
switcher_settings := levers.switcher_settings_init()
106121
skip_switcher_settings := installing && !levers.is_first_run(switcher_settings)
107122

108-
if installing
109-
this.UpdateWorkspace()
123+
if !skip_switcher_settings {
124+
ConfigureSwitcher(levers, switcher_settings, &reconfigured)
125+
}
126+
127+
levers.custom_settings_destroy(switcher_settings)
128+
129+
if installing || reconfigured
130+
return this.UpdateWorkspace()
110131

111132
return 0
112133
}
@@ -150,3 +171,120 @@ class Configurator extends Class {
150171
return 0
151172
}
152173
}
174+
175+
class SwitcherSettingsDialog extends Gui {
176+
__New(settings, result) {
177+
super.__New(, "【玉兔毫】方案选单设定", this)
178+
this.settings := settings
179+
this.loaded := false
180+
this.modified := false
181+
this.api := RimeLeversApi()
182+
183+
this.item_data := Map()
184+
this.result := result
185+
186+
; Layout
187+
this.MarginX := 15
188+
this.MarginY := 15
189+
this.AddText(, "请勾选所需的输入方案:")
190+
this.schema_list := this.AddListView("Section Checked NoSort w220 h175", ["方案名称"])
191+
this.schema_list.OnEvent("Click", (ctrl, lvid) => this.OnSchemaListClick(lvid))
192+
this.schema_list.OnEvent("ItemCheck", (ctrl, lvid, checked) => this.OnSchemaListItemCheck(lvid, checked))
193+
this.description := this.AddText("YP w285 h175", "选中列表中的输入方案以查看简介")
194+
this.AddText("XS", "在玉兔毫里,以下快捷键可唤出方案选单,以切换模式或选用其他输入方案。")
195+
this.hotkeys := this.AddEdit("-Multi ReadOnly r1 w505")
196+
this.more_schemas := this.AddButton("Disabled w155", "获取更多输入方案…")
197+
this.ok := this.AddButton("X+60 YP w90", "")
198+
this.ok.OnEvent("Click", (*) => this.OnOK())
199+
200+
this.Populate()
201+
}
202+
203+
Populate() {
204+
if !this.settings
205+
return
206+
local available := this.api.get_available_schema_list(this.settings)
207+
local selected := this.api.get_selected_schema_list(this.settings)
208+
this.schema_list.Delete()
209+
210+
local recruited := Map()
211+
212+
local selected_list := selected.list
213+
local available_list := available.list
214+
Loop selected.size {
215+
local schema_id := selected_list[A_Index].schema_id
216+
Loop available.size {
217+
item := available_list[A_Index]
218+
info := RimeSchemaInfo(item)
219+
if item.schema_id == schema_id && (!recruited.Has(info.Ptr) || recruited[info.Ptr] == false) {
220+
recruited[info.Ptr] := true
221+
row := this.schema_list.Add("Check", item.name)
222+
this.item_data[row] := info
223+
break
224+
}
225+
}
226+
}
227+
Loop available.size {
228+
item := available_list[A_Index]
229+
info := RimeSchemaInfo(item)
230+
if !recruited.Has(info.Ptr) || recruited[info.Ptr] == false {
231+
recruited[info.Ptr] := true
232+
row := this.schema_list.Add(, item.name)
233+
this.item_data[row] := info
234+
}
235+
}
236+
txt := this.api.get_hotkeys(this.settings)
237+
this.hotkeys.Value := txt
238+
this.loaded := true
239+
this.modified := false
240+
}
241+
242+
OnSchemaListClick(lvid) {
243+
if !this.loaded || !this.schema_list || lvid <= 0 || lvid > this.schema_list.GetCount() {
244+
return
245+
}
246+
this.ShowDetails(this.item_data[lvid])
247+
}
248+
249+
OnSchemaListItemCheck(lvid, checked) {
250+
if !this.loaded || !this.schema_list || lvid <= 0 || lvid > this.schema_list.GetCount() {
251+
return
252+
}
253+
this.modified := true
254+
}
255+
256+
ShowDetails(info) {
257+
if !info
258+
return
259+
details := ""
260+
if name := this.api.get_schema_name(info)
261+
details .= name
262+
if author := this.api.get_schema_author(info)
263+
details .= "`r`n`r`n" . author
264+
if description := this.api.get_schema_description(info)
265+
details .= "`r`n`r`n" . description
266+
this.description.Value := details
267+
}
268+
269+
OnOK() {
270+
if this.modified && !!this.settings && this.schema_list.GetCount() != 0 {
271+
selection := []
272+
row := 0
273+
while row := this.schema_list.GetNext(row, "Checked") {
274+
if info := this.item_data[row]
275+
selection.Push(this.api.get_schema_id(info))
276+
}
277+
if selection.Length == 0 {
278+
MsgBox("至少要选用一项吧。", "玉兔毫不是这般用法", "Icon!")
279+
return
280+
}
281+
this.api.select_schemas(this.settings, selection)
282+
}
283+
this.Exit(true)
284+
}
285+
286+
Exit(yes) {
287+
this.result.yes := yes
288+
this.Destroy()
289+
}
290+
}

0 commit comments

Comments
 (0)