Skip to content

Commit e110337

Browse files
committed
Variable- and scope-related cleanups
- Remove redundant local variable declarations - Rename the always_on_top global to is_always_on_top_on - Move options menu setup code into a dedicated function
1 parent bcdf40d commit e110337

File tree

1 file changed

+24
-32
lines changed

1 file changed

+24
-32
lines changed

EC-Autoclicker.ahk

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ SZ_TABLE := {
6060

6161
program_logs := []
6262
is_autoclicking := false
63-
always_on_top := true
63+
is_always_on_top_on := true
6464

6565
configured_hotkeys := []
6666
are_hotkeys_active := true
@@ -71,7 +71,6 @@ makeRadioGroup(name, radioControls, changedCallback := 0) {
7171
radioControls[1].Name := name
7272
RadioGroups.%name% := { Controls: radioControls, Callback: changedCallback }
7373
if changedCallback {
74-
local ctrl
7574
for ctrl in radioControls
7675
ctrl.OnEvent("Click", changedCallback)
7776
}
@@ -82,7 +81,6 @@ makeCheckable(name, checkbox, callback := 0, controls := []) {
8281
if callback = 1 {
8382
checkbox.OnEvent("Click", Toggle)
8483
Toggle(*) {
85-
local ctrl
8684
for ctrl in controls
8785
ctrl.Enabled := checkbox.Value
8886
}
@@ -355,10 +353,26 @@ add_log(text) {
355353
program_logs.RemoveAt(1)
356354
}
357355

356+
setupOptionsMenu() {
357+
for optionInfo in PersistentOptions {
358+
OptionsMenu.Add(optionInfo.Text, OptionsMenuItemCallbackWrapper)
359+
360+
optionInfo.CurrentSetting := RegRead(REG_KEY_PATH, optionInfo.ValueName, optionInfo.Default)
361+
362+
if optionInfo.CurrentSetting != optionInfo.Default
363+
optionInfo.Toggler()
364+
if optionInfo.CurrentSetting
365+
OptionsMenu.Check(optionInfo.Text)
366+
}
367+
368+
OptionsMenu.Add()
369+
OptionsMenu.Add(SZ_TABLE.Menu_Options_ResetToDefault, ResetOptionsToDefault)
370+
}
371+
358372
showGuiAtAutoclickerGuiPos(gui) {
359373
local posX, posY
360374
AutoclickerGui.GetPos(&posX, &posY)
361-
gui.Opt((always_on_top ? "+" : "-") "AlwaysOnTop")
375+
gui.Opt((is_always_on_top_on ? "+" : "-") "AlwaysOnTop")
362376
gui.Show("x" posX " y" posY)
363377
}
364378

@@ -397,7 +411,6 @@ validateProfileNameInput(profileName) {
397411
}
398412

399413
formatHotkeyText(hotkey) {
400-
local k, v
401414
for k, v in Map("~", "", "^", "{ctrl}", "!", "{alt}", "+", "{shift}")
402415
hotkey := StrReplace(hotkey, k, v)
403416
return hotkey
@@ -461,7 +474,6 @@ Positioning_ChangedModeSelection(radio, *) {
461474
Hotkeys_updateHotkeyBindings() {
462475
AutoclickerGui["Hotkeys_HotkeyList_ListView"].Delete()
463476

464-
local hotkeyData
465477
for hotkeyData in configured_hotkeys {
466478
AutoclickerGui["Hotkeys_HotkeyList_ListView"].Add(
467479
, hotkeyData.Action = 1 ? "Start"
@@ -478,7 +490,6 @@ Hotkeys_updateHotkeyBindings() {
478490

479491
HotkeyEvent(hotkey) {
480492
local hotkeyData
481-
local hDat
482493
for hDat in configured_hotkeys {
483494
if hDat.Hotkey = hotkey {
484495
hotkeyData := hDat
@@ -551,9 +562,6 @@ Hotkeys_AddHotkey(*) {
551562
Submit(*) {
552563
hideOwnedGui(KeyBinderGui)
553564

554-
local hotkeyText := formatHotkeyText(KeyBinderGui["Hotkey"].Value)
555-
556-
local hotkeyData
557565
for hotkeyData in configured_hotkeys {
558566
if "~" KeyBinderGui["Hotkey"].Value = hotkeyData.Hotkey {
559567
if MsgBox(
@@ -568,6 +576,8 @@ Hotkeys_AddHotkey(*) {
568576
}
569577
}
570578

579+
local hotkeyText := formatHotkeyText(KeyBinderGui["Hotkey"].Value)
580+
571581
configured_hotkeys.Push {
572582
Hotkey: "~" KeyBinderGui["Hotkey"].Value,
573583
HotkeyText: hotkeyText,
@@ -589,7 +599,6 @@ Hotkeys_RemoveHotkey(*) {
589599
if !rowNum
590600
break
591601

592-
local hotkeyData
593602
for hotkeyData in configured_hotkeys {
594603
if hotkeyData.HotkeyText = AutoclickerGui["Hotkeys_HotkeyList_ListView"].GetText(rowNum, 3) {
595604
configured_hotkeys.RemoveAt(A_Index)
@@ -605,7 +614,6 @@ Hotkeys_RemoveHotkey(*) {
605614
}
606615

607616
Hotkeys_ClearAllHotkeys(*) {
608-
local hotkeyData
609617
for hotkeyData in configured_hotkeys {
610618
configured_hotkeys.Delete(A_Index)
611619
Hotkey hotkeyData.Hotkey, "Off"
@@ -652,7 +660,6 @@ ProfileCreate(*) {
652660

653661
RegCreateKey REG_KEY_PATH "\Profiles\" profileName
654662

655-
local ctrlName, value
656663
for ctrlName, value in currentConfig.OwnProps() {
657664
if !InStr(ctrlName, "_")
658665
continue
@@ -663,9 +670,9 @@ ProfileCreate(*) {
663670
}
664671

665672
local serializedHotkeys := ""
666-
local hotkeyData
667673
for hotkeyData in configured_hotkeys
668674
serializedHotkeys .= hotkeyData.Hotkey "%" hotkeyData.Scope "%" hotkeyData.Action "`n"
675+
669676
RegWrite serializedHotkeys
670677
, "REG_MULTI_SZ"
671678
, REG_KEY_PATH "\Profiles\" profileName
@@ -832,7 +839,6 @@ ProfileManage(*) {
832839
local fileLocations := FileSelect("M",
833840
, "Import Autoclicker Profile(s)", "Autoclicker Profiles (*" FILE_EXT ")"
834841
)
835-
local fileLocation
836842
for fileLocation in fileLocations {
837843
add_log("Importing profile from " fileLocation)
838844

@@ -853,7 +859,6 @@ ProfileManage(*) {
853859

854860
RegCreateKey REG_KEY_PATH "\Profiles\" profileName
855861

856-
local err
857862
try {
858863
Loop Parse FileRead(fileLocation), "`n" {
859864
if !A_LoopField
@@ -902,7 +907,6 @@ ProfileLoad(profileName, *) {
902907
return
903908
}
904909

905-
local err
906910
try {
907911
Loop Reg REG_KEY_PATH "\Profiles\" profileName {
908912
local value := RegRead()
@@ -988,7 +992,6 @@ LogsOpen(*) {
988992
RefreshLogs(*) {
989993
LogsGui["List"].Delete()
990994

991-
local data
992995
for data in program_logs {
993996
LogsGui["List"].Add(, FormatTime(data.Timestamp, "HH:mm:ss"), data.Message)
994997
}
@@ -998,8 +1001,8 @@ LogsOpen(*) {
9981001
}
9991002

10001003
toggleAlwaysOnTop(optionInfo) {
1001-
global always_on_top := optionInfo.CurrentSetting
1002-
AutoclickerGui.Opt((always_on_top ? "+" : "-") "AlwaysOnTop")
1004+
global is_always_on_top_on := optionInfo.CurrentSetting
1005+
AutoclickerGui.Opt((is_always_on_top_on ? "+" : "-") "AlwaysOnTop")
10031006
}
10041007

10051008
toggleHotkeysActive(optionInfo) {
@@ -1033,7 +1036,6 @@ ResetOptionsToDefault(*) {
10331036
RegDelete
10341037
}
10351038

1036-
local optionInfo
10371039
for optionInfo in PersistentOptions {
10381040
if optionInfo.CurrentSetting != optionInfo.Default {
10391041
optionInfo.CurrentSetting := optionInfo.Default
@@ -1211,7 +1213,6 @@ Your current version is {}. Would you like to update now?
12111213

12121214
add_log("Downloading file")
12131215

1214-
local err
12151216
try
12161217
Download "https://github.com/" GITHUB_REPO "/releases/latest/download/EC-Autoclicker.exe"
12171218
, downloadFilePath
@@ -1231,16 +1232,7 @@ Your current version is {}. Would you like to update now?
12311232
}
12321233
}
12331234

1234-
for optionInfo in PersistentOptions {
1235-
OptionsMenu.Add optionInfo.Text, OptionsMenuItemCallbackWrapper
1236-
optionInfo.CurrentSetting := RegRead(REG_KEY_PATH, optionInfo.ValueName, optionInfo.Default)
1237-
if optionInfo.CurrentSetting != optionInfo.Default
1238-
optionInfo.Toggler()
1239-
if optionInfo.CurrentSetting
1240-
OptionsMenu.Check(optionInfo.Text)
1241-
}
1242-
OptionsMenu.Add()
1243-
OptionsMenu.Add(SZ_TABLE.Menu_Options_ResetToDefault, ResetOptionsToDefault)
1235+
setupOptionsMenu()
12441236

12451237
if A_Args.Length > 0 && A_Args[1] = "/profile" {
12461238
add_log("Detected /profile switch")

0 commit comments

Comments
 (0)