author | Jan Vrany <jan.vrany@labware.com> |
Sat, 30 Sep 2023 22:55:25 +0100 | |
branch | jv |
changeset 19648 | 5df52d354504 |
parent 15566 | 184cea584be5 |
permissions | -rw-r--r-- |
8276 | 1 |
" |
2 |
COPYRIGHT (c) 2008 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
8049 | 12 |
"{ Package: 'stx:libtool' }" |
13 |
||
14 |
"{ NameSpace: Tools }" |
|
15 |
||
16 |
StringSearchTool subclass:#StringSearchToolForTextView |
|
8079 | 17 |
instanceVariableNames:'textView matchHolder' |
8915 | 18 |
classVariableNames:'LastMatch' |
8079 | 19 |
poolDictionaries:'' |
20 |
category:'Interface-Tools' |
|
8049 | 21 |
! |
22 |
||
8276 | 23 |
!StringSearchToolForTextView class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 2008 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! ! |
|
8049 | 38 |
|
8915 | 39 |
!StringSearchToolForTextView class methodsFor:'accessing'! |
40 |
||
41 |
lastMatch |
|
42 |
||
43 |
^ LastMatch ? false |
|
44 |
! |
|
45 |
||
46 |
lastMatch: aBoolean |
|
47 |
||
48 |
LastMatch := aBoolean |
|
49 |
! ! |
|
50 |
||
8049 | 51 |
!StringSearchToolForTextView class methodsFor:'interface specs'! |
52 |
||
8079 | 53 |
windowSpec |
54 |
"This resource specification was automatically generated |
|
55 |
by the UIPainter of ST/X." |
|
56 |
||
57 |
"Do not manually edit this!! If it is corrupted, |
|
58 |
the UIPainter may not be able to read the specification." |
|
59 |
||
60 |
" |
|
61 |
UIPainter new openOnClass:Tools::StringSearchToolForTextView andSelector:#windowSpec |
|
62 |
Tools::StringSearchToolForTextView new openInterface:#windowSpec |
|
63 |
Tools::StringSearchToolForTextView open |
|
64 |
" |
|
65 |
||
66 |
<resource: #canvas> |
|
67 |
||
68 |
^ |
|
69 |
#(FullSpec |
|
70 |
name: windowSpec |
|
71 |
window: |
|
72 |
(WindowSpec |
|
73 |
label: 'Tools::StringSearchTool' |
|
74 |
name: 'Tools::StringSearchTool' |
|
75 |
min: (Point 10 10) |
|
76 |
bounds: (Rectangle 0 0 883 27) |
|
77 |
) |
|
78 |
component: |
|
79 |
(SpecCollection |
|
80 |
collection: ( |
|
81 |
(ViewSpec |
|
82 |
name: 'SearchBox' |
|
83 |
layout: (LayoutFrame 0 0 0 0 0 1 0 1) |
|
84 |
level: -1 |
|
85 |
component: |
|
86 |
(SpecCollection |
|
87 |
collection: ( |
|
88 |
(ActionButtonSpec |
|
89 |
label: 'closeSearchBarIcon' |
|
90 |
name: 'hideSearchBarButton' |
|
91 |
layout: (LayoutFrame 1 0 2 0 22 0 23 0) |
|
92 |
hasCharacterOrientedLabel: false |
|
93 |
translateLabel: true |
|
94 |
model: hideSearchBar |
|
95 |
) |
|
96 |
(LabelSpec |
|
97 |
label: 'Search:' |
|
98 |
name: 'SearchLabel' |
|
99 |
layout: (LayoutFrame 23 0 1 0 71 0 23 0) |
|
100 |
translateLabel: true |
|
101 |
adjust: right |
|
102 |
) |
|
103 |
(InputFieldSpec |
|
104 |
name: 'SearchEntryField' |
|
105 |
layout: (LayoutFrame 72 0 1 0 253 0 23 0) |
|
106 |
model: searchTextHolder |
|
107 |
immediateAccept: true |
|
108 |
acceptOnReturn: true |
|
109 |
acceptOnTab: true |
|
110 |
acceptOnLostFocus: true |
|
111 |
modifiedChannel: searchTextModifiedHolder |
|
112 |
acceptOnPointerLeave: false |
|
113 |
postBuildCallback: postBuildSearchTextView: |
|
114 |
) |
|
115 |
(ActionButtonSpec |
|
116 |
label: 'searchNextIcon' |
|
117 |
name: 'SearchNextButton' |
|
118 |
layout: (LayoutFrame 258 0 2 0 279 0 23 0) |
|
119 |
hasCharacterOrientedLabel: false |
|
120 |
translateLabel: true |
|
121 |
model: searchNextTextButtonPressed |
|
122 |
) |
|
123 |
(ActionButtonSpec |
|
124 |
label: 'searchPreviousIcon' |
|
125 |
name: 'searchPreviousButton' |
|
126 |
layout: (LayoutFrame 286 0 2 0 307 0 23 0) |
|
127 |
hasCharacterOrientedLabel: false |
|
128 |
translateLabel: true |
|
129 |
model: searchPreviousTextButtonPressed |
|
130 |
) |
|
131 |
(CheckBoxSpec |
|
8925 | 132 |
label: 'Case' |
133 |
name: 'DoNotIgnoreCaseCheckBox' |
|
8956 | 134 |
layout: (LayoutFrame 312 0 1 0 396 0 23 0) |
135 |
model: matchCaseHolder |
|
8079 | 136 |
translateLabel: true |
137 |
) |
|
138 |
(CheckBoxSpec |
|
139 |
label: 'Match' |
|
140 |
name: 'MatchCheckBox' |
|
8956 | 141 |
layout: (LayoutFrame 396 0 1 0 480 0 23 0) |
8079 | 142 |
model: matchHolder |
143 |
translateLabel: true |
|
144 |
) |
|
145 |
(CheckBoxSpec |
|
146 |
label: 'Restart' |
|
147 |
name: 'RestartCheckBox' |
|
8956 | 148 |
layout: (LayoutFrame 480 0 1 0 564 0 23 0) |
8079 | 149 |
model: restartHolder |
150 |
translateLabel: true |
|
151 |
) |
|
152 |
(LabelSpec |
|
153 |
label: 'SearchBarImageInfoLabel' |
|
154 |
name: 'SearchBarImageInfoLabel' |
|
8956 | 155 |
layout: (LayoutFrame 564 0 1 0 588 0 23 0) |
8079 | 156 |
hasCharacterOrientedLabel: false |
157 |
translateLabel: true |
|
158 |
labelChannel: searchBarImageInfoLabelHolder |
|
159 |
) |
|
160 |
(LabelSpec |
|
161 |
label: 'SearchBarInfoLabel' |
|
162 |
name: 'SearchBarInfoLabel' |
|
8956 | 163 |
layout: (LayoutFrame 595 0 1 0 877 0 23 0) |
8079 | 164 |
translateLabel: true |
165 |
labelChannel: searchBarInfoLabelHolder |
|
166 |
adjust: left |
|
167 |
) |
|
168 |
) |
|
169 |
||
170 |
) |
|
171 |
) |
|
172 |
) |
|
173 |
||
174 |
) |
|
175 |
) |
|
176 |
! |
|
177 |
||
8070
2acefb7023d2
changed #matchCheckboxVisible
Claus Gittinger <cg@exept.de>
parents:
8064
diff
changeset
|
178 |
windowSpec_old |
8049 | 179 |
"This resource specification was automatically generated |
180 |
by the UIPainter of ST/X." |
|
181 |
||
182 |
"Do not manually edit this!! If it is corrupted, |
|
183 |
the UIPainter may not be able to read the specification." |
|
184 |
||
185 |
" |
|
8956 | 186 |
UIPainter new openOnClass:Tools::StringSearchToolForTextView andSelector:#windowSpec_old |
187 |
Tools::StringSearchToolForTextView new openInterface:#windowSpec_old |
|
8049 | 188 |
" |
189 |
||
190 |
<resource: #canvas> |
|
191 |
||
192 |
^ |
|
193 |
#(FullSpec |
|
8956 | 194 |
name: #'windowSpec_old' |
8049 | 195 |
window: |
196 |
(WindowSpec |
|
197 |
label: 'Tools::StringSearchTool' |
|
198 |
name: 'Tools::StringSearchTool' |
|
199 |
min: (Point 10 10) |
|
200 |
max: (Point 1024 768) |
|
8078 | 201 |
bounds: (Rectangle 0 0 883 27) |
8049 | 202 |
) |
203 |
component: |
|
204 |
(SpecCollection |
|
205 |
collection: ( |
|
206 |
(ViewSpec |
|
207 |
name: 'SearchBox' |
|
208 |
layout: (LayoutFrame 0 0 0 0 0 1 0 1) |
|
209 |
level: -1 |
|
210 |
component: |
|
211 |
(SpecCollection |
|
212 |
collection: ( |
|
213 |
(ActionButtonSpec |
|
214 |
label: 'closeSearchBarIcon' |
|
215 |
name: 'hideSearchBarButton' |
|
216 |
layout: (LayoutFrame 1 0 2 0 22 0 23 0) |
|
217 |
hasCharacterOrientedLabel: false |
|
218 |
translateLabel: true |
|
219 |
model: hideSearchBar |
|
220 |
) |
|
221 |
(LabelSpec |
|
222 |
label: 'Search:' |
|
223 |
name: 'SearchLabel' |
|
8062 | 224 |
layout: (LayoutFrame 23 0 1 0 71 0 23 0) |
8049 | 225 |
translateLabel: true |
226 |
adjust: right |
|
227 |
) |
|
228 |
(InputFieldSpec |
|
229 |
name: 'SearchEntryField' |
|
8062 | 230 |
layout: (LayoutFrame 72 0 1 0 253 0 23 0) |
8049 | 231 |
model: searchTextHolder |
232 |
immediateAccept: true |
|
233 |
acceptOnReturn: true |
|
234 |
acceptOnTab: true |
|
235 |
acceptOnLostFocus: true |
|
236 |
modifiedChannel: searchTextModifiedHolder |
|
237 |
acceptOnPointerLeave: false |
|
238 |
postBuildCallback: postBuildSearchTextView: |
|
239 |
) |
|
240 |
(ActionButtonSpec |
|
241 |
label: 'searchNextIcon' |
|
242 |
name: 'SearchNextButton' |
|
8062 | 243 |
layout: (LayoutFrame 258 0 2 0 279 0 23 0) |
8049 | 244 |
hasCharacterOrientedLabel: false |
245 |
translateLabel: true |
|
8078 | 246 |
model: searchNextTextButtonPressed |
8049 | 247 |
) |
248 |
(ActionButtonSpec |
|
249 |
label: 'searchPreviousIcon' |
|
250 |
name: 'searchPreviousButton' |
|
8062 | 251 |
layout: (LayoutFrame 286 0 2 0 307 0 23 0) |
8049 | 252 |
hasCharacterOrientedLabel: false |
253 |
translateLabel: true |
|
8078 | 254 |
model: searchPreviousTextButtonPressed |
8049 | 255 |
) |
256 |
(CheckBoxSpec |
|
8956 | 257 |
label: 'Case' |
258 |
name: 'CaseCheckBox' |
|
8062 | 259 |
layout: (LayoutFrame 312 0 1 0 424 0 23 0) |
8956 | 260 |
model: matchCaseHolder |
8049 | 261 |
translateLabel: true |
262 |
) |
|
263 |
(CheckBoxSpec |
|
264 |
label: 'Match' |
|
265 |
name: 'MatchCheckBox' |
|
8062 | 266 |
layout: (LayoutFrame 424 0 1 0 508 0 23 0) |
8049 | 267 |
model: matchHolder |
268 |
translateLabel: true |
|
269 |
) |
|
8078 | 270 |
(CheckBoxSpec |
271 |
label: 'Restart' |
|
272 |
name: 'RestartCheckBox' |
|
273 |
layout: (LayoutFrame 509 0 1 0 593 0 23 0) |
|
274 |
model: restartHolder |
|
275 |
translateLabel: true |
|
276 |
) |
|
8049 | 277 |
(LabelSpec |
278 |
label: 'SearchBarImageInfoLabel' |
|
279 |
name: 'SearchBarImageInfoLabel' |
|
8078 | 280 |
layout: (LayoutFrame 598 0 1 0 622 0 23 0) |
8049 | 281 |
hasCharacterOrientedLabel: false |
282 |
translateLabel: true |
|
283 |
labelChannel: searchBarImageInfoLabelHolder |
|
284 |
) |
|
285 |
(LabelSpec |
|
286 |
label: 'SearchBarInfoLabel' |
|
287 |
name: 'SearchBarInfoLabel' |
|
8078 | 288 |
layout: (LayoutFrame 633 0 1 0 882 0 23 0) |
8049 | 289 |
translateLabel: true |
290 |
labelChannel: searchBarInfoLabelHolder |
|
291 |
adjust: left |
|
292 |
) |
|
293 |
) |
|
294 |
||
295 |
) |
|
296 |
) |
|
297 |
) |
|
298 |
||
299 |
) |
|
300 |
) |
|
301 |
! ! |
|
302 |
||
303 |
!StringSearchToolForTextView methodsFor:'accessing'! |
|
304 |
||
305 |
textView |
|
306 |
^ textView |
|
307 |
! |
|
308 |
||
309 |
textView:something |
|
310 |
textView := something. |
|
311 |
! ! |
|
312 |
||
313 |
!StringSearchToolForTextView methodsFor:'aspects'! |
|
314 |
||
8070
2acefb7023d2
changed #matchCheckboxVisible
Claus Gittinger <cg@exept.de>
parents:
8064
diff
changeset
|
315 |
matchCheckboxVisible |
2acefb7023d2
changed #matchCheckboxVisible
Claus Gittinger <cg@exept.de>
parents:
8064
diff
changeset
|
316 |
^ true |
2acefb7023d2
changed #matchCheckboxVisible
Claus Gittinger <cg@exept.de>
parents:
8064
diff
changeset
|
317 |
! |
2acefb7023d2
changed #matchCheckboxVisible
Claus Gittinger <cg@exept.de>
parents:
8064
diff
changeset
|
318 |
|
8049 | 319 |
matchHolder |
320 |
||
321 |
matchHolder isNil ifTrue:[ |
|
8915 | 322 |
matchHolder := self class lastMatch asValue. |
8049 | 323 |
"/ if your app needs to be notified of changes, uncomment one of the lines below: |
324 |
"/ matchHolder addDependent:self. |
|
325 |
matchHolder onChangeSend:#matchHolderChanged to:self. |
|
326 |
||
327 |
]. |
|
328 |
^ matchHolder. |
|
329 |
||
330 |
"Created: / 16-06-2007 / 06:45:04 / Administrador" |
|
331 |
"Modified: / 16-06-2007 / 19:32:15 / Administrador" |
|
332 |
! ! |
|
333 |
||
334 |
!StringSearchToolForTextView methodsFor:'change & update'! |
|
335 |
||
336 |
matchHolderChanged |
|
337 |
||
338 |
self searchNextTextIncludingCurrentSelection: true. |
|
8062 | 339 |
self setFocusToSearchTextView. |
8915 | 340 |
self class lastMatch: self matchHolder value. |
8997 | 341 |
! |
342 |
||
343 |
searchTextModifiedHolderChanged |
|
344 |
||
345 |
|searchPattern| |
|
346 |
||
347 |
super searchTextModifiedHolderChanged. |
|
348 |
||
349 |
searchPattern := self searchText. |
|
350 |
"/ Transcript showCR: searchPattern. |
|
351 |
textView setSearchPattern: searchPattern. |
|
8049 | 352 |
! ! |
353 |
||
354 |
!StringSearchToolForTextView methodsFor:'initialization & release'! |
|
355 |
||
356 |
postBuildSearchTextView: anEditFieldView |
|
357 |
||
358 |
super postBuildSearchTextView: anEditFieldView. |
|
359 |
anEditFieldView crAction: self crAction. |
|
360 |
! ! |
|
361 |
||
8910 | 362 |
!StringSearchToolForTextView methodsFor:'misc'! |
363 |
||
364 |
trimMatchPattern: aString |
|
365 |
||
15289
a4b2c2b77420
class: Tools::StringSearchToolForTextView
Claus Gittinger <cg@exept.de>
parents:
9466
diff
changeset
|
366 |
^ aString trimForWhich: [:ch | ch == $*]. |
8910 | 367 |
|
368 |
" |
|
369 |
'***foo***' trimForWhich: [:ch | ch = $*]. |
|
370 |
'foo***' trimForWhich: [:ch | ch = $*]. |
|
371 |
'***foo' trimForWhich: [:ch | ch = $*]. |
|
372 |
'***f***o***o***' trimForWhich: [:ch | ch = $*]. |
|
373 |
'foo' trimForWhich: [:ch | ch = $*]. |
|
374 |
" |
|
375 |
! ! |
|
376 |
||
8049 | 377 |
!StringSearchToolForTextView methodsFor:'public'! |
378 |
||
379 |
crAction |
|
380 |
||
381 |
^ [self returnFocusToTextView] |
|
382 |
! |
|
383 |
||
8085 | 384 |
escapePressed |
385 |
||
386 |
self returnFocusToTextView. |
|
387 |
super escapePressed. |
|
388 |
! |
|
389 |
||
8049 | 390 |
returnFocusToTextView |
391 |
||
392 |
textView takeFocus |
|
8910 | 393 |
! |
394 |
||
395 |
searchPreviousTextReachBeginning |
|
396 |
|message searchText match | |
|
397 |
||
8997 | 398 |
searchText := self searchText. |
8910 | 399 |
match := self matchHolder value. |
400 |
||
401 |
match ifTrue: [ |
|
402 |
searchText := self trimMatchPattern: searchText. |
|
403 |
(searchText includes: $*) ifTrue: [ |
|
8958 | 404 |
message := (resources string: 'Match pattern not available for backward search'). |
8910 | 405 |
self searchTextNotFound: message. |
406 |
Smalltalk beep. |
|
407 |
^ self |
|
408 |
]. |
|
409 |
]. |
|
410 |
||
411 |
super searchPreviousTextReachBeginning |
|
8049 | 412 |
! ! |
413 |
||
414 |
!StringSearchToolForTextView methodsFor:'searching'! |
|
415 |
||
416 |
hideSearchBar |
|
417 |
||
418 |
masterApplication isNil ifTrue:[^ self]. |
|
419 |
masterApplication hideSearchBar. |
|
420 |
self returnFocusToTextView. |
|
421 |
! |
|
422 |
||
423 |
searchNextTextFromBeginning |
|
424 |
|searchText ignoreCase match absentBlock| |
|
425 |
||
8997 | 426 |
searchText := self searchText. |
8049 | 427 |
searchText isEmptyOrNil ifTrue:[^self]. |
428 |
self textView isNil ifTrue:[^ self]. |
|
8956 | 429 |
ignoreCase := self ignoreCase. |
8049 | 430 |
match := self matchHolder value. |
431 |
absentBlock := [self searchTextNotFound.]. |
|
432 |
self textView |
|
433 |
searchFwd:searchText |
|
434 |
ignoreCase:ignoreCase |
|
435 |
match: match |
|
436 |
startingAtLine:1 |
|
437 |
col:0 |
|
438 |
ifAbsent:absentBlock |
|
439 |
! |
|
440 |
||
441 |
searchNextTextIncludingCurrentSelection: includeCurrentSelection |
|
8956 | 442 |
|searchText ignoreCase match absentBlock startCol startLine | |
8049 | 443 |
|
444 |
self searchTextStarted. |
|
8997 | 445 |
searchText := self searchText. |
8049 | 446 |
searchText isEmptyOrNil ifTrue:[^self]. |
447 |
self textView isNil ifTrue:[^ self]. |
|
8956 | 448 |
ignoreCase := self ignoreCase. |
8049 | 449 |
match := self matchHolder value. |
450 |
absentBlock := [self searchNextTextReachEnd]. |
|
8956 | 451 |
|
8049 | 452 |
(self textView hasSelection and:[includeCurrentSelection]) |
453 |
ifTrue:[ |
|
8064 | 454 |
startCol := ((self textView selectionStartCol ? 1) - 2) max: 0. |
8049 | 455 |
startLine := (self textView selectionStartLine ? 1). |
456 |
self textView searchFwd:searchText ignoreCase:ignoreCase match: match startingAtLine:startLine col:startCol ifAbsent:absentBlock. |
|
8956 | 457 |
] ifFalse:[ |
458 |
self textView startPositionForSearchForward = (0 @ 1) ifTrue: [ |
|
459 |
absentBlock := [self searchTextNotFound]. |
|
460 |
]. |
|
8049 | 461 |
self textView searchFwd:searchText ignoreCase:ignoreCase match: match ifAbsent:absentBlock |
462 |
]. |
|
463 |
! |
|
464 |
||
465 |
searchPreviousText |
|
466 |
||
8910 | 467 |
|searchText ignoreCase match absentBlock| |
8049 | 468 |
|
469 |
self searchTextStarted. |
|
8997 | 470 |
searchText := self searchText. |
8049 | 471 |
searchText isEmptyOrNil ifTrue:[^self]. |
8956 | 472 |
ignoreCase := self ignoreCase. |
8049 | 473 |
self textView isNil ifTrue:[^ self]. |
8910 | 474 |
match := self matchHolder value. |
475 |
match ifTrue: [ |
|
476 |
searchText := self trimMatchPattern: searchText. |
|
477 |
]. |
|
8049 | 478 |
absentBlock := [self searchPreviousTextReachBeginning]. |
479 |
self textView searchBwd:searchText ignoreCase:ignoreCase ifAbsent:absentBlock. |
|
480 |
! |
|
481 |
||
482 |
searchPreviousTextFromEnd |
|
483 |
||
484 |
|searchText ignoreCase absentBlock startLine startCol| |
|
485 |
||
8997 | 486 |
searchText := self searchText. |
8049 | 487 |
searchText isEmptyOrNil ifTrue:[^self]. |
8956 | 488 |
ignoreCase := self ignoreCase. |
8049 | 489 |
self textView isNil ifTrue:[^ self]. |
490 |
absentBlock := [self searchTextNotFound.]. |
|
491 |
startLine := self textView numberOfLines + 1. |
|
492 |
startCol := 1. |
|
493 |
self textView |
|
494 |
searchBwd:searchText |
|
495 |
ignoreCase:ignoreCase |
|
496 |
startingAtLine:startLine |
|
497 |
col:startCol |
|
498 |
ifAbsent:absentBlock |
|
499 |
! ! |
|
500 |
||
501 |
!StringSearchToolForTextView class methodsFor:'documentation'! |
|
502 |
||
503 |
version |
|
15289
a4b2c2b77420
class: Tools::StringSearchToolForTextView
Claus Gittinger <cg@exept.de>
parents:
9466
diff
changeset
|
504 |
^ '$Header: /cvs/stx/stx/libtool/Tools__StringSearchToolForTextView.st,v 1.17 2015-02-13 21:58:38 cg Exp $' |
8910 | 505 |
! |
506 |
||
507 |
version_CVS |
|
15289
a4b2c2b77420
class: Tools::StringSearchToolForTextView
Claus Gittinger <cg@exept.de>
parents:
9466
diff
changeset
|
508 |
^ '$Header: /cvs/stx/stx/libtool/Tools__StringSearchToolForTextView.st,v 1.17 2015-02-13 21:58:38 cg Exp $' |
8049 | 509 |
! ! |
15289
a4b2c2b77420
class: Tools::StringSearchToolForTextView
Claus Gittinger <cg@exept.de>
parents:
9466
diff
changeset
|
510 |