@@ -330,6 +330,28 @@ hideOwnedGui(gui, *) {
330
330
WinActivate " ahk_id " AutoclickerGui.Hwnd
331
331
}
332
332
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
+
333
355
formatHotkeyText (hotkey ) {
334
356
local k, v
335
357
for k, v in Map(" ~" , "" , " ^" , " {ctrl}" , " !" , " {alt}" , " +" , " {shift}" )
@@ -520,72 +542,35 @@ Hotkeys_ClearAllHotkeys(*) {
520
542
Hotkeys_updateHotkeyBindings
521
543
}
522
544
523
- profileNamePrompt (title, text, callback, owner := AutoclickerGui ) {
524
- static currentCallback
545
+ ProfileCreate (* ) {
525
546
static ProfileNamePromptGui
526
547
if ! IsSet(ProfileNamePromptGui) {
527
- ProfileNamePromptGui := Gui (" -SysMenu +Owner" AutoclickerGui.Hwnd)
548
+ ProfileNamePromptGui := Gui (" -SysMenu +Owner" AutoclickerGui.Hwnd, " Create/Update Profile " )
528
549
ProfileNamePromptGui.OnEvent " Escape" , hideOwnedGui
529
550
ProfileNamePromptGui.OnEvent " Close" , hideOwnedGui
530
551
531
- ProfileNamePromptGui.AddText " w206 r2 vPromptText"
552
+ ProfileNamePromptGui.AddText " w206 r2"
553
+ , " The current autoclicker configuration will`nbe saved with the following profile name:"
532
554
ProfileNamePromptGui.AddEdit " wp vProfileNameEdit"
533
555
534
556
ProfileNamePromptGui.AddButton(" w100 Default" , " OK" )
535
- .OnEvent(" Click" , ( * ) => CallbackWrapper(currentCallback) )
557
+ .OnEvent(" Click" , SubmitPrompt )
536
558
ProfileNamePromptGui.AddButton(" yp wp" , " Cancel" )
537
559
.OnEvent(" Click" , (* ) => hideOwnedGui(ProfileNamePromptGui))
538
560
539
561
add_log " Created profile name prompt GUI"
540
562
}
541
563
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
570
564
ProfileNamePromptGui[" ProfileNameEdit" ].Value := ""
571
565
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
582
568
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
587
573
588
- SubmitPrompt (profileName ) {
589
574
add_log " Reading configuration data"
590
575
591
576
local currentConfig := AutoclickerGui.Submit(false )
@@ -606,6 +591,9 @@ ProfileCreate(*) {
606
591
RegWrite serializedHotkeys, " REG_MULTI_SZ" , REG_KEY_PATH " \Profiles\" profileName, " Hotkeys"
607
592
608
593
add_log " Wrote configuration data to registry"
594
+
595
+ setupProfiles
596
+ hideOwnedGui ProfileNamePromptGui
609
597
}
610
598
}
611
599
@@ -664,29 +652,66 @@ ProfileManage(*) {
664
652
ProfileRename (* ) {
665
653
local selectedProfileName := ProfilesGui[" ProfileList" ].GetText(ProfilesGui[" ProfileList" ].GetNext())
666
654
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"
670
684
671
- SubmitPrompt (newProfileName ) {
672
685
Loop Reg REG_KEY_PATH " \Profiles" , " K" {
673
686
if A_LoopRegName = selectedProfileName {
674
- local newProfileRegPath := A_LoopRegKey " \" newProfileName
687
+ local newProfileRegPath := A_LoopRegKey " \" profileNewName
675
688
RegCreateKey newProfileRegPath
676
689
677
690
Loop Reg A_LoopRegKey " \" A_LoopRegName
678
691
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 " '"
680
693
681
694
RegDeleteKey
682
695
add_log " Deleted profile '" selectedProfileName " '"
683
696
684
- refreshProfileList newProfileName
697
+ ProfileRenamePromptGui.Hide
698
+ ProfilesGui.Opt " -Disabled"
699
+ WinActivate " ahk_id " ProfilesGui.Hwnd
700
+ refreshProfileList profileNewName
701
+ setupProfiles
685
702
return
686
703
}
687
704
}
688
705
MsgBox " The profile '" selectedProfileName " ' does not exist or has been deleted." , " Error" , " Iconx 8192"
706
+ ProfileRenamePromptGui.Opt " -Disabled"
689
707
refreshProfileList
708
+ setupProfiles
709
+ }
710
+
711
+ CancelPrompt (* ) {
712
+ ProfileRenamePromptGui.Hide
713
+ ProfilesGui.Opt " -Disabled"
714
+ WinActivate " ahk_id " ProfilesGui.Hwnd
690
715
}
691
716
}
692
717
0 commit comments