felix' search refactoring
authorfm
Mon, 24 Jul 2006 14:25:32 +0200
changeset 3318 ebd115677fd5
parent 3317 1a45a2a1a47c
child 3319 da288f73ea71
felix' search refactoring
TextView.st
--- a/TextView.st	Mon Jul 24 14:22:21 2006 +0200
+++ b/TextView.st	Mon Jul 24 14:25:32 2006 +0200
@@ -1,6 +1,6 @@
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
-	      All Rights Reserved
+              All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -13,24 +13,24 @@
 "{ Package: 'stx:libwidg' }"
 
 ListView subclass:#TextView
-	instanceVariableNames:'selectionStartLine selectionStartCol selectionEndLine
-		selectionEndCol clickPos clickStartLine clickStartCol clickLine
-		clickCol clickCount expandingTop wordStartCol wordStartLine
-		wordEndCol wordEndLine selectionFgColor selectionBgColor
-		selectStyle directoryForFileDialog defaultFileNameForFileDialog
-		externalEncoding contentsWasSaved searchAction lastSearchPattern
-		lastSearchIgnoredCase lastSearchDirection
-		parenthesisSpecification dropSource dragIsActive saveAction
-		st80SelectMode'
-	classVariableNames:'DefaultViewBackground DefaultSelectionForegroundColor
-		DefaultSelectionBackgroundColor
-		DefaultAlternativeSelectionForegroundColor
-		DefaultAlternativeSelectionBackgroundColor MatchDelayTime
-		WordSelectCatchesBlanks LastSearchPatterns
-		NumRememberedSearchPatterns LastSearchIgnoredCase
-		DefaultParenthesisSpecification'
-	poolDictionaries:''
-	category:'Views-Text'
+        instanceVariableNames:'selectionStartLine selectionStartCol selectionEndLine
+                selectionEndCol clickPos clickStartLine clickStartCol clickLine
+                clickCol clickCount expandingTop wordStartCol wordStartLine
+                wordEndCol wordEndLine selectionFgColor selectionBgColor
+                selectStyle directoryForFileDialog defaultFileNameForFileDialog
+                externalEncoding contentsWasSaved searchAction lastSearchPattern
+                lastSearchIgnoredCase lastSearchDirection
+                parenthesisSpecification dropSource dragIsActive saveAction
+                st80SelectMode'
+        classVariableNames:'DefaultViewBackground DefaultSelectionForegroundColor
+                DefaultSelectionBackgroundColor
+                DefaultAlternativeSelectionForegroundColor
+                DefaultAlternativeSelectionBackgroundColor MatchDelayTime
+                WordSelectCatchesBlanks LastSearchPatterns
+                NumRememberedSearchPatterns LastSearchIgnoredCase
+                DefaultParenthesisSpecification'
+        poolDictionaries:''
+        category:'Views-Text'
 !
 
 !TextView class methodsFor:'documentation'!
@@ -38,7 +38,7 @@
 copyright
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
-	      All Rights Reserved
+              All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -126,18 +126,18 @@
     they may also be opened as a textEditor;
 
     open a (readonly) textView on some information text:
-							[exBegin]
-	TextView 
-	    openWith:'read this' 
-	    title:'demonstration'
-							[exEnd]
+                                                        [exBegin]
+        TextView 
+            openWith:'read this' 
+            title:'demonstration'
+                                                        [exEnd]
 
     the same, but open it modal:
-							[exBegin]
-	TextView 
-	    openModalWith:'read this first' 
-	    title:'demonstration'
-							[exEnd]
+                                                        [exBegin]
+        TextView 
+            openModalWith:'read this first' 
+            title:'demonstration'
+                                                        [exEnd]
 
 
     open it modal (but editable) on some text:
@@ -148,26 +148,26 @@
     However, usually an applicationModel is installed as the
     editor-topViews application. This would get a closeRequest,
     where it could handle things.
-							[exBegin]
-	|m textView|
-
-	m := 'read this first' asValue.
-	textView := EditTextView openModalOnModel:m.
-	textView modified ifTrue:[
-	    (self confirm:'text was not accepted - do it now ?')
-	    ifTrue:[
-		m value:textView contents
-	    ]
-	].
-
-	Transcript showCR:m value.
-							[exEnd]
+                                                        [exBegin]
+        |m textView|
+
+        m := 'read this first' asValue.
+        textView := EditTextView openModalOnModel:m.
+        textView modified ifTrue:[
+            (self confirm:'text was not accepted - do it now ?')
+            ifTrue:[
+                m value:textView contents
+            ]
+        ].
+
+        Transcript showCR:m value.
+                                                        [exEnd]
 
 
     open a textEditor on some file:
