EditTextView.st
changeset 474 f73ed1f5cb75
parent 473 e810b5bd6bad
child 477 e7c29649e8ae
--- a/EditTextView.st	Tue Mar 05 16:01:00 1996 +0100
+++ b/EditTextView.st	Tue Mar 05 16:54:12 1996 +0100
@@ -317,6 +317,12 @@
     acceptAction := aBlock
 !
 
+autoIndent:aBoolean
+    autoIndent := aBoolean
+
+    "Created: 5.3.1996 / 14:37:50 / cg"
+!
+
 exceptionBlock:aBlock
     "define the action to be triggered when user tries to modify
      readonly text"
@@ -359,17 +365,6 @@
     ^ cursorCol
 !
 
-cursorForegroundColor:color1 backgroundColor:color2
-    "set both cursor foreground and cursor background colors"
-
-    |wasOn|
-
-    wasOn := self hideCursor.
-    cursorFgColor := color1 on:device.
-    cursorBgColor := color2 on:device.
-    wasOn ifTrue:[self showCursor]
-!
-
 cursorLine
     "return the cursors line (1..). 
      This is the absolute line; NOT the visible line"
@@ -426,6 +421,19 @@
     readOnly := true
 ! !
 
+!EditTextView methodsFor:'accessing-look'!
+
+cursorForegroundColor:color1 backgroundColor:color2
+    "set both cursor foreground and cursor background colors"
+
+    |wasOn|
+
+    wasOn := self hideCursor.
+    cursorFgColor := color1 on:device.
+    cursorBgColor := color2 on:device.
+    wasOn ifTrue:[self showCursor]
+! !
+
 !EditTextView methodsFor:'change & update '!
 
 accept
@@ -2026,7 +2034,7 @@
                           #SelectLine #ExpandSelectionByLine #DeleteLine
                           #InsertLine)>
 
-    |sensor n fKeyMacros shifted|
+    |sensor n fKeyMacros shifted i|
 
     sensor := self sensor.
     shifted := sensor shiftDown.
@@ -2247,6 +2255,11 @@
                 self copyAndDeleteSelection.            
             ].
             self insertCharAtCursor:(Character cr). 
+            autoIndent == true ifTrue:[
+                i := self leftIndentForLine:cursorLine.
+                self indentFromLine:cursorLine toLine:cursorLine.
+                self cursorCol:(i max:1)
+            ].
         ].
         ^self
     ].
@@ -2339,7 +2352,7 @@
     ].
     super keyPress:key x:x y:y
 
-    "Modified: 2.3.1996 / 00:04:24 / cg"
+    "Modified: 5.3.1996 / 15:00:25 / cg"
 !
 
 mapped
@@ -2412,51 +2425,64 @@
      last non-empty line before start, and change the indent
      of the line based on that indent."
 
-    |leftStart lnr delta d line spaces|
-
-    "find a line to base indent on..."
-    leftStart := 0.
-    lnr := start.
-    [(leftStart == 0) and:[lnr ~~ 1]] whileTrue:[
-	lnr := lnr - 1.
-	leftStart := self leftIndentOfLine:lnr
-    ].
-
+    |leftStart delta d line spaces|
+
+    leftStart := self leftIndentForLine:start.
     (leftStart == 0) ifTrue:[^ self].
 
     delta := leftStart - (self leftIndentOfLine:start).
     (delta == 0) ifTrue:[^ self].
     (delta > 0) ifTrue:[
-	spaces := String new:delta
+        spaces := String new:delta
     ].
     start to:end do:[:lineNr |
-	line := self listAt:lineNr.
-	line notNil ifTrue:[
-	    line isBlank ifTrue:[
-		list at:lineNr put:nil
-	    ] ifFalse:[
-		(delta > 0) ifTrue:[
-		    line := spaces , line.
-		    widthOfWidestLine notNil ifTrue:[
-			widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:line).
-		    ]
-		] ifFalse:[
-		    "check if deletion is ok"
-		    d := delta negated + 1.
-
-		    line size > d ifTrue:[
-			(line copyTo:(d - 1)) withoutSeparators isEmpty ifTrue:[
-			    line := line copyFrom:d
-			]
-		    ].
-		    widthOfWidestLine := nil
-		].
-		list at:lineNr put:line.
-		self textChanged.
-	    ]
-	]
+        line := self listAt:lineNr.
+        line notNil ifTrue:[
+            line isBlank ifTrue:[
+                list at:lineNr put:nil
+            ] ifFalse:[
+                (delta > 0) ifTrue:[
+                    line := spaces , line.
+                    widthOfWidestLine notNil ifTrue:[
+                        widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:line).
+                    ]
+                ] ifFalse:[
+                    "check if deletion is ok"
+                    d := delta negated + 1.
+
+                    line size > d ifTrue:[
+                        (line copyTo:(d - 1)) withoutSeparators isEmpty ifTrue:[
+                            line := line copyFrom:d
+                        ]
+                    ].
+                    widthOfWidestLine := nil
+                ].
+                list at:lineNr put:line.
+                self textChanged.
+            ]
+        ]
     ].
     self redrawFromLine:start to:end
+
+    "Modified: 5.3.1996 / 14:59:18 / cg"
+!
+
+leftIndentForLine:lineNr
+    "find an appropriate indent for a line.
+     this is done by searching for the last non-empty line before it
+     and returning its indent."
+
+    |leftStart lnr|
+
+    leftStart := 0.
+    lnr := lineNr.
+    [(leftStart == 0) and:[lnr ~~ 1]] whileTrue:[
+        lnr := lnr - 1.
+        leftStart := self leftIndentOfLine:lnr
+    ].
+    ^ leftStart
+
+    "Created: 5.3.1996 / 14:58:53 / cg"
 ! !
 
 !EditTextView methodsFor:'initialization'!
@@ -2499,6 +2525,9 @@
     showMatchingParenthesis := false.
     hasKeyboardFocus := false. "/ true.
     tabMeansNextField := false.
+    autoIndent := false.
+
+    "Modified: 5.3.1996 / 14:36:48 / cg"
 !
 
 realize
@@ -2627,6 +2656,7 @@
                     'font ...'
                     '-'
                     'indent'
+                    'autoIndent \c'
                     '-'
                     'save as ...'
                     'print'
@@ -2639,6 +2669,7 @@
                      changeFont
                      nil
                      indent
+                     autoIndent:
                      nil
                      save
                      print
@@ -2662,6 +2693,7 @@
                 receiver:model.
 
     m subMenuAt:#others put:sub.
+    sub checkToggleAt:#autoIndent: put:autoIndent.
 
     readOnly ifTrue:[
         m disable:#paste
@@ -2675,7 +2707,7 @@
     ].
     ^ m.
 
-    "Modified: 28.2.1996 / 19:00:12 / cg"
+    "Modified: 5.3.1996 / 14:43:41 / cg"
 !
 
 paste
@@ -3280,5 +3312,5 @@
 !EditTextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.53 1996-03-05 15:01:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.54 1996-03-05 15:54:12 cg Exp $'
 ! !