#UI_ENHANCEMENT by cg
authorClaus Gittinger <cg@exept.de>
Sat, 11 Nov 2017 17:29:21 +0100
changeset 6226 b7628412aff5
parent 6225 0122e4e6c587
child 6227 ff84138a7915
#UI_ENHANCEMENT by cg class: EditTextView fix: care for readOnly in some edit operations added: #checkModificationsAllowedFlashIfNot: comment/format in: #checkModificationsAllowed changed: #applyConverterToSelection: #deleteCopyToClipboard: #handleNonCommandKey: #indentFromLine:toLine:by: #pasteOrReplaceByKeyPress #pasteOrReplaceFromHistory #withSelfAndTextForPasteDo:
EditTextView.st
--- a/EditTextView.st	Thu Nov 09 20:09:30 2017 +0100
+++ b/EditTextView.st	Sat Nov 11 17:29:21 2017 +0100
@@ -3102,6 +3102,8 @@
 
     |line1 line2|
 
+    (self checkModificationsAllowedFlashIfNot:true) ifFalse:[^ self].
+    
     line1 := self selectionStartLine.
     line2 := self selectionEndLine.
     line1 isNil ifTrue:[
@@ -3134,6 +3136,7 @@
     ]
 
     "Created: / 06-06-2016 / 10:53:17 / cg"
+    "Modified: / 11-11-2017 / 12:55:25 / cg"
 !
 
 convertSelectionToLowercase
@@ -5882,10 +5885,7 @@
 handleNonCommandKey:keyArg
     |selStartLineBefore selStartColBefore selEndLineBefore selEndColBefore key|
 
-    self isReadOnly ifTrue:[
-        self flashReadOnly.
-        ^ self.
-    ].
+    (self checkModificationsAllowedFlashIfNot:true) ifFalse:[^ self].
 
     key := keyArg.
 
@@ -5991,7 +5991,7 @@
     ].
     completionSupport notNil ifTrue:[ completionSupport postKeyPress:keyArg ].
 
-    "Modified (comment): / 25-01-2012 / 00:30:11 / cg"
+    "Modified: / 11-11-2017 / 12:54:01 / cg"
 !
 
 keyPress:key x:x y:y
@@ -6255,6 +6255,9 @@
     |d line spaces anyChange|
 
     (delta == 0) ifTrue:[^ self].
+
+    (self checkModificationsAllowedFlashIfNot:true) ifFalse:[ ^ self].
+
     (delta > 0) ifTrue:[
         spaces := String new:delta
     ].
@@ -6292,7 +6295,7 @@
 
     "/ self redrawFromLine:start to:end
 
-    "Modified: 5.3.1996 / 14:59:18 / cg"
+    "Modified: / 11-11-2017 / 12:54:33 / cg"
 !
 
 leftIndentForLine:lineNr
@@ -6592,10 +6595,7 @@
 
     |line col history sel |
 
-    (self checkModificationsAllowed) ifFalse:[
-        self flashReadOnly.
-        ^ self
-    ].
+    (self checkModificationsAllowedFlashIfNot:true) ifFalse:[^ self].
 
     sel := self selection.
     sel notNil ifTrue:[
@@ -6638,7 +6638,7 @@
         ]
     ]
 
-    "Modified: / 5.4.1998 / 16:51:53 / cg"
+    "Modified: / 11-11-2017 / 12:53:45 / cg"
 !
 
 editMenu
@@ -7358,14 +7358,14 @@
 
     |text|
 
-    self checkModificationsAllowed ifFalse:[
-        self flashReadOnly.
-        ^ self
-    ].
+    (self checkModificationsAllowedFlashIfNot:true) ifFalse:[^ self].
+
     text := self getClipboardText:#clipboard.
     text notNil ifTrue:[
         self pasteOrReplace:text
     ]
+
+    "Modified: / 11-11-2017 / 12:52:54 / cg"
 !
 
 pasteOrReplaceFromHistory
@@ -7374,14 +7374,14 @@
 
     |text|
 
-    self checkModificationsAllowed ifFalse:[
-        self flashReadOnly.
-        ^ self
-    ].
+    (self checkModificationsAllowedFlashIfNot:true) ifFalse:[^ self].
+
     text := self getTextSelectionFromHistory.
     text notNil ifTrue:[
         self pasteOrReplace:text
     ]
+
+    "Modified: / 11-11-2017 / 12:52:42 / cg"
 !
 
 replace
@@ -7812,15 +7812,14 @@
 
     |sel|
 
-    self checkModificationsAllowed ifFalse:[
-        self flashReadOnly.
-        ^ self
-    ].
+    (self checkModificationsAllowedFlashIfNot:true) ifFalse:[^ self].
 
     sel := self getTextSelectionOrTextSelectionFromHistory.
     sel notNil ifTrue:[
         aBlock value:self value:sel.
     ]
+
+    "Modified: / 11-11-2017 / 12:52:31 / cg"
 ! !
 
 !EditTextView methodsFor:'private'!
@@ -7834,10 +7833,11 @@
 !
 
 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."
+    "check if the text can be modified (i.e. is not readOnly), return true or false.
+     If not, and an exceptionBlock has been defined, evaluate it.
+     The exceptionBlock can be provided by the application or user of the textView,
+     and may show a warnBox or whatever, or ask again.
+     It can return true to allow the modification"
 
     self isReadOnly ifTrue: [
         exceptionBlock isNil ifTrue:[
@@ -7850,7 +7850,31 @@
     ].
     ^ true
 
-    "Modified: / 17.6.1998 / 15:51:10 / cg"
+    "Modified: / 17-06-1998 / 15:51:10 / cg"
+    "Modified (comment): / 11-11-2017 / 12:49:29 / cg"
+!
+
+checkModificationsAllowedFlashIfNot:doFlashIfNot
+    "check if the text can be modified (i.e. is not readOnly), return true or false.
+     If not, and an exceptionBlock has been defined, evaluate it.
+     The exceptionBlock can be provided by the application or user of the textView,
+     and may show a warnBox or whatever, or ask again.
+     It can return true to allow the modification.
+     If either no exceptionBlock was defined or it returned false,
+     and doFlashIfNot is true then flash the view to tell the user."
+
+    self isReadOnly ifTrue: [
+        (exceptionBlock isNil 
+        or:[(exceptionBlock value:'Text may not be modified') ~~ true]) ifTrue:[
+            doFlashIfNot ifTrue:[
+                self flashReadOnly
+            ].    
+            ^ false
+        ].
+    ].
+    ^ true
+
+    "Created: / 11-11-2017 / 12:52:00 / cg"
 !
 
 currentSelectionBgColor