-							[exBegin]
-	EditTextView openOn:'Makefile'
-							[exEnd]
+                                                        [exBegin]
+        EditTextView openOn:'Makefile'
+                                                        [exEnd]
 
 "
 
@@ -179,12 +179,12 @@
     "for ST-80 compatibility"
 
     ^ (self new) 
-	on:aModel 
-	aspect:aspect
-	list:aspect
-	change:change 
-	menu:menu
-	initialSelection:initial
+        on:aModel 
+        aspect:aspect
+        list:aspect
+        change:change 
+        menu:menu
+        initialSelection:initial
 !
 
 with:someText
@@ -544,9 +544,9 @@
     top := StandardSystemView label:label icon:self defaultIcon.
 
     frame := HVScrollableView 
-		for:self 
-		miniScrollerH:true miniScrollerV:false
-		in:top.
+                for:self 
+                miniScrollerH:true miniScrollerV:false
+                in:top.
     frame origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
     ^ frame scrolledView
 
@@ -561,9 +561,9 @@
     textView := self setupEmpty.
     top := textView topView.
     aFileName notNil ifTrue:[
-	f := aFileName asFilename.
-	top label:(f baseName).
-	textView contents:(f contents).
+        f := aFileName asFilename.
+        top label:(f baseName).
+        textView contents:(f contents).
     ].
 
     ^ textView
@@ -593,7 +593,7 @@
     aTitle notNil ifTrue:[top label:aTitle].
 
     aStringOrStringCollection notNil ifTrue:[
-	textView contents:aStringOrStringCollection
+        textView contents:aStringOrStringCollection
     ].
 
     ^ textView
@@ -674,7 +674,7 @@
 
     selectionStartLine isNil ifTrue:[^ 0].
     ^ self characterPositionOfLine:selectionStartLine
-			       col:selectionStartCol
+                               col:selectionStartCol
 
     "Modified: 14.8.1997 / 16:35:37 / cg"
 !
@@ -819,9 +819,9 @@
     super setContents:something.
 
     selStartLine notNil ifTrue:[
-	self 
-	    selectFromLine:selStartLine col:selStartCol
-	    toLine:selEndLine col:selEndCol.
+        self 
+            selectFromLine:selStartLine col:selStartCol
+            toLine:selEndLine col:selEndCol.
     ].
 
     selectStyle := selStyle
@@ -861,35 +861,35 @@
     beginCol := self findBeginOfWordAtLine:selectLine col:selectCol.
     endCol := self findEndOfWordAtLine:selectLine col:selectCol.
     endCol == 0 ifTrue:[
-	endLine := selectLine + 1
+        endLine := selectLine + 1
     ].
 
     "is the initial character within a word ?"
     (wordCheck value:thisCharacter) ifTrue:[
-	"
-	 try to catch a blank ...
-	"
-
-	WordSelectCatchesBlanks ifTrue:[
-	    ((beginCol == 1)
-	    or:[(self characterAtLine:selectLine col:(beginCol - 1))
-		 ~~ Character space]) ifTrue:[
-		((self characterAtLine:selectLine col:(endCol + 1))
-		  == Character space) ifTrue:[
-		    endCol := endCol + 1.
-		    flag := #wordRight
-		]
-	    ] ifFalse:[
-		beginCol := beginCol - 1.
-		flag := #wordLeft
-	    ].
-	].
+        "
+         try to catch a blank ...
+        "
+
+        WordSelectCatchesBlanks ifTrue:[
+            ((beginCol == 1)
+            or:[(self characterAtLine:selectLine col:(beginCol - 1))
+                 ~~ Character space]) ifTrue:[
+                ((self characterAtLine:selectLine col:(endCol + 1))
+                  == Character space) ifTrue:[
+                    endCol := endCol + 1.
+                    flag := #wordRight
+                ]
+            ] ifFalse:[
+                beginCol := beginCol - 1.
+                flag := #wordLeft
+            ].
+        ].
     ].
     aFiveArgBlock value:selectLine 
-		  value:beginCol 
-		  value:endLine 
-		  value:endCol
-		  value:flag
+                  value:beginCol 
+                  value:endLine 
+                  value:endCol
+                  value:flag
 
     "Modified: 18.3.1996 / 17:31:04 / cg"
 ! !
