#FEATURE
authorClaus Gittinger <cg@exept.de>
Sun, 17 Jan 2016 20:14:38 +0100
changeset 5556 0a908345e353
parent 5555 7390d495b02c
child 5557 6578803bd491
#FEATURE class: TextView changed: #flyByHelpSpec #openSearchBoxAndSearch #searchDialogSpec added preserve case option in replace
TextView.st
--- a/TextView.st	Sun Jan 17 11:49:35 2016 +0100
+++ b/TextView.st	Sun Jan 17 20:14:38 2016 +0100
@@ -356,6 +356,17 @@
 #selectLines
 'If checked, lines containing the matched string are selected.'
 
+#replacePreserveCase
+'Preserve the case of replaced text'
+
+#replaceAll
+'Search and replace all occurrences of the searched string'
+
+#searchWithWrap
+'Wrap around at the end of the text, an continue the search from the top'
+
+#matchWithRegex
+'Use regex pattern for search (as opposed to glob pattern)'
 )
 ! !
 
@@ -452,6 +463,7 @@
                          enableChannel: match
                          model: matchWithRegex
                          translateLabel: true
+                         activeHelpKey: matchWithRegex
                        )
                       )
                     
@@ -506,7 +518,7 @@
                 (CheckBoxSpec
                    label: 'Wrap at End of Text (forward only)'
                    name: 'CheckBox7'
-                   activeHelpKey: searchAtBeginOfLineOnly
+                   activeHelpKey: searchWithWrap
                    level: 0
                    tabable: true
                    model: wrapAtEndOfTextHolder
@@ -551,9 +563,9 @@
                    extent: (Point 420 24)
                  )
                 (CheckBoxSpec
-                   label: 'Replace All (to End of Text)'
+                   label: '  Replace All (to End of Text)'
                    name: 'CheckBox8'
-                   activeHelpKey: searchAtBeginOfLineOnly
+                   activeHelpKey: replaceAll
                    level: 0
                    visibilityChannel: replaceBoolean
                    tabable: true
@@ -561,6 +573,17 @@
                    translateLabel: true
                    extent: (Point 420 24)
                  )
+                (CheckBoxSpec
+                   label: '  Preserve Case'
+                   name: 'CheckBox8'
+                   activeHelpKey: replacePreserveCase
+                   level: 0
+                   visibilityChannel: replaceBoolean
+                   tabable: true
+                   model: replacePreserveCaseBoolean
+                   translateLabel: true
+                   extent: (Point 420 24)
+                 )
                 )
               
              )
@@ -2228,7 +2251,7 @@
      fwd ign match initialString
      bindings bldr doSearch modal searchVariableHolder selectedVariable searchFullWordHolder
      replaceBooleanEnabledHolder replaceBooleanHolder replaceTextHolder
-     replaceAllBooleanHolder
+     replaceAllBooleanHolder replacePreserveCaseBooleanHolder
      searchAtBeginOfLineOnlyHolder updateReturnKeyBehavior|
 
     searchBarActionBlock notNil ifTrue:[
@@ -2249,8 +2272,9 @@
     searchVariableHolder := (lastSearchWasVariableSearch ? false) asValue.
     searchFullWordHolder := false asValue.
     searchAtBeginOfLineOnlyHolder := false asValue.
-    replaceBooleanHolder := (LastSearchWasReplace ? false) asValue.
+    replaceBooleanHolder := ("LastSearchWasReplace ?" false) asValue.
     replaceAllBooleanHolder := false asValue.
+    replacePreserveCaseBooleanHolder := false asValue.
     replaceTextHolder := (LastSearchReplacedString ? '') asValue.
     replaceBooleanEnabledHolder := self isReadOnly not asValue.
 
@@ -2300,7 +2324,7 @@
             LastSearchWasReplace :=replaceBooleanHolder value.
             LastSearchReplacedString := replaceTextHolder value.
             
-            pattern := patternHolder value.
+            pattern := patternHolder bla.
             pattern notEmptyOrNil ifTrue:[
                 searchAction := 
                     [
@@ -2320,8 +2344,9 @@
         ].
 
         replaceBooleanHolder value ifTrue:[
-            |selStart|
-
+            |selStart replacement replaceAction|
+
+            replacement := replaceTextHolder value.
             isVariableSearch ifTrue:[
                 "/ must replace from the end towards beginning,
                 "/ because syntax-elements do not update their position, when
@@ -2339,14 +2364,26 @@
                     ].
             ].
 
+            replaceAction := [ self replace:replacement ].
+            replacePreserveCaseBooleanHolder value ifTrue:[
+                replaceAction := [
+                    self selectionAsString isUppercaseFirst ifTrue:[
+                        self replace:replacement asUppercaseFirst
+                    ] ifFalse:[
+                        self replace:replacement asLowercaseFirst
+                    ]
+                ].    
+            ].    
+
             selStart := self characterPositionOfSelection.
-            self replace:(replaceTextHolder value).
-
+
+            replaceAction value.
             searchAction value.
+            
             replaceAllBooleanHolder value ifTrue:[
                 [self characterPositionOfSelection ~= selStart] whileTrue:[
                     selStart := self characterPositionOfSelection.
-                    self replace:(replaceTextHolder value).
+                    replaceAction value.
                     searchAction value.
                 ]
             ]
@@ -2413,20 +2450,25 @@
     bindings at:#replaceEnabled put:replaceBooleanEnabledHolder.
     bindings at:#replaceBoolean put:replaceBooleanHolder.
     bindings at:#replaceAllBoolean put:replaceAllBooleanHolder.
+    bindings at:#replacePreserveCaseBoolean put:replacePreserveCaseBooleanHolder.
     bindings at:#replaceTextHolder put:replaceTextHolder.
 
+    bindings at:#flyByHelpSpec put:self class flyByHelpSpec.
+    
     updateReturnKeyBehavior :=
         [
+            |lbl returnAction|
+            
             "/ when replacing, do not close box on return    
             replaceBooleanHolder value ifTrue:[
-                (bldr componentAt:#cancelButton)
-                        label:(resources string:'Close').
-                searchBox window keyboardProcessor returnAction:searchAction.        
+                lbl := 'Close'.
+                returnAction := searchAction.        
             ] ifFalse:[
-                (bldr componentAt:#cancelButton)
-                        label:(resources string:'Cancel').
-                searchBox window keyboardProcessor returnAction:nil.        
+                lbl := 'Cancel'.
+                returnAction := nil.        
             ].
+            (bldr componentAt:#cancelButton) label:(resources string:lbl).
+            searchBox window keyboardProcessor returnAction:returnAction.        
         ].
     
     replaceBooleanHolder onChangeEvaluate:
@@ -2458,7 +2500,7 @@
 
     modal ifTrue:[
         updateReturnKeyBehavior value.
-        searchBox openDialog.
+        searchBox openDialogAtPointer.
         searchBox accepted ifTrue:[ doSearch value:fwd ].
     ] ifFalse:[
         (bldr componentAt:#nextButton) isReturnButton:false.