Skip to content

Commit ce1c568

Browse files
authored
v1.1.3 (revision)
1 parent 3c95d29 commit ce1c568

File tree

1 file changed

+80
-55
lines changed

1 file changed

+80
-55
lines changed

EC-Autoclicker.ahk

Lines changed: 80 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,28 @@ hideOwnedGui(gui, *) {
330330
WinActivate "ahk_id " AutoclickerGui.Hwnd
331331
}
332332

333+
validateProfileNameInput(profileName) {
334+
if RegExReplace(profileName, "\s") = ""
335+
return false
336+
if profileName ~= "[\\/:\*\?`"<>\|]" {
337+
MsgBox "A profile name can't contain any of the following characters:`n\ / : * ? `" < > |", "Create/Update Profile", "Iconx 8192"
338+
return false
339+
}
340+
Loop Reg REG_KEY_PATH "\Profiles", "K" {
341+
if A_LoopRegName = profileName {
342+
if MsgBox(
343+
"A profile similarly named '" A_LoopRegName "' already exists. Would you like to overwrite it?"
344+
, "Overwrite Profile", "YesNo Iconi 8192"
345+
) = "Yes" {
346+
RegDeleteKey A_LoopRegKey "\" A_LoopRegName
347+
return true
348+
} else
349+
return false
350+
}
351+
}
352+
return true
353+
}
354+
333355
formatHotkeyText(hotkey) {
334356
local k, v
335357
for k, v in Map("~", "", "^", "{ctrl}", "!", "{alt}", "+", "{shift}")
@@ -520,72 +542,35 @@ Hotkeys_ClearAllHotkeys(*) {
520542
Hotkeys_updateHotkeyBindings
521543
}
522544

523-
profileNamePrompt(title, text, callback, owner := AutoclickerGui) {
524-
static currentCallback
545+
ProfileCreate(*) {
525546
static ProfileNamePromptGui
526547
if !IsSet(ProfileNamePromptGui) {
527-
ProfileNamePromptGui := Gui("-SysMenu +Owner" AutoclickerGui.Hwnd)
548+
ProfileNamePromptGui := Gui("-SysMenu +Owner" AutoclickerGui.Hwnd, "Create/Update Profile")
528549
ProfileNamePromptGui.OnEvent "Escape", hideOwnedGui
529550
ProfileNamePromptGui.OnEvent "Close", hideOwnedGui
530551

531-
ProfileNamePromptGui.AddText "w206 r2 vPromptText"
552+
ProfileNamePromptGui.AddText "w206 r2"
553+
, "The current autoclicker configuration will`nbe saved with the following profile name:"
532554
ProfileNamePromptGui.AddEdit "wp vProfileNameEdit"
533555

534556
ProfileNamePromptGui.AddButton("w100 Default", "OK")
535-
.OnEvent("Click", (*) => CallbackWrapper(currentCallback))
557+
.OnEvent("Click", SubmitPrompt)
536558
ProfileNamePromptGui.AddButton("yp wp", "Cancel")
537559
.OnEvent("Click", (*) => hideOwnedGui(ProfileNamePromptGui))
538560

539561
add_log "Created profile name prompt GUI"
540562
}
541563

542-
CallbackWrapper(currentCallback) {
543-
local profileName := ProfileNamePromptGui["ProfileNameEdit"].Value
544-
if RegExReplace(profileName, "\s") = ""
545-
return
546-
if profileName ~= "[\\/:\*\?`"<>\|]" {
547-
MsgBox "A profile name can't contain any of the following characters:`n\ / : * ? `" < > |", "Create/Update Profile", "Iconx 8192"
548-
return
549-
}
550-
Loop Reg REG_KEY_PATH "\Profiles", "K" {
551-
if A_LoopRegName = profileName {
552-
if MsgBox(
553-
"A profile similarly named '" A_LoopRegName "' already exists. Would you like to overwrite it with the new configuration set?"
554-
, "Overwrite Profile", "YesNo Iconi 8192"
555-
) = "Yes"
556-
RegDeleteKey A_LoopRegKey "\" A_LoopRegName
557-
else
558-
return
559-
}
560-
}
561-
ProfileNamePromptGui.Opt "+Disabled"
562-
currentCallback profileName
563-
setupProfiles
564-
hideOwnedGui ProfileNamePromptGui
565-
}
566-
567-
currentCallback := callback
568-
ProfileNamePromptGui.Title := title
569-
ProfileNamePromptGui["PromptText"].Text := text
570564
ProfileNamePromptGui["ProfileNameEdit"].Value := ""
571565
ProfileNamePromptGui.Opt "-Disabled"
572-
owner.Opt "+Disabled"
573-
if owner = AutoclickerGui
574-
showGuiAtAutoclickerGuiPos ProfileNamePromptGui
575-
else {
576-
local posX, posY
577-
owner.GetPos &posX, &posY
578-
ProfileNamePromptGui.Opt (always_on_top ? "+" : "-") "AlwaysOnTop"
579-
ProfileNamePromptGui.Show "x" posX " y" posY
580-
}
581-
}
566+
AutoclickerGui.Opt "+Disabled"
567+
showGuiAtAutoclickerGuiPos ProfileNamePromptGui
582568

