forked from gphilippot/purebasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindWindow.pb
217 lines (174 loc) · 8.09 KB
/
FindWindow.pb
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
;--------------------------------------------------------------------------------------------
; Copyright (c) Fantaisie Software. All rights reserved.
; Dual licensed under the GPL and Fantaisie Software licenses.
; See LICENSE and LICENSE-FANTAISIE in the project root for license information.
;--------------------------------------------------------------------------------------------
Procedure OpenFindWindow()
If IsWindow(#WINDOW_Find) = 0
If *ActiveSource <> *ProjectInfo
FindWindowDialog = OpenDialog(?Dialog_Find, WindowID(#WINDOW_Main), @FindWindowPosition)
If FindWindowDialog
EnsureWindowOnDesktop(#WINDOW_Find)
For i = 1 To FindHistorySize
If FindSearchHistory(i) <> ""
AddGadgetItem(#GADGET_Find_FindWord, -1, FindSearchHistory(i))
EndIf
If FindReplaceHistory(i) <> ""
AddGadgetItem(#GADGET_Find_ReplaceWord, -1, FindReplaceHistory(i))
EndIf
Next i
SetGadgetState(#GADGET_Find_Case, FindCaseSensitive)
SetGadgetState(#GADGET_Find_WholeWord, FindWholeWord)
SetGadgetState(#GADGET_Find_NoComments, FindNoComments)
SetGadgetState(#GADGET_Find_NoStrings, FindNoStrings)
SetGadgetState(#GADGET_Find_SelectionOnly,FindSelectionOnly)
SetGadgetState(#GADGET_Find_DoReplace, 0) ; doreplace should always be disabled when opening this window.
DisableGadget(#GADGET_Find_ReplaceWord, 1)
DisableGadget(#GADGET_Find_Replace, 1)
DisableGadget( #GADGET_Find_Replaceall, 1)
SetGadgetState(#GADGET_Find_FindWord, 0) ; select the last entry
GetSelection(@LineStart, @RowStart, @LineEnd, @RowEnd)
If LineStart = LineEnd
If RowStart = RowEnd
SetGadgetState(#GADGET_Find_SelectionOnly, 0)
DisableGadget(#GADGET_Find_SelectionOnly, 1)
Else
; display the default selection in the box
Line$ = Mid(GetLine(LineStart-1), RowStart, RowEnd-RowStart)
SetGadgetText(#GADGET_Find_FindWord, Line$)
EndIf
EndIf
EndIf
EndIf
Else
SetWindowForeground(#WINDOW_Find)
EndIf
SelectComboBoxText(#GADGET_Find_FindWord)
SetActiveGadget(#GADGET_Find_FindWord)
EndProcedure
Procedure UpdateFindWindow()
FindWindowDialog\LanguageUpdate()
While FindHistorySize < CountGadgetItems(#GADGET_Find_FindWord)
RemoveGadgetItem(#GADGET_Find_FindWord, CountGadgetItems(#GADGET_Find_FindWord)-1)
Wend
While FindHistorySize < CountGadgetItems(#GADGET_Find_ReplaceWord)
RemoveGadgetItem(#GADGET_Find_ReplaceWord, CountGadgetItems(#GADGET_Find_ReplaceWord)-1)
Wend
FindWindowDialog\GuiUpdate()
EndProcedure
Procedure FindWindowEvents(EventID)
If EventID = #PB_Event_Menu ; Little wrapper to map the shortcut events (identified as menu)
EventID = #PB_Event_Gadget ; to normal gadget events...
GadgetID = EventMenu()
Else
GadgetID = EventGadget()
EndIf
Select EventID
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select GadgetID
Case #GADGET_Find_DoReplace
If GetGadgetState(#GADGET_Find_DoReplace)
DisableGadget(#GADGET_Find_ReplaceWord, 0)
DisableGadget(#GADGET_Find_Replace, 0)
DisableGadget( #GADGET_Find_Replaceall, 0)
Else
DisableGadget(#GADGET_Find_ReplaceWord, 1)
DisableGadget(#GADGET_Find_Replace, 1)
DisableGadget( #GADGET_Find_Replaceall, 1)
EndIf
Case #GADGET_Find_FindNext,
#GADGET_Find_FindPrevious
If *ActiveSource <> *ProjectInfo
FindCaseSensitive = GetGadgetState(#GADGET_Find_Case)
FindWholeWord = GetGadgetState(#GADGET_Find_WholeWord)
FindNoComments = GetGadgetState(#GADGET_Find_NoComments)
FindNoStrings = GetGadgetState(#GADGET_Find_NoStrings)
FindSelectionOnly = GetGadgetState(#GADGET_Find_SelectionOnly)
FindDoReplace = GetGadgetState(#GADGET_Find_DoReplace)
FindSearchString$ = GetGadgetText(#Gadget_Find_FindWord)
FindReplaceString$= SearchString$
UpdateFindComboBox(#Gadget_Find_FindWord)
UpdateFindComboBox(#GADGET_Find_ReplaceWord)
If GadgetID = #GADGET_Find_FindPrevious
Reverse = #True
EndIf
If FindText(1, Reverse) And FindDoReplace = 0
Quit = 1
Else
SetWindowForeground(#WINDOW_Find)
EndIf
EndIf
Case #GADGET_Find_Replace
If *ActiveSource <> *ProjectInfo
*Debugger.DebuggerData = IsDebuggedFile(*ActiveSource)
If *Debugger And *Debugger\CanDestroy = 0 ; no error if the code finished executing
MessageRequester(#ProductName$, Language("Debugger","EditError"), #FLAG_INFO)
Else
FindCaseSensitive = GetGadgetState(#GADGET_Find_Case)
FindWholeWord = GetGadgetState(#GADGET_Find_WholeWord)
FindNoComments = GetGadgetState(#GADGET_Find_NoComments)
FindNoStrings = GetGadgetState(#GADGET_Find_NoStrings)
FindSelectionOnly = GetGadgetState(#GADGET_Find_SelectionOnly)
FindDoReplace = GetGadgetState(#GADGET_Find_DoReplace)
FindSearchString$ = GetGadgetText(#Gadget_Find_FindWord)
FindReplaceString$= GetGadgetText(#GADGET_Find_ReplaceWord)
UpdateFindComboBox(#Gadget_Find_FindWord)
UpdateFindComboBox(#GADGET_Find_ReplaceWord)
FindText(2)
EndIf
SetWindowForeground(#WINDOW_Find)
EndIf
Case #GADGET_Find_Replaceall
If *ActiveSource <> *ProjectInfo
*Debugger.DebuggerData = IsDebuggedFile(*ActiveSource)
If *Debugger And *Debugger\CanDestroy = 0 ; no error if the code finished executing
MessageRequester(#ProductName$, Language("Debugger","EditError"), #FLAG_INFO)
Else
FindCaseSensitive = GetGadgetState(#GADGET_Find_Case)
FindWholeWord = GetGadgetState(#GADGET_Find_WholeWord)
FindNoComments = GetGadgetState(#GADGET_Find_NoComments)
FindNoStrings = GetGadgetState(#GADGET_Find_NoStrings)
FindSelectionOnly = GetGadgetState(#GADGET_Find_SelectionOnly)
FindDoReplace = GetGadgetState(#GADGET_Find_DoReplace)
FindSearchString$ = GetGadgetText(#Gadget_Find_FindWord)
FindReplaceString$= GetGadgetText(#GADGET_Find_ReplaceWord)
UpdateFindComboBox(#Gadget_Find_FindWord)
UpdateFindComboBox(#GADGET_Find_ReplaceWord)
FindText(3)
EndIf
SetWindowForeground(#WINDOW_Find)
EndIf
Case #GADGET_Find_Close
Quit = 1
EndSelect
EndSelect
If Quit
; get checkbox choices
FindCaseSensitive = GetGadgetState(#GADGET_Find_Case)
FindWholeWord = GetGadgetState(#GADGET_Find_WholeWord)
FindNoComments = GetGadgetState(#GADGET_Find_NoComments)
FindNoStrings = GetGadgetState(#GADGET_Find_NoStrings)
FindSelectionOnly = GetGadgetState(#GADGET_Find_SelectionOnly)
FindDoReplace = GetGadgetState(#GADGET_Find_DoReplace)
; save search strings
For i = 1 To FindHistorySize
If CountGadgetItems(#GADGET_Find_FindWord) >= i
FindSearchHistory(i) = GetGadgetItemText(#GADGET_Find_FindWord, i-1, 0)
Else
FindSearchHistory(i) = ""
EndIf
If CountGadgetItems(#GADGET_Find_ReplaceWord) >= i
FindReplaceHistory(i) = GetGadgetItemText(#GADGET_Find_ReplaceWord, i-1, 0)
Else
FindReplaceHistory(i) = ""
EndIf
Next i
If MemorizeWindow
FindWindowDialog\Close(@FindWindowPosition.DialogPosition)
Else
FindWindowDialog\Close()
EndIf
EndIf
EndProcedure