first attempt in providing an ST80 (or vi)
authorClaus Gittinger <cg@exept.de>
Wed, 13 Aug 1997 15:40:07 +0200
changeset 1300 be8b356b2e59
parent 1299 27f3fc6dee3d
child 1301 1fbe38b283e4
first attempt in providing an ST80 (or vi) mode, where you cannot position the cursor behind the lines physical end.
ETxtView.st
EditTextView.st
--- a/ETxtView.st	Wed Aug 13 11:28:06 1997 +0200
+++ b/ETxtView.st	Wed Aug 13 15:40:07 1997 +0200
@@ -20,7 +20,7 @@
 		trimBlankLines wordWrap replacementWordSelectStyle acceptChannel
 		acceptEnabled'
 	classVariableNames:'DefaultCursorForegroundColor DefaultCursorBackgroundColor
-		DefaultCursorType DefaultCursorNoFocusForegroundColor'
+		DefaultCursorType DefaultCursorNoFocusForegroundColor ST80Mode'
 	poolDictionaries:''
 	category:'Views-Text'
 !
@@ -121,6 +121,13 @@
         prevCursorState         <Boolean>       temporary, private
 
 
+    class variables:
+        ST80Mode                <Boolean>       if true, cursor positioning is
+                                                done as in vi or ST80; i.e.
+                                                wysiwyg mode is somewhat relaxed,
+                                                in that the cursor cannot be
+                                                positioned behind a lines end.
+                                                This is not yet completely implemented.
     used globals:
 
         DeleteHistory           <Text>          last 1000 lines of deleted text
@@ -335,7 +342,9 @@
     DefaultCursorNoFocusForegroundColor := StyleSheet colorAt:'textCursorNoFocusForegroundColor'.
     DefaultCursorType := StyleSheet at:'textCursorType' default:#block.
 
-    "Modified: 18.2.1997 / 15:00:01 / cg"
+    ST80Mode := false.
+
+    "Modified: 13.8.1997 / 15:38:16 / cg"
 ! !
 
 !EditTextView methodsFor:'ST-80 compatibility editing'!
@@ -733,9 +742,16 @@
 cursorLeft
     "move cursor to left"
 
-    (cursorCol ~~ 1) ifTrue: [
-	self cursorCol:(cursorCol - 1)
-    ].
+    (cursorCol ~~ 1) ifTrue:[
+        self cursorCol:(cursorCol - 1)
+    ] ifFalse:[
+        ST80Mode == true ifTrue:[
+            self cursorUp.
+            self cursorToEndOfLine.
+        ]
+    ]
+
+    "Modified: 12.8.1997 / 13:57:14 / cg"
 !
 
 cursorLine:line col:col
@@ -781,7 +797,18 @@
 cursorRight
     "move cursor to right"
 
+    |l|
+
+    ST80Mode == true ifTrue:[
+        l := (self listAt:cursorLine).
+        cursorCol >= (l size + 1) ifTrue:[
+            self cursorReturn.
+            ^ self    
+        ]
+    ].    
     self cursorCol:(cursorCol + 1)
+
+    "Modified: 13.8.1997 / 15:33:48 / cg"
 !
 
 cursorTab
@@ -851,15 +878,12 @@
 cursorToEndOfLine
     "move cursor to end of current line"
 
-    |line newCol|
-
-    list isNil ifTrue:[
-	newCol := 1
-    ] ifFalse:[
-	line := list at:cursorLine.
-	newCol := line size + 1
-    ].
-    self cursorCol:newCol
+    |line|
+
+    line := (self listAt:cursorLine).
+    self cursorCol:(line size + 1)
+
+    "Modified: 13.8.1997 / 15:34:02 / cg"
 !
 
 cursorToFirstVisibleLine
@@ -1275,10 +1299,19 @@
      but it may be redefined in EditFields or views which dont like the 
      cursor to be positioned behind the end of a textLine (vi/st-80 behavior)"
 