583-
ProfileCreate(*) {
584-
profileNamePrompt "Create/Update Profile"
585-
, "The current autoclicker configuration will`nbe saved with the following profile name:"
586-
, SubmitPrompt
569+
SubmitPrompt(*) {
570+
local profileName := ProfileNamePromptGui["ProfileNameEdit"].Value
571+
if !validateProfileNameInput(profileName)
572+
return
587573

588-
SubmitPrompt(profileName) {
589574
add_log "Reading configuration data"
590575

591576
local currentConfig := AutoclickerGui.Submit(false)
@@ -606,6 +591,9 @@ ProfileCreate(*) {
606591
RegWrite serializedHotkeys, "REG_MULTI_SZ", REG_KEY_PATH "\Profiles\" profileName, "Hotkeys"
607592

608593
add_log "Wrote configuration data to registry"
594+
595+
setupProfiles
596+
hideOwnedGui ProfileNamePromptGui
609597
}
610598
}
611599

@@ -664,29 +652,66 @@ ProfileManage(*) {
664652
ProfileRename(*) {
665653
local selectedProfileName := ProfilesGui["ProfileList"].GetText(ProfilesGui["ProfileList"].GetNext())
666654

667-
profileNamePrompt "Rename Profile"
668-
, "The profile '" selectedProfileName "' will be renamed to:"
669-
, SubmitPrompt
655+
static ProfileRenamePromptGui
656+
if !IsSet(ProfileRenamePromptGui) {
657+
ProfileRenamePromptGui := Gui("-SysMenu +Owner" ProfilesGui.Hwnd, "Rename Profile")
658+
ProfileRenamePromptGui.OnEvent "Escape", CancelPrompt
659+
ProfileRenamePromptGui.OnEvent "Close", CancelPrompt
660+
661+
ProfileRenamePromptGui.AddText "w206 vPromptText"
662+
ProfileRenamePromptGui.AddEdit "wp vProfileNameEdit"
663+
664+
ProfileRenamePromptGui.AddButton("w100 Default", "OK")
665+
.OnEvent("Click", SubmitPrompt)
666+
ProfileRenamePromptGui.AddButton("yp wp", "Cancel")
667+
.OnEvent("Click", CancelPrompt)
668+
669+
add_log "Created profile name prompt GUI"
670+
}
671+
672+
ProfileRenamePromptGui["PromptText"].Text := "The profile '" selectedProfileName "' will be renamed to:"
673+
ProfileRenamePromptGui["ProfileNameEdit"].Value := ""
674+
ProfileRenamePromptGui.Opt "-Disabled"
675+
ProfilesGui.Opt "+Disabled"
676+
showGuiAtAutoclickerGuiPos ProfileRenamePromptGui
677+
678+
SubmitPrompt(*) {
679+
local profileNewName := ProfileRenamePromptGui["ProfileNameEdit"].Value
680+
if !validateProfileNameInput(profileNewName)
681+
return
682+
683+
ProfileRenamePromptGui.Opt "+Disabled"
670684

671-
SubmitPrompt(newProfileName) {
672685
Loop Reg REG_KEY_PATH "\Profiles", "K" {
673686
if A_LoopRegName = selectedProfileName {
674-
local newProfileRegPath := A_LoopRegKey "\" newProfileName
687+
local newProfileRegPath := A_LoopRegKey "\" profileNewName
675688
RegCreateKey newProfileRegPath
676689

677690
Loop Reg A_LoopRegKey "\" A_LoopRegName
678691
RegWrite RegRead(), A_LoopRegType, newProfileRegPath, A_LoopRegName
679-
add_log "Copied reg data to profile '" newProfileName "'"
692+
add_log "Copied reg data to profile '" profileNewName "'"
680693

681694
RegDeleteKey
682695
add_log "Deleted profile '" selectedProfileName "'"
683696

684-
refreshProfileList newProfileName
697+
ProfileRenamePromptGui.Hide
698+
ProfilesGui.Opt "-Disabled"
699+
WinActivate "ahk_id " ProfilesGui.Hwnd
700+
refreshProfileList profileNewName
701+
setupProfiles
685702
return
686703
}
687704
}
688705
MsgBox "The profile '" selectedProfileName "' does not exist or has been deleted.", "Error", "Iconx 8192"
706+
ProfileRenamePromptGui.Opt "-Disabled"
689707
refreshProfileList
708+
setupProfiles
709+
}
710+
711+
CancelPrompt(*) {
712+
ProfileRenamePromptGui.Hide
713+
ProfilesGui.Opt "-Disabled"
714+
WinActivate "ahk_id " ProfilesGui.Hwnd
690715
}
691716
}
692717

0 commit comments

Comments
 (0)