EditTextView.st
changeset 3023 9a6809da7351
parent 3020 68a2dfad4e5e
child 3024 e2d7e40e6481
equal deleted inserted replaced
3022:1b6d4d75a3d0 3023:9a6809da7351
   392 !EditTextView class methodsFor:'defaults'!
   392 !EditTextView class methodsFor:'defaults'!
   393 
   393 
   394 st80Mode
   394 st80Mode
   395     "return true, if the st80 editing mode is turned on.
   395     "return true, if the st80 editing mode is turned on.
   396      This setting affects the behavior of the cursor, when positioned
   396      This setting affects the behavior of the cursor, when positioned
   397      beyond the end of a line or the end of the text.
   397      beyond the end of a line or the end of the text."
   398      The default is initialized from the viewStyle."
       
   399 
   398 
   400     ^ UserPreferences current st80EditMode
   399     ^ UserPreferences current st80EditMode
   401 
   400 
   402    "
   401    "
   403     EditTextView st80Mode:true
   402     EditTextView st80Mode:true
  1190     "move cursor to left"
  1189     "move cursor to left"
  1191 
  1190 
  1192     (cursorCol ~~ 1) ifTrue:[
  1191     (cursorCol ~~ 1) ifTrue:[
  1193         self cursorCol:(cursorCol - 1)
  1192         self cursorCol:(cursorCol - 1)
  1194     ] ifFalse:[
  1193     ] ifFalse:[
  1195 "/ no, do not wrap back to previous line
  1194         cursorLine ~~ 1 ifTrue:[
  1196 "/        cursorLine ~~ 1 ifTrue:[
  1195             self st80EditMode ifTrue:[
  1197 "/            self st80Mode == true ifTrue:[
  1196                 self cursorUp.
  1198 "/                self cursorUp.
  1197                 self cursorToEndOfLine.
  1199 "/                self cursorToEndOfLine.
  1198            ]
  1200 "/           ]
  1199         ]
  1201 "/        ]
       
  1202     ]
  1200     ]
  1203 
  1201 
  1204     "Modified: / 23.1.1998 / 12:37:13 / cg"
  1202     "Modified: / 23.1.1998 / 12:37:13 / cg"
  1205 !
  1203 !
  1206 
  1204 
  1265 cursorRight
  1263 cursorRight
  1266     "move cursor to right"
  1264     "move cursor to right"
  1267 
  1265 
  1268     |l|
  1266     |l|
  1269 
  1267 
  1270     self st80EditMode == true ifTrue:[
  1268     self st80EditMode ifTrue:[
  1271         l := (self listAt:cursorLine).
  1269         l := (self listAt:cursorLine).
  1272         cursorCol >= (l size + 1) ifTrue:[
  1270         cursorCol >= (l size + 1) ifTrue:[
  1273 "/ no, do not wrap to next line
  1271             cursorLine < list size ifTrue:[
  1274 "/            cursorLine < list size ifTrue:[
  1272                 self cursorReturn.
  1275 "/                self cursorReturn.
  1273             ].
  1276 "/            ].
       
  1277             ^ self    
  1274             ^ self    
  1278         ]
  1275         ]
  1279     ].    
  1276     ].    
  1280     self cursorCol:(cursorCol + 1)
  1277     self cursorCol:(cursorCol + 1)
  1281 
  1278 
  1951     |l max|
  1948     |l max|
  1952 
  1949 
  1953     "/ in ST80 mode,
  1950     "/ in ST80 mode,
  1954     "/ the cursor may not be positioned beyond the
  1951     "/ the cursor may not be positioned beyond the
  1955     "/ end of a line or beyond the last line of the text
  1952     "/ end of a line or beyond the last line of the text
  1956     "/
  1953     
  1957     self st80EditMode == true ifTrue:[
  1954     self st80EditMode ifTrue:[
  1958         l := (self listAt:line).
  1955         l := (self listAt:line).
  1959         max := l size + 1.
  1956         max := l size + 1.
  1960         col > max ifTrue:[
  1957         col > max ifTrue:[
  1961             ^ max
  1958             ^ max
  1962         ]
  1959         ]
  1976 
  1973 
  1977     "/
  1974     "/
  1978     "/ in st80Mode, the cursor may not be positioned
  1975     "/ in st80Mode, the cursor may not be positioned
  1979     "/ beyond the last line
  1976     "/ beyond the last line
  1980     "/
  1977     "/
  1981     self st80EditMode == true ifTrue:[
  1978     self st80EditMode ifTrue:[
  1982         ^ (line min:(list size)) max:1
  1979         ^ (line min:(list size)) max:1
  1983     ].
  1980     ].
  1984     ^ line
  1981     ^ line
  1985 
  1982 
  1986     "Created: / 22.5.1996 / 18:22:23 / cg"
  1983     "Created: / 22.5.1996 / 18:22:23 / cg"
  2088     wasOn ifTrue:[self showCursor]
  2085     wasOn ifTrue:[self showCursor]
  2089 !
  2086 !
  2090 
  2087 
  2091 deleteCharAtLine:lineNr col:colNr
  2088 deleteCharAtLine:lineNr col:colNr
  2092     "delete a single character at colNr in line lineNr"
  2089     "delete a single character at colNr in line lineNr"
       
  2090 
       
  2091     self st80EditMode ifTrue:[
       
  2092         (self listAt:cursorLine) size + 1 = colNr ifTrue:[
       
  2093             | wasOn |
       
  2094             wasOn := self hideCursor.
       
  2095             self 
       
  2096                 cursorReturn;
       
  2097                 cursorCol:1;
       
  2098                 deleteCharBeforeCursor.        
       
  2099             wasOn ifTrue:[ self showCursor].
       
  2100             ^ self.
       
  2101         ].
       
  2102     ].
  2093 
  2103 
  2094     self deleteCharsAtLine:lineNr fromCol:colNr toCol:colNr
  2104     self deleteCharsAtLine:lineNr fromCol:colNr toCol:colNr
  2095 !
  2105 !
  2096 
  2106 
  2097 deleteCharBeforeCursor
  2107 deleteCharBeforeCursor
  2931     drawCharacterOnly := false.
  2941     drawCharacterOnly := false.
  2932     self checkForExistingLine:lineNr.
  2942     self checkForExistingLine:lineNr.
  2933     line := list at:lineNr.
  2943     line := list at:lineNr.
  2934     lineSize := line size.
  2944     lineSize := line size.
  2935 
  2945 
  2936     self st80EditMode ~~ true ifTrue:[
  2946     self st80EditMode ifFalse:[
  2937         (trimBlankLines 
  2947         (trimBlankLines 
  2938         and:[colNr > lineSize
  2948         and:[colNr > lineSize
  2939         and:[aCharacter == Character space]]) ifTrue:[
  2949         and:[aCharacter == Character space]]) ifTrue:[
  2940             ^ self
  2950             ^ self
  2941         ]
  2951         ]
  3766                           #InsertLine
  3776                           #InsertLine
  3767                           #SelectLineFromBeginning
  3777                           #SelectLineFromBeginning
  3768                           #LearnKeyboardMacro #ExecuteKeyboardMacro
  3778                           #LearnKeyboardMacro #ExecuteKeyboardMacro
  3769                           #'F*' #'f*')>
  3779                           #'F*' #'f*')>
  3770 
  3780 
  3771     |fKeyMacros shifted i event cmdMacro|
  3781     |fKeyMacros shiftPressed ctrlPressed i event cmdMacro|
  3772 
  3782 
  3773     event := WindowGroup lastEventQuerySignal query.
  3783     event := WindowGroup lastEventQuerySignal query.
  3774     shifted := event hasShift.
  3784     shiftPressed := event hasShift.
       
  3785     ctrlPressed := event hasCtrl.
  3775 
  3786 
  3776     cmdMacro := UserPreferences current functionKeySequences at:key ifAbsent:nil.
  3787     cmdMacro := UserPreferences current functionKeySequences at:key ifAbsent:nil.
  3777     cmdMacro notNil ifTrue:[
  3788     cmdMacro notNil ifTrue:[
  3778         self executeKeyboardMacro:cmdMacro.
  3789         self executeKeyboardMacro:cmdMacro.
  3779         ^ self
  3790         ^ self
  3789             ].
  3800             ].
  3790             ^ self
  3801             ^ self
  3791         ].
  3802         ].
  3792 
  3803 
  3793         self makeCursorVisible.
  3804         self makeCursorVisible.
  3794         shifted ifTrue:[
  3805         shiftPressed ifTrue:[
  3795             self deleteWordBeforeCursor.
  3806             self deleteWordBeforeCursor.
  3796         ] ifFalse:[
  3807         ] ifFalse:[
  3797             self deleteCharBeforeCursor. 
  3808             self deleteCharBeforeCursor. 
  3798         ].
  3809         ].
  3799 
  3810 
  3826      see TextView>>:x:y
  3837      see TextView>>:x:y
  3827     "
  3838     "
  3828     (key at:1) asLowercase == $f ifTrue:[
  3839     (key at:1) asLowercase == $f ifTrue:[
  3829         (('[fF][0-9]' match:key)
  3840         (('[fF][0-9]' match:key)
  3830         or:['[fF][0-9][0-9]' match:key]) ifTrue:[
  3841         or:['[fF][0-9][0-9]' match:key]) ifTrue:[
  3831             shifted ifFalse:[
  3842             shiftPressed ifFalse:[
  3832                 fKeyMacros := UserPreferences current functionKeySequences.
  3843                 fKeyMacros := UserPreferences current functionKeySequences.
  3833                 fKeyMacros notNil ifTrue:[
  3844                 fKeyMacros notNil ifTrue:[
  3834                     (fKeyMacros includesKey:key) ifTrue:[
  3845                     (fKeyMacros includesKey:key) ifTrue:[
  3835                         self pasteOrReplace:(fKeyMacros at:key) asStringCollection.
  3846                         self pasteOrReplace:(fKeyMacros at:key) asStringCollection.
  3836                         ^ self
  3847                         ^ self
  3880     (key == #Ctrln) ifTrue:[self unselect. self cursorDown. ^ self].
  3891     (key == #Ctrln) ifTrue:[self unselect. self cursorDown. ^ self].
  3881     (key == #Ctrlp) ifTrue:[self unselect. self cursorUp. ^ self].
  3892     (key == #Ctrlp) ifTrue:[self unselect. self cursorUp. ^ self].
  3882 "
  3893 "
  3883 
  3894 
  3884     (key == #BeginOfLine) ifTrue:[
  3895     (key == #BeginOfLine) ifTrue:[
  3885         self unselect.
  3896         shiftPressed ifTrue: [       
  3886         shifted ifTrue:[
  3897             "/ "Original St/X code - now use Ctrl modifier"
  3887             self cursorHome
  3898             "/ self unselect.
       
  3899             "/ self cursorHome.
       
  3900             "Jan's modification"        
       
  3901             self addToSelectionAfter:[ self cursorToBeginOfLine ].
       
  3902         ] ifFalse: [
       
  3903             self unselect.
       
  3904             ctrlPressed ifTrue:[
       
  3905                 self cursorHome.
       
  3906             ] ifFalse:[
       
  3907                 self cursorToBeginOfLine.
       
  3908             ]
       
  3909         ].
       
  3910         ^ self
       
  3911     ].
       
  3912     (key == #EndOfLine) ifTrue:[
       
  3913         shiftPressed ifTrue:[
       
  3914             "/ "Original St/X code - now use Ctrl modifier"
       
  3915             "/ self unselect.
       
  3916             "/ self cursorToBottom
       
  3917             "Jan's modification"        
       
  3918             self addToSelectionAfter:[ self cursorToEndOfLine ] .
  3888         ] ifFalse:[
  3919         ] ifFalse:[
  3889             self cursorToBeginOfLine. 
  3920             self unselect.
  3890         ].
  3921             ctrlPressed ifTrue:[
  3891         ^ self
  3922                 self cursorToBottom
  3892     ].
  3923             ] ifFalse:[
  3893     (key == #EndOfLine) ifTrue:[
  3924                 self cursorToEndOfLine. 
  3894         self unselect.
  3925             ]
  3895         shifted ifTrue:[
       
  3896             self cursorToBottom
       
  3897         ] ifFalse:[
       
  3898             self cursorToEndOfLine. 
       
  3899         ].
  3926         ].
  3900         ^ self
  3927         ^ self
  3901     ].
  3928     ].
  3902     (key == #NextWord) ifTrue:[self cursorToNextWord. ^self].
  3929     (key == #NextWord) ifTrue:[self cursorToNextWord. ^self].
  3903     (key == #PreviousWord) ifTrue:[self cursorToPreviousWord. ^self].
  3930     (key == #PreviousWord) ifTrue:[self cursorToPreviousWord. ^self].
  3905 
  3932 
  3906     (key == #CursorRight
  3933     (key == #CursorRight
  3907     or:[key == #CursorDown
  3934     or:[key == #CursorDown
  3908     or:[key == #CursorLeft
  3935     or:[key == #CursorLeft
  3909     or:[key == #CursorUp]]]) ifTrue:[
  3936     or:[key == #CursorUp]]]) ifTrue:[
  3910         self cursorKeyPress:key shifted:shifted.
  3937         self cursorKeyPress:key shifted:shiftPressed.
  3911         ^ self.
  3938         ^ self.
  3912     ].
  3939     ].
  3913 
  3940 
  3914     (key == #Return)    ifTrue:[
  3941     (key == #Return)    ifTrue:[
  3915         shifted ifTrue:[
  3942         shiftPressed ifTrue:[
  3916             self unselect. self cursorReturn. 
  3943             self unselect. self cursorReturn. 
  3917             ^ self
  3944             ^ self
  3918         ].
  3945         ].
  3919         self isReadOnly ifTrue:[
  3946         self isReadOnly ifTrue:[
  3920             self unselect; makeCursorVisible.
  3947             self unselect; makeCursorVisible.
  3967         ^ self
  3994         ^ self
  3968     ].
  3995     ].
  3969 
  3996 
  3970     "/ key == #DeleteSpaces ifTrue:[
  3997     "/ key == #DeleteSpaces ifTrue:[
  3971     (key == #Delete) ifTrue:[
  3998     (key == #Delete) ifTrue:[
  3972         shifted ifTrue:[
  3999         shiftPressed ifTrue:[
  3973             [(cursorCol <= (self listAt:cursorLine) size)
  4000             [(cursorCol <= (self listAt:cursorLine) size)
  3974              and:[self characterUnderCursor isSeparator]] whileTrue:[
  4001              and:[self characterUnderCursor isSeparator]] whileTrue:[
  3975                 self makeCursorVisible.
  4002                 self makeCursorVisible.
  3976                 self deleteCharAtCursor. 
  4003                 self deleteCharAtCursor. 
  3977             ].
  4004             ].
  5504     ^ startCol @ cursorLine
  5531     ^ startCol @ cursorLine
  5505 ! !
  5532 ! !
  5506 
  5533 
  5507 !EditTextView methodsFor:'selections'!
  5534 !EditTextView methodsFor:'selections'!
  5508 
  5535 
       
  5536 addToSelectionAfter:aBlock
       
  5537     "Pokud existuje selekce, upravi ji
       
  5538      podle aktualni pozice kurzoru a pozice
       
  5539      po provedeni blocku.
       
  5540      Urceno k implementaci Shift-Home a Shift-End
       
  5541      Nejak nevim, jak to presneji popsat :-)"
       
  5542 
       
  5543     |startLine startCol endLine endCol |
       
  5544 
       
  5545     self hasSelection ifTrue: [
       
  5546         startLine := selectionStartLine .
       
  5547         startCol := selectionStartCol .
       
  5548         endLine := selectionEndLine .
       
  5549         endCol := selectionEndCol .
       
  5550     ] ifFalse: [
       
  5551         startLine := endLine :=  cursorLine .
       
  5552         startCol := endCol := cursorCol .
       
  5553     ].
       
  5554 
       
  5555     "deselectim a provedu presun kurzoru..."
       
  5556     self unselect .
       
  5557     aBlock value .
       
  5558 
       
  5559     "funguje dost mizerne, jen na jednom radku..."
       
  5560     (startCol - cursorCol) abs <= (endCol - cursorCol) abs
       
  5561         ifTrue: [
       
  5562             startCol := cursorCol.
       
  5563         ] ifFalse: [
       
  5564             endCol := cursorCol - 1.
       
  5565         ].
       
  5566     self selectFromLine:startLine col:startCol toLine: endLine col:endCol .
       
  5567 !
       
  5568 
  5509 autoMoveCursorToEndOfSelection
  5569 autoMoveCursorToEndOfSelection
  5510     "return true, if the cursor should be automatically moved to the
  5570     "return true, if the cursor should be automatically moved to the
  5511      end of a selection.
  5571      end of a selection.
  5512      Redefined to return false in terminaViews, where the cursor should
  5572      Redefined to return false in terminaViews, where the cursor should
  5513      not be affected by selecting"
  5573      not be affected by selecting"
  5866 ! !
  5926 ! !
  5867 
  5927 
  5868 !EditTextView class methodsFor:'documentation'!
  5928 !EditTextView class methodsFor:'documentation'!
  5869 
  5929 
  5870 version
  5930 version
  5871     ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.356 2004-09-14 09:55:41 cg Exp $'
  5931     ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.357 2004-09-14 10:39:31 cg Exp $'
  5872 ! !
  5932 ! !