@@ -929,7 +929,7 @@
      and selection. Added for ST-80 compatibility"
 
     aspectSym notNil ifTrue:[aspectMsg := aspectSym. 
-			     listMsg isNil ifTrue:[listMsg := aspectSym]].
+                             listMsg isNil ifTrue:[listMsg := aspectSym]].
     changeSym notNil ifTrue:[changeMsg := changeSym].
     listSym notNil ifTrue:[listMsg := listSym].
     menuSym notNil ifTrue:[menuMsg := menuSym].
@@ -1634,21 +1634,21 @@
     selectionFgColor isNil ifTrue:[selectionFgColor := bgColor].
     selectionBgColor := DefaultSelectionBackgroundColor.
     selectionBgColor isNil ifTrue:[
-	device hasColors ifTrue:[
-	    DefaultSelectionForegroundColor isNil ifTrue:[
-		selectionFgColor := fgColor
-	    ].
-	    selectionBgColor := Color green
-	] ifFalse:[
-	    device hasGrayscales ifTrue:[
-		DefaultSelectionForegroundColor isNil ifTrue:[
-		    selectionFgColor := fgColor
-		].
-		selectionBgColor := Color grey
-	    ] ifFalse:[
-		selectionBgColor := fgColor
-	    ]
-	]
+        device hasColors ifTrue:[
+            DefaultSelectionForegroundColor isNil ifTrue:[
+                selectionFgColor := fgColor
+            ].
+            selectionBgColor := Color green
+        ] ifFalse:[
+            device hasGrayscales ifTrue:[
+                DefaultSelectionForegroundColor isNil ifTrue:[
+                    selectionFgColor := fgColor
+                ].
+                selectionBgColor := Color grey
+            ] ifFalse:[
+                selectionBgColor := fgColor
+            ]
+        ]
     ].
 
     "Modified: 22.1.1997 / 11:57:53 / cg"
@@ -1922,8 +1922,7 @@
      Q: is it a good idea to preserve the last searchstring between views ?
     "
 
-    |searchBox patternHolder caseHolder 
-     pattern fwd ign initialString
+    |searchBox patternHolder caseHolder fwd ign initialString
      bindings bldr search modal|
 
     modal := (UserPreferences current searchDialogIsModal).   "/ thats experimental
@@ -1952,22 +1951,7 @@
     fwd := true. 
 
     search := [:fwd |
-        pattern := patternHolder value.
-        pattern := pattern string. "/ is that a good idea ?
-        pattern notEmpty ifTrue:[
-            self rememberSearchPattern:pattern.
-
-            ign := caseHolder value.
-            LastSearchIgnoredCase := ign.
-
-            fwd ifFalse:[
-                lastSearchDirection := #backward.
-                self searchBwd:pattern ignoreCase:ign.
-            ] ifTrue:[
-                lastSearchDirection := #forward.
-                self searchFwd:pattern ignoreCase:ign.
-            ]
-        ]
+        self search:patternHolder value ignoreCase:caseHolder value forward:fwd.
     ].
 
     bindings := IdentityDictionary new.
@@ -2015,6 +1999,27 @@
         "/ searchBox window open.
         searchBox window assignKeyboardFocusToFirstInputField.
     ]
+
+    "Modified: / 11-07-2006 / 11:18:38 / fm"
+!
+
+search:patternArg ignoreCase:ign forward:fwd 
+    |pattern|
+
+    pattern := patternArg string.
+    pattern notEmpty ifTrue:[
+        self rememberSearchPattern:pattern.
+        LastSearchIgnoredCase := ign.
+        fwd ifFalse:[
+            lastSearchDirection := #backward.
+            self searchBwd:pattern ignoreCase:ign.
+        ] ifTrue:[
+            lastSearchDirection := #forward.
+            self searchFwd:pattern ignoreCase:ign.
+        ]
+    ]
+
+    "Created: / 11-07-2006 / 11:18:04 / fm"
 ! !
 
 !TextView methodsFor:'private'!
@@ -2031,8 +2036,8 @@
     "save contents on a stream, replacing leading spaces by tab-characters."
 
     self 
-	fileOutContentsOn:aStream 
-	compressTabs:true
+        fileOutContentsOn:aStream 
+        compressTabs:true
 !
 
 fileOutContentsOn:aStream compressTabs:compressTabs
@@ -2040,9 +2045,9 @@
      leading spaces will be replaced by tab-characters in the output."
 
     self 