+    |l max|
+
+    ST80Mode == true ifTrue:[
+        l := (self listAt:line).
+        max := l size + 1.
+        col > max ifTrue:[
+            ^ max
+        ]
+    ].
     ^ col
 
     "Created: 22.5.1996 / 14:25:30 / cg"
-    "Modified: 22.5.1996 / 18:29:21 / cg"
+    "Modified: 13.8.1997 / 15:34:13 / cg"
 !
 
 validateCursorLine:line
@@ -1306,165 +1339,6 @@
     ]
 ! !
 
-!EditTextView methodsFor:'documentation'!
-
-examples
-"
-  non MVC operation:
-
-    basic setup:
-                                                                        [exBegin]
-        |top textView|
-
-        top := StandardSystemView new.
-        top extent:300@200.
-
-        textView := EditTextView new.
-        textView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top addSubView:textView.
-
-        textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
-
-        top open.
-                                                                        [exEnd]
-
-
-    with vertical scrollbar:
-                                                                        [exBegin]
-        |top scrollView textView|
-
-        top := StandardSystemView new.
-        top extent:300@200.
-
-        scrollView := ScrollableView for:EditTextView.
-        textView := scrollView scrolledView.
-        scrollView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top addSubView:scrollView.
-
-        textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
-
-        top open.
-                                                                        [exEnd]
-
-
-    with horizontal & vertical scrollbars:
-                                                                        [exBegin]
-        |top scrollView textView|
-
-        top := StandardSystemView new.
-        top extent:300@200.
-
-        scrollView := HVScrollableView for:EditTextView.
-        textView := scrollView scrolledView.
-        scrollView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top addSubView:scrollView.
-
-        textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
-
-        top open.
-                                                                        [exEnd]
-
-
-    set the action for accept:
-                                                                        [exBegin]
-        |top textView|
-
-        top := StandardSystemView new.
-        top extent:300@200.
-
-        textView := EditTextView new.
-        textView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top addSubView:textView.
-
-        textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
-        textView acceptAction:[:contents |
-                                Transcript showCR:'will not overwrite the file with:'.
-                                Transcript showCR:contents asString
-                              ].
-        top open.
-                                                                        [exEnd]
-
-
-
-  MVC operation:
-    (the examples model here is a plug simulating a real model;
-     real world applications would not use a plug ..)
-                                                                        [exBegin]
-        |top textView model|
-
-        model := Plug new.
-        model respondTo:#accepted:
-                   with:[:newContents | 
-                                Transcript showCR:'will not overwrite the file with:'.
-                                Transcript showCR:newContents asString
-                        ].
-        model respondTo:#getList
-                   with:['/etc/hosts' asFilename contentsOfEntireFile].
-
-        
-        top := StandardSystemView new.
-        top extent:300@200.
-
-        textView := EditTextView new.
-        textView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top addSubView:textView.
-
-        textView model:model;
-                 changeMessage:#accepted:;
-                 listMessage:#getList;
-                 aspect:#list.
-        top open.
-                                                                        [exEnd]
-
-
-    two textViews on the same model:
-                                                                        [exBegin]
-        |top1 textView1 top2 textView2 model currentContents|
-
-        model := Plug new.
-        model respondTo:#accepted:
-                   with:[:newContents |
-                                Transcript showCR:'accepted:'.
-                                Transcript showCR:newContents asString.
-                                currentContents := newContents.
-                                model changed:#contents
-                        ].
-        model respondTo:#getList
-                   with:[Transcript showCR:'query'.
-                         currentContents].
-
-
-        top1 := StandardSystemView new.
-        top1 extent:300@200.
-
-        textView1 := EditTextView new.
-        textView1 origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top1 addSubView:textView1.
-
-        textView1 model:model;
-                  aspect:#contents;
-                  changeMessage:#accepted:;
-                  listMessage:#getList.
-        top1 open.
-
-        top2 := StandardSystemView new.
-        top2 extent:300@200.
-
-        textView2 := EditTextView new.
-        textView2 origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top2 addSubView:textView2.
-
-        textView2 model:model;
-                  aspect:#contents;
-                  changeMessage:#accepted:;
-                  listMessage:#getList.
-        top2 open.
-                                                                        [exEnd]
-"
-
-    "Modified: 27.4.1996 / 16:29:43 / cg"
-! !
-
 !EditTextView methodsFor:'editing'!
 
 copyAndDeleteSelection
