#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Mon, 06 Jun 2016 11:10:34 +0200
changeset 5761 0b2929b446e9
parent 5759 df4a9cdcf3b7
child 5762 42aeb0e32655
#FEATURE by cg class: EditTextView added:9 methods comment/format in: #parenthizeSelectionWith:and: changed: #convertSelectionToLowercaseOrUppercaseOrUppercaseFirst
EditTextView.st
--- a/EditTextView.st	Thu May 19 02:49:11 2016 +0200
+++ b/EditTextView.st	Mon Jun 06 11:10:34 2016 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
               All Rights Reserved
@@ -2455,6 +2457,30 @@
     "Modified: / 30.3.1999 / 16:02:34 / stefan"
 !
 
+singleQuoteSelection
+    "place single quotes around the selected text"
+
+    |line1 col1 line2 col2|
+
+    line1 := self selectionStartLine.
+    col1 := self selectionStartCol.
+    line2 := self selectionEndLine.
+    col2 := self selectionEndCol.
+    (line1 notNil
+        and:[ col1 notNil
+        and:[ line2 notNil
+        and:[ col2 notNil ]]])
+    ifTrue:[
+        self insertString:Character quote asString atLine:line2 col:col2+1.
+        self insertString:Character quote asString atLine:line1 col:col1.
+        self selectFromLine:line1 col:col1 toLine:line2 col:col2+2.
+    ] ifFalse:[
+        self beep.
+    ]
+
+    "Created: / 06-06-2016 / 11:03:36 / cg"
+!
+
 undrawCursor
     "undraw the cursor (i.e. redraw the character(s) under the cursor)"
 
@@ -2757,8 +2783,8 @@
 
 !EditTextView methodsFor:'editing'!
 
-convertSelectionToLowercaseOrUppercaseOrUppercaseFirst
-    "toLower/toUppercaseFirst/toUpper selected text"
+applyConverterToSelection:converter
+    "apply a converter to the selected text"
 
     |line1 line2|
 
@@ -2772,8 +2798,7 @@
     ].
     line1 notNil ifTrue:[
         line1 to:line2 do:[:lineNr |
-            |line col1 col2 isAllLower isLowerFirst isAllUpper isUpperFirst
-             makeLowercase makeUppercase makeUppercaseFirst makeLowercaseFirst|
+            |line col1 col2 newLine|
 
             line := (self listAt:lineNr) copy.
             line size > 0 ifTrue:[
@@ -2787,75 +2812,148 @@
                 ] ifFalse:[
                     col2 := (self listAt:lineNr) size.
                 ].
-                isAllLower := isAllUpper := isUpperFirst := isLowerFirst := true.
+                newLine := converter value:line value:lineNr value:col1 value:col2.
+                self withoutRedrawAt:lineNr put:newLine.
+                self invalidateLine:lineNr.
+            ].
+        ].
+    ]
+
+    "Created: / 06-06-2016 / 10:53:17 / cg"
+!
+
+convertSelectionToLowercase
+    "to-lower selected text"
+
+    self applyConverterToSelection:[:line :lnr :col1 :col2 |
+        col1 to:col2 do:[:col |
+            |ch|
+
+            ch := line at:col.
+            line at:col put:ch asLowercase.
+        ].
+        line.        
+    ].
+
+    "Created: / 06-06-2016 / 10:50:28 / cg"
+!
+
+convertSelectionToLowercaseOrUppercaseOrUppercaseFirst
+    "toLower/toUppercaseFirst/toUpper selected text"
+
+    self applyConverterToSelection:[:line :lineNr :col1 :col2 |
+        |isAllLower isLowerFirst isAllUpper isUpperFirst
+         makeLowercase makeUppercase makeUppercaseFirst makeLowercaseFirst|
+
+        isAllLower := isAllUpper := isUpperFirst := isLowerFirst := true.
+        col1 to:col2 do:[:col |
+            |ch|
+
+            ch := line at:col.
+            ch isUppercase ifTrue:[
+                isAllLower := false.
+                col == col1 ifTrue:[
+                    isLowerFirst := false.
+                ].
+            ] ifFalse:[
+                ch isLowercase ifTrue:[
+                    isAllUpper := false.
+                    col == col1 ifTrue:[
+                        isUpperFirst := false.
+                    ].
+                ]
+            ].
+        ].
+
+        makeLowercase := makeUppercase := makeUppercaseFirst := makeLowercaseFirst := false.
+        isLowerFirst ifTrue:[
+            makeUppercaseFirst := true.
+        ] ifFalse:[
+            "/ must remember where we come from - otherwise, we end up
+            "/ in upperFirst - lowerFirst cycle.
+            "/ think about a good place to store this state
+            false "(isUpperFirst and:[isAllUpper not])" ifTrue:[
+                makeLowercaseFirst := true.
+             ] ifFalse:[
+                isAllUpper ifTrue:[
+                    makeLowercase := true.
+                ] ifFalse:[
+                    makeUppercase := true.
+                ]
+            ]
+        ].
+        makeUppercaseFirst ifTrue:[
+            line at:col1 put:(line at:col1) asUppercase.
+        ] ifFalse:[
+            makeLowercaseFirst ifTrue:[
+                line at:col1 put:(line at:col1) asLowercase.
+            ] ifFalse:[
                 col1 to:col2 do:[:col |
                     |ch|
 
                     ch := line at:col.
-                    ch isUppercase ifTrue:[
-                        isAllLower := false.
-                        col == col1 ifTrue:[
-                            isLowerFirst := false.
-                        ].
-                    ] ifFalse:[
-                        ch isLowercase ifTrue:[
-                            isAllUpper := false.
-                            col == col1 ifTrue:[
-                                isUpperFirst := false.
+                    ch := makeLowercase
+                            ifTrue:[ ch asLowercase ]
+                            ifFalse:[
+                                makeUppercase
+                                    ifTrue:[ ch asUppercase ]
+                                    ifFalse:[
+                                        col == col1
+                                            ifTrue:[ ch asUppercase ]
+                                            ifFalse:[ ch asLowercase ]
+                                    ]
                             ].
-                        ]
-                    ].
+                    line at:col put:ch.
                 ].
-
-                makeLowercase := makeUppercase := makeUppercaseFirst := makeLowercaseFirst := false.
-                isLowerFirst ifTrue:[
-                    makeUppercaseFirst := true.
-                ] ifFalse:[
-                    "/ must remember where we come from - otherwise, we end up
-                    "/ in upperFirst - lowerFirst cycle.
-                    "/ think about a good place to store this state
-                    false "(isUpperFirst and:[isAllUpper not])" ifTrue:[
-                        makeLowercaseFirst := true.
-                     ] ifFalse:[
-                        isAllUpper ifTrue:[
-                            makeLowercase := true.
-                        ] ifFalse:[
-                            makeUppercase := true.
-                        ]
-                    ]
-                ].
-                makeUppercaseFirst ifTrue:[
-                    line at:col1 put:(line at:col1) asUppercase.
-                ] ifFalse:[
-                    makeLowercaseFirst ifTrue:[
-                        line at:col1 put:(line at:col1) asLowercase.
-                    ] ifFalse:[
-                        col1 to:col2 do:[:col |
-                            |ch|
-
-                            ch := line at:col.
-                            ch := makeLowercase
-                                    ifTrue:[ ch asLowercase ]
-                                    ifFalse:[
-                                        makeUppercase
-                                            ifTrue:[ ch asUppercase ]
-                                            ifFalse:[
-                                                col == col1
-                                                    ifTrue:[ ch asUppercase ]
-                                                    ifFalse:[ ch asLowercase ]
-                                            ]
-                                    ].
-                            line at:col put:ch.
-                        ].
-                    ].
-                ].
-                self withoutRedrawAt:lineNr put:line.
-                self invalidateLine:lineNr.
             ].
         ].
+        line
     ]
 
     "Created: / 14-07-2011 / 11:40:26 / cg"
+    "Modified: / 06-06-2016 / 10:57:15 / cg"
+!
+
+convertSelectionToUppercase
+    "to-upper selected text"
+
+    self applyConverterToSelection:[:line :lnr :col1 :col2 |
+        col1 to:col2 do:[:col |
+            |ch|
+
+            ch := line at:col.
+            line at:col put:ch asUppercase.
+        ].
+        line.        
+    ].
+
+    "Created: / 06-06-2016 / 11:09:04 / cg"
+!
+
+convertSelectionToUppercaseFirst
+    "to-upperFirst selected text"
+
+    self applyConverterToSelection:[:line :lnr :col1 :col2 |
+        |state|
+
+        state := #first.
+        col1 to:col2 do:[:col |
+            |ch|
+
+            ch := line at:col.
+            ch isSeparator ifFalse:[
+                state == #first ifTrue:[
+                    line at:col put:ch asUppercase.
+                    state := #skipRest
+                ]
+            ] ifTrue:[
+                state := #first
+            ]
+        ].
+        line.        
+    ].
+
+    "Created: / 06-06-2016 / 10:50:52 / cg"
 !
 
 copyAndDeleteSelection
