Skip to content

Commit fba7e17

Browse files
committed
add ui for changing increment mode
1 parent 4e233a0 commit fba7e17

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

TagCompanion.ahk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ context.HotstringManager.Load(context.SettingsManager.settings['hotstrings']['fi
8989

9090
; Increment number in selection.
9191
^Up:: {
92-
ClipboardIncrement("First", context.SettingsManager.settings['increment']['up'])
92+
ClipboardIncrement(context.SettingsManager.settings['increment']['mode'], context.SettingsManager.settings['increment']['up'])
9393
}
9494

9595
; Decrement number in selection.
9696
^Down:: {
97-
ClipboardIncrement("First", context.SettingsManager.settings['increment']['down'])
97+
ClipboardIncrement(context.SettingsManager.settings['increment']['mode'], context.SettingsManager.settings['increment']['down'])
9898
}
9999

100100
#SuspendExempt false

lib/Clipboard.ahk

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ ClipboardIncrement(IncrementMode, offset) {
2626
SendInput newText
2727

2828
; Reselect the current region
29-
SendInput("^+{Left}")
29+
Loop (StrLen(newText)) {
30+
SendInput("+{Up}")
31+
}
32+
; SendInput("^+{Left}")
3033
if i > 1 {
3134
Loop (i - 1) {
3235
SendInput("^+{Up}")

lib/MenuManager.ahk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class MenuManager {
1515
this.FileMenu.Add("Exit", (*) => ExitApp())
1616
this.FileMenu.SetIcon("&Open Hotstrings...`tCtrl+O","shell32.dll", 4)
1717
this.FileMenu.SetIcon("&Save Hotstrings`tCtrl+S","shell32.dll", 259)
18+
19+
this.SettingsMenu := Menu()
20+
this.SettingsMenu.Add("Increment First", (*) => context.SettingsManager.SetIncrementMode("first"))
21+
this.SettingsMenu.Add("Increment Last", (*) => context.SettingsManager.SetIncrementMode("last"))
22+
this.FileMenu.Add()
1823

1924
this.HelpMenu := Menu()
2025
this.HelpMenu.Add("&Help`tF1", this.MenuHandler)
@@ -23,8 +28,10 @@ class MenuManager {
2328
this.HelpMenu.SetIcon("&Help`tF1","shell32.dll", 24)
2429
this.MenuBar := MenuBar()
2530
this.MenuBar.Add("&File", this.FileMenu)
31+
this.MenuBar.Add("Settings", this.SettingsMenu)
2632
this.MenuBar.Add("Help", this.HelpMenu)
2733
this.context.GuiMain.MenuBar := this.MenuBar
34+
this.UpdateState()
2835
}
2936

3037

@@ -33,6 +40,18 @@ class MenuManager {
3340
SetTimer () => ToolTip(), -3000
3441
}
3542

43+
UpdateState() {
44+
settings := this.context.SettingsManager.settings
45+
if (settings["increment"]["mode"] == "last") {
46+
this.SettingsMenu.Uncheck("Increment First")
47+
this.SettingsMenu.Check("Increment Last")
48+
} else {
49+
this.SettingsMenu.Check("Increment First")
50+
this.SettingsMenu.Uncheck("Increment Last")
51+
}
52+
53+
}
54+
3655
ControlDelayMenuHandler(ItemName, ItemPos, MenuInstance) {
3756
Switch ItemName {
3857
case "Send It (Fastest)":

lib/SettingsManager.ahk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,10 @@ class SettingsManager {
107107
HotstringsSetEnabled(Value) {
108108
this.settings['hotstrings']['enabled'] := Value
109109
}
110+
111+
SetIncrementMode(Value) {
112+
this.settings['increment']['mode'] := Value
113+
this.context.MenuManager.UpdateState()
114+
this.Autosave()
115+
}
110116
}

lib/Strings.ahk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ StringUnescapeCC(String)
1919
/**
2020
* Find and increment a number inside a string
2121
* @param {String} String input string
22-
* @param {'First'|'Last'} IncrementMode
22+
* @param {'first'|'last'} IncrementMode
2323
* @param {Integer} Offset value to add
2424
* @returns {String} output string
2525
*/
2626
StringIncrement(String, IncrementMode, Offset){
2727
regex := ""
2828
Switch IncrementMode {
29-
case "First":
29+
case "first":
3030
regex := "(\d+)"
31-
case "Last":
31+
case "last":
3232
regex := "(\d+)(?!.*\d+)"
3333
}
3434

0 commit comments

Comments
 (0)