@@ -2095,10 +1969,12 @@
     line := list at:lineNr.
     lineSize := line size.
 
-    (trimBlankLines 
-    and:[colNr > lineSize
-    and:[aCharacter == Character space]]) ifTrue:[
-        ^ self
+    ST80Mode ~~ true ifTrue:[
+        (trimBlankLines 
+        and:[colNr > lineSize
+        and:[aCharacter == Character space]]) ifTrue:[
+            ^ self
+        ]
     ].
 
     (lineSize == 0) ifTrue:[
@@ -2148,10 +2024,7 @@
         ]
     ]
 
-    "Modified: 22.5.1996 / 15:35:12 / cg"
-
-
-
+    "Modified: 13.8.1997 / 15:37:21 / cg"
 !
 
 insertLines:someText from:start to:end before:lineNr
@@ -3556,16 +3429,23 @@
 !EditTextView methodsFor:'private'!
 
 checkModificationsAllowed
+    "check if the text can be modified (i.e. is not readOnly).
+     evaluate the exceptionBlock if not.
+     This block should be provided by the application or user of the textView,
+     and may show a warnBox or whatever."
+
     readOnly ifTrue: [
-	exceptionBlock isNil ifTrue:[
-	    ^ false
-	].
-
-	(exceptionBlock value:'Text may not be modified') ~~ true ifTrue:[
-	    ^ false
-	]
+        exceptionBlock isNil ifTrue:[
+            ^ false
+        ].
+
+        (exceptionBlock value:'Text may not be modified') ~~ true ifTrue:[
+            ^ false
+        ]
     ].
     ^ true
+
+    "Modified: 13.8.1997 / 15:36:07 / cg"
 !
 
 textChanged
@@ -4064,5 +3944,5 @@
 !EditTextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Attic/ETxtView.st,v 1.130 1997-08-11 11:58:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Attic/ETxtView.st,v 1.131 1997-08-13 13:40:07 cg Exp $'
 ! !
--- a/EditTextView.st	Wed Aug 13 11:28:06 1997 +0200
+++ b/EditTextView.st	Wed Aug 13 15:40:07 1997 +0200
@@ -20,7 +20,7 @@
 		trimBlankLines wordWrap replacementWordSelectStyle acceptChannel
 		acceptEnabled'
 	classVariableNames:'DefaultCursorForegroundColor DefaultCursorBackgroundColor
-		DefaultCursorType DefaultCursorNoFocusForegroundColor'
+		DefaultCursorType DefaultCursorNoFocusForegroundColor ST80Mode'
 	poolDictionaries:''
 	category:'Views-Text'
 !
@@ -121,6 +121,13 @@
         prevCursorState         <Boolean>       temporary, private
 
 
+    class variables:
+        ST80Mode                <Boolean>       if true, cursor positioning is
+                                                done as in vi or ST80; i.e.
+                                                wysiwyg mode is somewhat relaxed,
+                                                in that the cursor cannot be
+                                                positioned behind a lines end.
+                                                This is not yet completely implemented.
     used globals:
 
         DeleteHistory           <Text>          last 1000 lines of deleted text
@@ -335,7 +342,9 @@
     DefaultCursorNoFocusForegroundColor := StyleSheet colorAt:'textCursorNoFocusForegroundColor'.
     DefaultCursorType := StyleSheet at:'textCursorType' default:#block.
 
-    "Modified: 18.2.1997 / 15:00:01 / cg"
+    ST80Mode := false.
+
+    "Modified: 13.8.1997 / 15:38:16 / cg"
 ! !
 
 !EditTextView methodsFor:'ST-80 compatibility editing'!
@@ -733,9 +742,16 @@
 cursorLeft
     "move cursor to left"
 