@@ -3210,6 +3308,15 @@
     "Modified: / 22.2.2000 / 23:59:04 / cg"
 !
 
+indentSelectionBy1
+    "indent selected line-range
+     by 1 space (i.e. to the right)"
+
+    self indentBy:1
+
+    "Created: / 06-06-2016 / 10:58:19 / cg"
+!
+
 insert:aCharacter atLine:lineNr col:colNr
     "insert a single character at lineNr/colNr;
      set emphasis to character at current position"
@@ -3578,7 +3685,18 @@
     self addUndo:(PasteString new line:lineNr col:len+1 string:(Character cr asString) selected:false).
 !
 
+parenthizeSelection
+    "place parenthesis around the selected text.
+     if already parenthized, de-parenthize it"
+
+    self parenthizeSelectionWith:$( and:$)
+
+    "Created: / 06-06-2016 / 10:59:05 / cg"
+!
+
 parenthizeSelectionWith:openingCharacter and:closingCharacter
+    "if already parenthized, de-parenthize it"
+
     |newSelectionEnd startLine endLine startCol endCol|
 
     self hasSelection ifFalse:[^ self].
@@ -3609,6 +3727,8 @@
     self
         selectFromLine:startLine col:startCol
         toLine:endLine col:newSelectionEnd.
+
+    "Modified (comment): / 06-06-2016 / 11:00:37 / cg"
 !
 
 removeTrailingBlankLines
@@ -3969,6 +4089,26 @@
     self addUndo:(DeleteRange line1:lineNr col1:colNr line2:lineNr+1 col2:0 info:'split').
 !
 
+toggleTabSetting
+    "toggle between 4-col
+     and 8-col tabs"
+
+    (tabPositions == self class tab4Positions)
+         ifTrue:[self setTab8]
+         ifFalse:[self setTab4]
+
+    "Created: / 06-06-2016 / 11:02:07 / cg"
+!
+
+undentSelectionBy1
+    "undent selected line-range
+     by 1 space (i.e. to the left)"
+
+    self undentBy:1
+
+    "Created: / 06-06-2016 / 10:49:51 / cg"
+!
+
 withAutoIndent:aBoolean do:aBlock
     |sav|