-	fileOutContentsOn:aStream 
-	compressTabs:compressTabs 
-	encoding:nil
+        fileOutContentsOn:aStream 
+        compressTabs:compressTabs 
+        encoding:nil
 !
 
 fileOutContentsOn:aStream compressTabs:compressTabs encoding:encodingSymOrNil
@@ -2160,7 +2165,7 @@
     selectionEndLine := firstLineShown + nFullLinesShown.
     selectionEndCol := 0.
     prevEndLine to:selectionEndLine do:[:lineNr |
-	self redrawLine:lineNr
+        self redrawLine:lineNr
     ].
     Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT.
 !
@@ -2212,7 +2217,7 @@
     selectionStartLine := firstLineShown.
     selectionStartCol := 1.
     selectionStartLine to:prevStartLine do:[:lineNr |
-	self redrawLine:lineNr
+        self redrawLine:lineNr
     ].
     Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT.
 !
@@ -2221,10 +2226,10 @@
     "stop auto scroll; deinstall timed-block"
 
     autoScrollBlock notNil ifTrue:[
-	Processor removeTimedBlock:autoScrollBlock.
-	self compressMotionEvents:true.
-	autoScrollBlock := nil.
-	autoScrollDeltaT := nil
+        Processor removeTimedBlock:autoScrollBlock.
+        self compressMotionEvents:true.
+        autoScrollBlock := nil.
+        autoScrollDeltaT := nil
     ]
 !
 
@@ -2232,11 +2237,11 @@
     "return the width in pixels for a scroll between firstLine and lastLine"
 
     selectionStartLine notNil ifTrue:[
-	(lastLine < selectionStartLine) ifFalse:[
-	    (firstLine > selectionEndLine) ifFalse:[
-		^ width
-	    ]
-	]
+        (lastLine < selectionStartLine) ifFalse:[
+            (firstLine > selectionEndLine) ifFalse:[
+                ^ width
+            ]
+        ]
     ].
     ^ super widthForScrollBetween:firstLine and:lastLine
 ! !
@@ -2264,11 +2269,11 @@
     "if there is a margin, clear it - a helper for selection drawing"
 
     (leftMargin ~~ 0) ifTrue:[
-	self paint:color.
-	self fillRectangleX:margin
-			  y:(self yOfVisibleLine:visLine)
-		      width:leftMargin
-		     height:fontHeight
+        self paint:color.
+        self fillRectangleX:margin
+                          y:(self yOfVisibleLine:visLine)
+                      width:leftMargin
+                     height:fontHeight
     ]
 
     "Created: 6.3.1996 / 14:22:55 / cg"
@@ -3361,14 +3366,14 @@
 
     realPattern := pattern.
     (realPattern startsWith:$*) ifTrue:[
-	realPattern := realPattern copyFrom:2
+        realPattern := realPattern copyFrom:2
     ].
     (realPattern endsWith:$*) ifTrue:[
-	realPattern := realPattern copyWithoutLast:1
+        realPattern := realPattern copyWithoutLast:1
     ].
 
     self selectFromLine:line col:col
-		 toLine:line col:(col + realPattern size - 1).
+                 toLine:line col:(col + realPattern size - 1).
     self makeLineVisible:line
 !
 
@@ -3652,35 +3657,35 @@
 
     self unselect.
     startLine notNil ifTrue:[
-	"new:"
-	endLine < startLine ifTrue:[
-	    ^ self selectFromLine:endLine col:endCol toLine:startLine col:startCol
-	].
-	(endLine == startLine and:[endCol < startCol]) ifTrue:[
-	    endCol ~~ 0 ifTrue:[
-		self selectFromLine:endLine col:endCol toLine:startLine col:startCol.
-	    ].
-	    ^ self
-	].
+        "new:"
+        endLine < startLine ifTrue:[
+            ^ self selectFromLine:endLine col:endCol toLine:startLine col:startCol
+        ].
+        (endLine == startLine and:[endCol < startCol]) ifTrue:[
+            endCol ~~ 0 ifTrue:[
+                self selectFromLine:endLine col:endCol toLine:startLine col:startCol.
+            ].
+            ^ self
+        ].
 
 " old:
-	endLine < startLine ifTrue:[^ self].
-	(startLine == endLine and:[endCol < startCol]) ifTrue:[^ self].
+        endLine < startLine ifTrue:[^ self].
+        (startLine == endLine and:[endCol < startCol]) ifTrue:[^ self].
 "
-	selectionStartLine := startLine.
-	selectionStartCol := startCol.
-	selectionEndLine := endLine.
-	selectionEndCol := endCol.
-	self validateNewSelection.
-
-	(selectionStartLine == selectionEndLine) ifTrue:[
-	    self redrawLine:selectionStartLine from:selectionStartCol to:selectionEndCol
-	] ifFalse:[
-	    selectionStartLine to:selectionEndLine do:[:lineNr |
-		self redrawLine:lineNr
-	    ]
-	].
-	selectStyle := nil.
+        selectionStartLine := startLine.
+        selectionStartCol := startCol.
+        selectionEndLine := endLine.
+        selectionEndCol := endCol.
+        self validateNewSelection.
+
+        (selectionStartLine == selectionEndLine) ifTrue:[
+            self redrawLine:selectionStartLine from:selectionStartCol to:selectionEndCol
+        ] ifFalse:[
+            selectionStartLine to:selectionEndLine do:[:lineNr |
+                self redrawLine:lineNr
+            ]
+        ].
+        selectStyle := nil.
     ]
 
     "
