-
Notifications
You must be signed in to change notification settings - Fork 0
/
gptPS.ahk
163 lines (134 loc) · 5.46 KB
/
gptPS.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
<!#CR>
************************************************************************************************************************
* ByteForge Copyright © *
* -------------------------------------------------------------------------------------------------------------------- *
* Company Name > ByteForge *
* Company Email > admin@byteforge.app *
* Company Websites > http://www.byteforge.app *
* -------------------------------------------------------------------------------------------------------------------- *
* File and License Informations *
* -------------------------------------------------------------------------------------------------------------------- *
* File Name > <!#FN> gptPS.ahk </#FN>
* License > <!#LT> BSD-3-Clause-Attribution </#LT>
* <!#LU> https://spdx.org/licenses/BSD-3-Clause-Attribution.html </#LU>
* <!#LD> This file may not be redistributed in whole or significant part. </#LD>
* File Version > <!#FV> 1.1.1 </#FV>
* *
******************************************* VSCode Extension: Version Boss *********************************************
</#CR>
*/
#SingleInstance Force
#Include splash.ahk
#Include categories.ahk
#Include Hotkeys.ahk
#Include CategoryTab.ahk
Persistent
OnExit ExitHandler ; register the function with the OnExit command
ExitHandler(ExitReason, ExitCode) {
; MsgBox("Script is exiting. Reason: " . ExitReason . ", Code: " . ExitCode)
EnableHotkeys("Off")
}
global myGui, myGuiTabs, tabControl, isListBoxesShown := false
; Initialize the application with dependencies
Initialize(categories) {
EnableHotkeys("Off")
ShowSplashScreen()
; Delay the execution of OpenOrShowPhraseSelector() until the splash screen disappears
SetTimer OpenOrShowPhraseSelector, -2500
}
; Create the GUI with the tab control and tabs
CreatePhraseSelectorGui(categories) {
global myGui, myGuiTabs, tabControl
keycat := []
for key in categories {
keycat.Push(key)
}
; Create the GUI instance
myGui := Gui("+AlwaysOnTop", "GPT Phrase Select")
myGui.SetFont("S12")
; Add the tab control and tabs to the GUI
myGuiTabs := []
tabControl := myGui.Add("Tab3", , keycat)
for key, value in categories {
tabControl.UseTab(key)
newTab := CategoryTab(myGui, value)
myGuiTabs.Push(newTab)
}
; Register the Close event handler for the GUI
myGui.OnEvent("Close", GuiClose)
myGui.onevent('size', gui_size)
}
; Open or show the Phrase Selector GUI
OpenOrShowPhraseSelector() {
global myGui, isListBoxesShown
; Create a new GUI instance
CreatePhraseSelectorGui(categories)
; Show the GUI, set focus and enable the Escape and Enter hotkeys
myGui.Show("Restore")
isListBoxesShown := true
SetFocusToActiveListBox()
EnableHotkeys("On")
}
; Close the Phrase Selector GUI
ClosePhraseSelector() {
global myGui, isListBoxesShown
myGui.Show("Hide")
isListBoxesShown := false
EnableHotkeys("Off")
}
; Toggle the phrase selector GUI
TogglePhraseSelector() {
global isListBoxesShown
if (!isListBoxesShown) {
OpenOrShowPhraseSelector()
} else {
ClosePhraseSelector()
}
}
; GUI Event handler for minimize, maximize, change size event
Gui_Size(GuiObj, MinMax, Width, Height) {
; interrupt other threads to ensure the resize event is handled correctly
Critical "Off"
Sleep -1
if (MinMax == -1) {
ClosePhraseSelector()
}
}
; Terminate gptPS Script and close
GuiClose(thisGui) {
; Hide the gui window so it doesn't block the msgbox due to z-order
ClosePhraseSelector()
; Show a confirmation prompt before closing the GUI
if (MsgBox("Are you sure you want to close GPT Phrase Select?","Close gptPS?", "y/n 0x40000") = "No") {
; If the user selects "No", cancel the close event and show the GUI again
thisGui.CancelClose := true
OpenOrShowPhraseSelector()
return true ; true = 1
}
; The user selected to close the app
ExitApp
}
; Set the focus to the ListBox of the active tab
SetFocusToActiveListBox() {
global myGuiTabs, tabControl
activeTabIndex := tabControl.Value
activeTab := myGuiTabs[activeTabIndex]
activeTab.listBox.Focus()
}
PressEnter() {
global myGuiTabs, tabControl
activeTabIndex := tabControl.Value
activeTab := myGuiTabs[activeTabIndex]
activeTab.OnEnterPress()
}
EnableHotkeys(state := "On") {
if (state != "On" && state != "Off") {
MsgBox("Invalid parameter. Use 'On' or 'Off'.")
return
}
; Enable or disable the Escape and Enter hotkeys based on the state parameter
Hotkey "Esc", state
Hotkey "Enter", state
}
Initialize(categories)