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