@@ -3753,10 +3758,10 @@
     "select the word at given line/col"
 
     self wordAtLine:line col:col do:[
-	:beginLine :beginCol :endLine :endCol :style |
-
-	self selectFromLine:beginLine col:beginCol toLine:endLine col:endCol.
-	selectStyle := style
+        :beginLine :beginCol :endLine :endCol :style |
+
+        self selectFromLine:beginLine col:beginCol toLine:endLine col:endCol.
+        selectStyle := style
     ]
 
     "Modified: 18.3.1996 / 17:30:38 / cg"
@@ -3771,8 +3776,8 @@
     selectVisibleLine := self visibleLineOfY:y.
     selectLine := self visibleLineToListLine:selectVisibleLine.
     selectLine notNil ifTrue:[
-	selectCol := self colOfX:x inVisibleLine:selectVisibleLine.
-	self selectWordAtLine:selectLine col:selectCol
+        selectCol := self colOfX:x inVisibleLine:selectVisibleLine.
+        self selectWordAtLine:selectLine col:selectCol
     ]
 
     "Modified: / 8.9.1998 / 21:22:46 / cg"
@@ -3835,34 +3840,34 @@
     |startLine endLine startVisLine endVisLine|
 
     selectionStartLine notNil ifTrue:[
-	startLine := selectionStartLine.
-	endLine := selectionEndLine.
-
-	self unselectWithoutRedraw.
-
-	"/ if the selection is not visible, we are done
-
-	startLine >= (firstLineShown + nLinesShown) ifTrue:[^ self].
-	endLine < firstLineShown ifTrue:[^ self].
-
-	startLine < firstLineShown ifTrue:[
-	    startVisLine := 1
-	] ifFalse:[
-	    startVisLine := self listLineToVisibleLine:startLine
-	].
-	endLine >= (firstLineShown + nLinesShown) ifTrue:[
-	    endVisLine := nLinesShown
-	] ifFalse:[
-	    endVisLine := self listLineToVisibleLine:endLine
-	].
-
-	"/ if its only part of a line, just redraw what has to be
-
-	(startLine == endLine) ifTrue:[
-	    super redrawVisibleLine:startVisLine from:selectionStartCol to:selectionEndCol
-	] ifFalse:[
-	    self redrawFromVisibleLine:startVisLine to:endVisLine
-	].
+        startLine := selectionStartLine.
+        endLine := selectionEndLine.
+
+        self unselectWithoutRedraw.
+
+        "/ if the selection is not visible, we are done
+
+        startLine >= (firstLineShown + nLinesShown) ifTrue:[^ self].
+        endLine < firstLineShown ifTrue:[^ self].
+
+        startLine < firstLineShown ifTrue:[
+            startVisLine := 1
+        ] ifFalse:[
+            startVisLine := self listLineToVisibleLine:startLine
+        ].
+        endLine >= (firstLineShown + nLinesShown) ifTrue:[
+            endVisLine := nLinesShown
+        ] ifFalse:[
+            endVisLine := self listLineToVisibleLine:endLine
+        ].
+
+        "/ if its only part of a line, just redraw what has to be
+
+        (startLine == endLine) ifTrue:[
+            super redrawVisibleLine:startVisLine from:selectionStartCol to:selectionEndCol
+        ] ifFalse:[
+            self redrawFromVisibleLine:startVisLine to:endVisLine
+        ].
     ].
     selectStyle := nil
 
@@ -3890,7 +3895,7 @@
 !TextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.269 2006-07-17 10:58:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.270 2006-07-24 12:25:32 fm Exp $'
 ! !
 
 TextView initialize!