-    (cursorCol ~~ 1) ifTrue: [
-	self cursorCol:(cursorCol - 1)
-    ].
+    (cursorCol ~~ 1) ifTrue:[
+        self cursorCol:(cursorCol - 1)
+    ] ifFalse:[
+        ST80Mode == true ifTrue:[
+            self cursorUp.
+            self cursorToEndOfLine.
+        ]
+    ]
+
+    "Modified: 12.8.1997 / 13:57:14 / cg"
 !
 
 cursorLine:line col:col
@@ -781,7 +797,18 @@
 cursorRight
     "move cursor to right"
 
+    |l|
+
+    ST80Mode == true ifTrue:[
+        l := (self listAt:cursorLine).
+        cursorCol >= (l size + 1) ifTrue:[
+            self cursorReturn.
+            ^ self    
+        ]
+    ].    
     self cursorCol:(cursorCol + 1)
+
+    "Modified: 13.8.1997 / 15:33:48 / cg"
 !
 
 cursorTab
@@ -851,15 +878,12 @@
 cursorToEndOfLine
     "move cursor to end of current line"
 
-    |line newCol|
-
-    list isNil ifTrue:[
-	newCol := 1
-    ] ifFalse:[
-	line := list at:cursorLine.
-	newCol := line size + 1
-    ].
-    self cursorCol:newCol
+    |line|
+
+    line := (self listAt:cursorLine).
+    self cursorCol:(line size + 1)
+
+    "Modified: 13.8.1997 / 15:34:02 / cg"
 !
 
 cursorToFirstVisibleLine
@@ -1275,10 +1299,19 @@
      but it may be redefined in EditFields or views which dont like the 
      cursor to be positioned behind the end of a textLine (vi/st-80 behavior)"
 
+    |l max|
+
+    ST80Mode == true ifTrue:[
+        l := (self listAt:line).
+        max := l size + 1.
+        col > max ifTrue:[
+            ^ max
+        ]
+    ].
     ^ col
 
     "Created: 22.5.1996 / 14:25:30 / cg"
-    "Modified: 22.5.1996 / 18:29:21 / cg"
+    "Modified: 13.8.1997 / 15:34:13 / cg"
 !
 
 validateCursorLine:line
@@ -1306,165 +1339,6 @@
     ]
 ! !
 
