keyboardMacros.rc
changeset 726 c3108d9652d8
parent 720 b41f5ac59722
child 729 2390cc6de1b4
--- a/keyboardMacros.rc	Wed Nov 29 16:40:10 2006 +0100
+++ b/keyboardMacros.rc	Wed Dec 06 11:37:48 2006 +0100
@@ -371,6 +371,89 @@
 	]
 '.
 
+macros at:#ConvertSelectionToLowercaseOrUppercaseOrUppercaseFirst put:'
+	"to-lower selected text"
+
+	|line1 line2|
+
+	line1 := self selectionStartLine.
+	line2 := self selectionEndLine.
+	line1 isNil ifTrue:[
+	    line1 := self perform:#cursorLine ifNotUnderstood:nil.
+	    line1 notNil ifTrue:[
+		line2 := line1
+	    ]
+	].
+	line1 notNil ifTrue:[
+	    line1 to:line2 do:[:lineNr |
+		|line col1 col2 isAllLower isAllUpper isUpperFirst
+		 makeLowercase makeUppercase makeUppercaseFirst|
+
+		line := (self listAt:lineNr) copy.
+		line size > 0 ifTrue:[
+		    lineNr == line1 ifTrue:[
+			col1 := selectionStartCol.
+		    ] ifFalse:[
+			col1 := 1.
+		    ].
+		    lineNr == line2 ifTrue:[
+			col2 := selectionEndCol.
+		    ] ifFalse:[
+			col2 := (self listAt:lineNr) size.
+		    ].
+		    isAllLower := isAllUpper := isUpperFirst := true.
+		    col1 to:col2 do:[:col |
+			|ch|
+
+			ch := line at:col.
+			ch isUppercase ifTrue:[
+			    isAllLower := false.
+			    col ~~ col1 ifTrue:[
+				isUpperFirst := false.
+			    ].
+			] ifFalse:[
+			    ch isLowercase ifTrue:[
+				isAllUpper := false.
+				col == col1 ifTrue:[
+				    isUpperFirst := false.
+				].
+			    ]
+			].
+		    ].
+		    makeLowercase := makeUppercase := makeUppercaseFirst := false.
+		    isAllLower ifTrue:[
+			makeUppercaseFirst := true.
+		    ] ifFalse:[
+			isUpperFirst ifTrue:[
+			    makeUppercase := true.
+			] ifFalse:[
+			    makeLowercase := true.
+			]
+		    ].
+		    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.
+		].
+	    ].
+	]
+'.
+
 macros at:#ParenthizeSelection put:'
 	"place parenthesis around the selected text"