Skip to content

Commit 5f0d47e

Browse files
committed
Merge pull request #113 from rcmdnk/keyremap
Introduce tabs in settings window
2 parents 109eadc + d9751b2 commit 5f0d47e

14 files changed

+171
-50
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,19 @@ or launch the setting window by `Ctrl-Alt-Shift-v`.
199199

200200
![traymenu](https://raw.githubusercontent.com/rcmdnk/vim_ahk/master/pictures/traymenu.jpg "traymenu")
201201

202-
![settings](https://raw.githubusercontent.com/rcmdnk/vim_ahk/master/pictures/settings.jpg "settings")
202+
![settings_keys](https://raw.githubusercontent.com/rcmdnk/vim_ahk/master/pictures/settings_keys.png "settings_keys")
203+
![settings_applications](https://raw.githubusercontent.com/rcmdnk/vim_ahk/master/pictures/settings_applications.png "settings_applications")
204+
![settings_status](https://raw.githubusercontent.com/rcmdnk/vim_ahk/master/pictures/settings_status.png "settings_status")
205+
![settings_configuration](https://raw.githubusercontent.com/rcmdnk/vim_ahk/master/pictures/settings_configuration.png "settings_configuration")
203206

204-
Here, you can add applications, change the mode change key,
205-
or change the verbose level.
207+
Here, you can add applications, change the mode change key, change the verbose level,
208+
or import/export the configuration file.
209+
210+
If you import a configuration file, these settings will be enabled
211+
only if you push the `Apply` or `OK` button.
206212

207213
If you push `Reset`, default settings will be shown in the window.
208-
These settings will be enabled only if you push the `OK` button.
214+
These settings will be enabled only if you push the `Apply` or `OK` button, too.
209215

210216
These **default settings** are overwritten by
211217
your `VimXXX` options in your script described above.

lib/vim_ahk.ahk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ class VimAhk{
138138
, "1: Nothing `n2: Minimum tooltip (mode information only)`n3: Tooltip (all information)`n4: Debug mode with a message box, which doesn't disappear automatically")
139139
this.AddToConf("VimAppList", "Allow List", "Allow List"
140140
, "Application list usage"
141-
, "All: Enable on all application (the application list is ignored) `nAllow List: Use the application list as an allow list`nDeny List: Use the application list as a deny list")
141+
, "All: Enable on all applications (the application list is ignored) `nAllow List: Use the application list as an allow list`nDeny List: Use the application list as a deny list")
142142
this.AddToConf("VimGroup", DefaultGroup, DefaultGroup
143-
, "Application"
143+
, "Application list"
144144
, "Set one application per line.`n`nIt can be any of Window Title, Class or Process.`nYou can check these values by Window Spy (in the right click menu of tray icon).")
145145

146146
this.CheckBoxes := ["VimEscNormal", "VimSendEscNormal", "VimLongEscNormal", "VimCtrlBracketToEsc", "VimCtrlBracketNormal", "VimSendCtrlBracketNormal", "VimLongCtrlBracketNormal", "VimRestoreIME", "VimJJ", "VimChangeCaretWidth"]

lib/vim_check.ahk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
this.Vim := Vim
44
}
55

6-
CheckMenu(ItemName, ItemPos, MyMenu) {
6+
CheckMenu(ItemName:="", ItemPos:="", MyMenu:="") {
77
; Additional message is necessary before checking current window.
88
; Otherwise process name cannot be retrieved...?
99
MsgBox("Checking current window...", "Vim Ahk")

lib/vim_gui.ahk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class VimGui{
3131
UpdateGui(){
3232
}
3333

34-
ShowGui(ItemName, ItemPos, MyMenu){
34+
ShowGui(ItemName:="", ItemPos:="", MyMenu:=""){
3535
if(this.Obj == 0){
3636
this.Obj := Gui("", this.Title)
3737
this.MakeGui()

lib/vim_ini.ahk

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
this.IniDir := Dir
1818
this.Ini := Dir "\" Ini
1919
this.section := Section
20+
21+
this.OpenIniDirObj := ObjBindMethod(this, "OpenIniDir")
22+
this.OpenIniObj := ObjBindMethod(this, "OpenIni")
2023
}
2124

22-
ReadIni(Conf:=""){
23-
if (Conf == ""){
24-
Conf := this.Vim.Conf
25-
}
26-
for k, v in Conf {
25+
ReadIni(){
26+
for k, v in this.Vim.Conf {
2727
Current := v["val"]
2828
if(Current != ""){
2929
val := IniRead(this.Ini, this.Section, k, Current)
@@ -68,4 +68,14 @@
6868
IniWrite(v["val"], this.Ini, this.Section, k)
6969
}
7070
}
71+
72+
OpenIniDir(Obj, Info){
73+
this.Vim.VimToolTip.RemoveToolTip()
74+
Run("explorer.exe " this.IniDir)
75+
}
76+
77+
OpenIni(Obj, Info){
78+
this.Vim.VimToolTip.RemoveToolTip()
79+
Run("notepad.exe " this.Ini)
80+
}
7181
}

lib/vim_move.ahk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
this.Zero()
2828
this.ShiftDown()
2929
this.Up()
30-
this.vim.state.setmode("Vim_VisualLine")
30+
this.Vim.state.setmode("Vim_VisualLine")
3131
}
3232

3333
if(this.Vim.State.IsCurrentVimMode("Vim_VisualLineFirst")) and (Key == "j" or Key == "^d" or Key == "^f" or Key == "+g"){
34-
this.vim.state.setmode("Vim_VisualLine")
34+
this.Vim.state.setmode("Vim_VisualLine")
3535
}
3636

3737
if(this.Vim.State.StrIsInCurrentVimMode("Vim_ydc")) and (Key == "k" or Key == "^u" or Key == "^b" or Key == "g"){

lib/vim_setting.ahk

Lines changed: 139 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class VimSetting Extends VimGui{
77

88
this.ResetObj := ObjBindMethod(this, "Reset")
99
this.CancelObj := ObjBindMethod(this, "Cancel")
10+
this.ApplyObj := ObjBindMethod(this, "Apply")
11+
this.ImportObj := ObjBindMethod(this, "ImportIni")
12+
this.ExportObj := ObjBindMethod(this, "ExportIni")
1013
}
1114

1215
AddConf(ControlType, Key, Options, Text:="", V:=False){
@@ -25,65 +28,91 @@ class VimSetting Extends VimGui{
2528
}
2629

2730
MakeGui(){
28-
this.Obj.Opt("-MinimizeBox -Resize")
29-
created := 0
31+
this.Obj.Opt("-Resize -MinimizeBox -MaximizeBox")
32+
this.Tab := this.Obj.Add("Tab3", "X+0 Y+0 W480 H360", ["Keys", "Applications", "Status", "Configuration file"])
33+
34+
; Tab 1: Keys
35+
this.Tab.UseTab(1)
36+
this.Obj.AddText("X+0 Y+0 Section", "")
3037
for i, k in this.Vim.Checkboxes {
31-
if(created == 0){
32-
y := "YM"
33-
created := 1
34-
}else{
35-
y := "Y+10"
36-
}
37-
if(inStr(k, "Long") or inStr(k, "Send")) {
38-
x := "30"
39-
}else{
40-
x := "10"
41-
}
42-
this.AddConf("Checkbox", k, "XM+" x " " y, this.Vim.GetDescription(k), True)
38+
x := (inStr(k, "Long") or inStr(k, "Send")) ? "30" : "10"
39+
this.AddConf("Checkbox", k, "XS+" x " Y+6", this.Vim.GetDescription(k), True)
4340
this.Obj[k].Value := this.Vim.GetVal(k)
4441
}
45-
this.AddConf("Text", "VimTwoLetter", "XM+10 Y+15")
46-
this.AddConf("Edit", "VimTwoLetter", "XM+10 Y+5 R4 W100 Multi", StrReplace(this.Vim.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1), True)
47-
this.AddConf("Text", "VimDisableUnused", "XM+10 Y+15")
48-
this.AddConf("DDL", "VimDisableUnused", "X+5 Y+-16 W30 Choose" this.Vim.GetVal("VimDisableUnused"), [1, 2, 3], True)
49-
this.AddConf("Text", "VimSetTitleMatchMode", "XM+10 Y+15")
42+
this.AddConf("Text", "VimTwoLetter", "XS+10 Y+15")
43+
this.AddConf("Edit", "VimTwoLetter", "XS+10 Y+5 R4 W100 Multi", StrReplace(this.Vim.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1), True)
44+
this.AddConf("Text", "VimDisableUnused", "XS+10 Y+15")
45+
this.AddConf("DDL", "VimDisableUnused", "X+5 YP-4 W40 Choose" this.Vim.GetVal("VimDisableUnused"), [1, 2, 3], True)
46+
47+
; Tab 2: Applications (Merged with Matching & Lists)
48+
this.Tab.UseTab(2)
49+
this.Obj.AddText("X+0 Y+0 Section", "")
50+
; (Disabled unused keys moved to Keys tab)
51+
this.AddConf("Text", "VimSetTitleMatchMode", "XS+10 Y+10")
5052
if(this.Vim.GetVal("VimSetTitleMatchMode") == "RegEx"){
5153
matchmode := 4
5254
}else{
5355
matchmode := this.Vim.GetVal("VimSetTitleMatchMode")
5456
}
55-
this.AddConf("DDL","VimSetTitleMatchMode", "X+5 Y+-16 W60 Choose" matchmode, [1, 2, 3, "RegEx"], True)
57+
this.AddConf("DDL","VimSetTitleMatchMode", "X+5 YP-4 W60 Choose" matchmode, [1, 2, 3, "RegEx"], True)
5658
if(this.Vim.GetVal("VimSetTitleMatchModeFS") == "Fast"){
5759
matchmodefs := 1
5860
}else{
5961
matchmodefs := 2
6062
}
61-
this.AddConf("DDL", "VimSetTitleMatchModeFS", "X+5 Y+-20 W50 Choose" matchmodefs, ["Fast", "Slow"], True)
62-
this.AddConf("Text", "VimIconCheckInterval", "XM+10 Y+10")
63-
this.AddConf("Edit", "VimIconCheckInterval", "X+5 Y+-16 W70")
64-
this.AddConf("UpDown", "VimIconCheckInterval", "Range0-1000000", this.Vim.GetVal("VimIconCheckInterval"), True)
65-
this.AddConf("Text", "VimVerbose", "XM+10 Y+10")
66-
this.AddConf("DDL", "VimVerbose", "X+5 Y+-16 W30 Choose" this.Vim.GetVal("VimVerbose"), [1, 2, 3, 4], True)
67-
this.AddConf("Text", "VimAppList", "XM+10 Y+10")
63+
this.AddConf("DDL", "VimSetTitleMatchModeFS", "X+5 YP+0 W50 Choose" matchmodefs, ["Fast", "Slow"], True)
64+
65+
; Applications specific
66+
this.AddConf("Text", "VimAppList", "XS+10 Y+15")
6867
if(this.Vim.GetVal("VimAppList") == "All"){
6968
matchapplist := 1
7069
}else if(this.Vim.GetVal("VimAppList") == "Allow List"){
7170
matchapplist := 2
7271
}else{
7372
matchapplist := 3
7473
}
75-
this.AddConf("DDL", "VimAppList", "X+5 Y+-16 W100 Choose" matchapplist, ["All", "Allow List", "Deny List"], True)
76-
this.AddConf("Text", "VimGroup", "XM+10 Y+5")
77-
this.AddConf("Edit", "VimGroup", "XM+10 Y+5 R10 W300 Multi", StrReplace(this.Vim.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1), True)
78-
this.Obj.AddText("XM+10 Y+10", "Check")
74+
this.AddConf("DDL", "VimAppList", "X+5 YP-4 W100 Choose" matchapplist, ["All", "Allow List", "Deny List"], True)
75+
this.AddConf("Text", "VimGroup", "XS+10 Y+5")
76+
this.AddConf("Edit", "VimGroup", "XS+10 Y+5 R10 W300 Multi", StrReplace(this.Vim.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1), True)
77+
78+
; Tab 3: Status
79+
this.Tab.UseTab(3)
80+
this.Obj.AddText("X+0 Y+0 Section", "")
81+
this.AddConf("Text", "VimIconCheckInterval", "XS+10 Y+10")
82+
this.AddConf("Edit", "VimIconCheckInterval", "X+5 YP-4 W70")
83+
this.AddConf("UpDown", "VimIconCheckInterval", "Range0-1000000", this.Vim.GetVal("VimIconCheckInterval"), True)
84+
this.AddConf("Text", "VimVerbose", "XS+10 Y+10")
85+
this.AddConf("DDL", "VimVerbose", "X+5 YP-4 W30 Choose" this.Vim.GetVal("VimVerbose"), [1, 2, 3, 4], True)
86+
87+
; Tab 4: Configuration file
88+
this.Tab.UseTab(4)
89+
this.Obj.AddText("X+0 Y+0 Section", "")
90+
SplitPath(this.Vim.Ini.Ini, &fileName, &iniDir)
91+
this.Obj.AddText("XS+10 Y+10", "Current configuration directory:")
92+
this.AddClick("Text", "XS+10 cBlue", iniDir, this.Vim.Ini.OpenIniDirObj)
93+
this.Obj.AddText("XS+10 Y+10", "Current configuration file:")
94+
this.AddClick("Text", "XS+10 cBlue", fileName, this.Vim.Ini.OpenIniObj)
95+
this.AddClick("Button", "XS+10 Y+10 W120", "Import", this.ImportObj, "Load settings from an INI file")
96+
this.AddClick("Button", "X+10 W120", "Export", this.ExportObj, "Save current settings to an INI file")
97+
98+
; End tabs; add help and buttons below the tab
99+
this.Tab.UseTab()
100+
101+
; Add contents below the tab
102+
this.Tab.GetPos(&tabX, &tabY, &tabW, &tabH)
103+
underTab := tabY + tabH + 10
104+
105+
;; Create help controls and measure
106+
this.Obj.AddText("X15 Y" underTab, "Check")
79107
this.Obj.SetFont("Underline")
80108
this.AddClick("Text", "X+5 cBlue", "HELP", this.Vim.about.OpenHomepageObj, this.Vim.About.Homepage)
81109
this.Obj.SetFont("Norm")
82110
this.Obj.AddText("X+5", "for further information.")
83111

84-
this.AddClick("Button", "X10 W100 Y+10 Default", "OK", this.OKObj, "Reflect changes and exit")
112+
this.AddClick("Button", "X15 W100 Y+10 Default", "OK", this.OKObj, "Apply changes and close")
113+
this.AddClick("Button", "X+10 W100", "Apply", this.ApplyObj, "Apply changes without closing")
85114
this.AddClick("Button", "X+10 W100", "Reset", this.ResetObj, "Reset to the default values")
86-
this.AddClick("Button", "X+10 W100", "Cancel", this.CancelObj, "Don't change and exit")
115+
this.AddClick("Button", "X+10 W100", "Cancel", this.CancelObj, "Discard changes and close")
87116
}
88117

89118
UpdateGui(){
@@ -167,10 +196,18 @@ class VimSetting Extends VimGui{
167196
this.Obj.Submit()
168197
this.VimV2Conf()
169198
this.Vim.Setup()
170-
this.vim.Ini.WriteIni()
199+
this.Vim.Ini.WriteIni()
171200
this.Hide(Obj)
172201
}
173202

203+
Apply(Obj, Info){
204+
this.Obj.Submit(false)
205+
this.VimV2Conf()
206+
this.Vim.Setup()
207+
this.Vim.Ini.WriteIni()
208+
this.Vim.VimToolTip.RemoveToolTip()
209+
}
210+
174211
Cancel(Obj, Info){
175212
this.Hide(Obj)
176213
}
@@ -179,4 +216,72 @@ class VimSetting Extends VimGui{
179216
this.Vim.SetConfDefault()
180217
this.UpdateGuiValue()
181218
}
219+
220+
ImportIni(Obj, Info){
221+
try {
222+
path := FileSelect("", "", "Import INI (staged; Apply to confirm)", "INI (*.ini)")
223+
if (path == "")
224+
return
225+
; Read selected INI into a temporary conf map without touching runtime conf
226+
tmpConf := Map()
227+
for k, v in this.Vim.Conf {
228+
tmpConf[k] := Map("default", v["default"], "val", v["val"], "description", v["description"], "info", v["info"])
229+
}
230+
SplitPath(path, &fileName, &dir)
231+
tmpIni := VimIni(this.Vim, dir, fileName)
232+
tmpIni.ReadIni()
233+
234+
; Update GUI controls from tmpConf only
235+
; Checkboxes
236+
for i, k in this.Vim.Checkboxes {
237+
if this.Obj.HasProp(k) && tmpConf.Has(k)
238+
this.Obj[k].Value := tmpConf[k]["val"]
239+
}
240+
; Text/DDL fields with conversions
241+
if this.Obj.HasProp("VimTwoLetter")
242+
this.Obj["VimTwoLetter"].Value := StrReplace(tmpConf["VimTwoLetter"]["val"], this.Vim.GroupDel, "`n", 0, , -1)
243+
if this.Obj.HasProp("VimDisableUnused")
244+
this.Obj["VimDisableUnused"].Value := tmpConf["VimDisableUnused"]["val"]
245+
if this.Obj.HasProp("VimIconCheckInterval")
246+
this.Obj["VimIconCheckInterval"].Value := tmpConf["VimIconCheckInterval"]["val"]
247+
; Title match mode
248+
if this.Obj.HasProp("VimSetTitleMatchMode") {
249+
matchmode := tmpConf["VimSetTitleMatchMode"]["val"]
250+
this.Obj["VimSetTitleMatchMode"].Value := (matchmode == "RegEx") ? 4 : matchmode
251+
}
252+
if this.Obj.HasProp("VimSetTitleMatchModeFS") {
253+
matchmodefs := tmpConf["VimSetTitleMatchModeFS"]["val"]
254+
this.Obj["VimSetTitleMatchModeFS"].Value := (matchmodefs == "Fast") ? 1 : 2
255+
}
256+
if this.Obj.HasProp("VimVerbose")
257+
this.Obj["VimVerbose"].Value := tmpConf["VimVerbose"]["val"]
258+
if this.Obj.HasProp("VimAppList") {
259+
ap := tmpConf["VimAppList"]["val"]
260+
this.Obj["VimAppList"].Value := (ap == "All") ? 1 : (ap == "Allow List") ? 2 : 3
261+
}
262+
if this.Obj.HasProp("VimGroup")
263+
this.Obj["VimGroup"].Value := StrReplace(tmpConf["VimGroup"]["val"], this.Vim.GroupDel, "`n", 0, , -1)
264+
265+
; Do not write to the main INI nor apply runtime yet — waits for Apply
266+
MsgBox("Imported settings staged from:`n" path "`nClick Apply to apply them.", "Vim Ahk")
267+
} catch as e {
268+
MsgBox("Failed to import: " e.Message, "Vim Ahk", "Iconx")
269+
}
270+
}
271+
272+
ExportIni(Obj, Info){
273+
try {
274+
path := FileSelect("S", "", "Export INI", "INI (*.ini)")
275+
if (path == "")
276+
return
277+
; Ensure current settings are saved before export
278+
this.Obj.Submit(false)
279+
this.VimV2Conf()
280+
this.Vim.Ini.WriteIni()
281+
FileCopy(this.Vim.Ini.Ini, path, true)
282+
MsgBox("Exported settings to: `n" path, "Vim Ahk")
283+
} catch as e {
284+
MsgBox("Failed to export: " e.Message, "Vim Ahk", "Iconx")
285+
}
286+
}
182287
}

lib/vim_state.ahk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
this.Vim.VimToolTip.SetRemoveToolTip(1000)
4444
}
4545

46-
FullStatus(ItemName, ItemPos, MyMenu){
46+
FullStatus(ItemName:="", ItemPos:="", MyMenu:=""){
4747
this.CheckMode(4, , , , 1)
4848
}
4949

pictures/settings.jpg

100755100644
File mode changed.

pictures/settings_applications.png

11.1 KB
Loading

0 commit comments

Comments
 (0)