-!EditTextView methodsFor:'documentation'!
-
-examples
-"
-  non MVC operation:
-
-    basic setup:
-                                                                        [exBegin]
-        |top textView|
-
-        top := StandardSystemView new.
-        top extent:300@200.
-
-        textView := EditTextView new.
-        textView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top addSubView:textView.
-
-        textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
-
-        top open.
-                                                                        [exEnd]
-
-
-    with vertical scrollbar:
-                                                                        [exBegin]
-        |top scrollView textView|
-
-        top := StandardSystemView new.
-        top extent:300@200.
-
-        scrollView := ScrollableView for:EditTextView.
-        textView := scrollView scrolledView.
-        scrollView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top addSubView:scrollView.
-
-        textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
-
-        top open.
-                                                                        [exEnd]
-
-
-    with horizontal & vertical scrollbars:
-                                                                        [exBegin]
-        |top scrollView textView|
-
-        top := StandardSystemView new.
-        top extent:300@200.
-
-        scrollView := HVScrollableView for:EditTextView.
-        textView := scrollView scrolledView.
-        scrollView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top addSubView:scrollView.
-
-        textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
-
-        top open.
-                                                                        [exEnd]
-
-
-    set the action for accept:
-                                                                        [exBegin]
-        |top textView|
-
-        top := StandardSystemView new.
-        top extent:300@200.
-
-        textView := EditTextView new.
-        textView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top addSubView:textView.
-
-        textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
-        textView acceptAction:[:contents |
-                                Transcript showCR:'will not overwrite the file with:'.
-                                Transcript showCR:contents asString
-                              ].
-        top open.
-                                                                        [exEnd]
-
-
-
-  MVC operation:
-    (the examples model here is a plug simulating a real model;
-     real world applications would not use a plug ..)
-                                                                        [exBegin]
-        |top textView model|
-
-        model := Plug new.
-        model respondTo:#accepted:
-                   with:[:newContents | 
-                                Transcript showCR:'will not overwrite the file with:'.
-                                Transcript showCR:newContents asString
-                        ].
-        model respondTo:#getList
-                   with:['/etc/hosts' asFilename contentsOfEntireFile].
-
-        
-        top := StandardSystemView new.
-        top extent:300@200.
-
-        textView := EditTextView new.
-        textView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top addSubView:textView.
-
-        textView model:model;
-                 changeMessage:#accepted:;
-                 listMessage:#getList;
-                 aspect:#list.
-        top open.
-                                                                        [exEnd]
-
-
-    two textViews on the same model:
-                                                                        [exBegin]
-        |top1 textView1 top2 textView2 model currentContents|
-
-        model := Plug new.
-        model respondTo:#accepted:
-                   with:[:newContents |
-                                Transcript showCR:'accepted:'.
-                                Transcript showCR:newContents asString.
-                                currentContents := newContents.
-                                model changed:#contents
-                        ].
-        model respondTo:#getList
-                   with:[Transcript showCR:'query'.
-                         currentContents].
-
-
-        top1 := StandardSystemView new.
-        top1 extent:300@200.
-
-        textView1 := EditTextView new.
-        textView1 origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top1 addSubView:textView1.
-
-        textView1 model:model;
-                  aspect:#contents;
-                  changeMessage:#accepted:;
-                  listMessage:#getList.
-        top1 open.
-
-        top2 := StandardSystemView new.
-        top2 extent:300@200.
-
-        textView2 := EditTextView new.
-        textView2 origin:0.0 @ 0.0 corner:1.0 @ 1.0.
-        top2 addSubView:textView2.
-
-        textView2 model:model;
-                  aspect:#contents;
-                  changeMessage:#accepted:;
-                  listMessage:#getList.
-        top2 open.
-                                                                        [exEnd]
-"
-
-    "Modified: 27.4.1996 / 16:29:43 / cg"
-! !
-
 !EditTextView methodsFor:'editing'!
 
 copyAndDeleteSelection
@@ -2095,10 +1969,12 @@
     line := list at:lineNr.
     lineSize := line size.
 
-    (trimBlankLines 
-    and:[colNr > lineSize
-    and:[aCharacter == Character space]]) ifTrue:[
-        ^ self
+    ST80Mode ~~ true ifTrue:[
+        (trimBlankLines 
+        and:[colNr > lineSize
+        and:[aCharacter == Character space]]) ifTrue:[
+            ^ self
+        ]
     ].
 
     (lineSize == 0) ifTrue:[
@@ -2148,10 +2024,7 @@
         ]
     ]
 
-    "Modified: 22.5.1996 / 15:35:12 / cg"
-
-
-
+    "Modified: 13.8.1997 / 15:37:21 / cg"
 !
 
 insertLines:someText from:start to:end before:lineNr
@@ -3556,16 +3429,23 @@
 !EditTextView methodsFor:'private'!
 
 checkModificationsAllowed
+    "check if the text can be modified (i.e. is not readOnly).
+     evaluate the exceptionBlock if not.
+     This block should be provided by the application or user of the textView,
+     and may show a warnBox or whatever."
+
     readOnly ifTrue: [
-	exceptionBlock isNil ifTrue:[
-	    ^ false
-	].
-
-	(exceptionBlock value:'Text may not be modified') ~~ true ifTrue:[
-	    ^ false
-	]
+        exceptionBlock isNil ifTrue:[
+            ^ false
+        ].
+
+        (exceptionBlock value:'Text may not be modified') ~~ true ifTrue:[
+            ^ false
+        ]
     ].
     ^ true
+
+    "Modified: 13.8.1997 / 15:36:07 / cg"
 !
 
 textChanged
@@ -4064,5 +3944,5 @@
 !EditTextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.130 1997-08-11 11:58:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.131 1997-08-13 13:40:07 cg Exp $'
 ! !