ETxtView.st
changeset 1818 aa16d9b96e40
parent 1817 1a9e22f755c8
child 1819 963883688bc7
equal deleted inserted replaced
1817:1a9e22f755c8 1818:aa16d9b96e40
  2259 
  2259 
  2260 deleteFromLine:startLine col:startCol toLine:endLine col:endCol
  2260 deleteFromLine:startLine col:startCol toLine:endLine col:endCol
  2261     "delete all text from startLine/startCol to endLine/endCol -
  2261     "delete all text from startLine/startCol to endLine/endCol -
  2262      joining lines if nescessary"
  2262      joining lines if nescessary"
  2263 
  2263 
  2264     |line lineSize|
  2264     |line newLine lineSize nMore|
  2265 
  2265 
  2266     self checkModificationsAllowed ifFalse:[ ^ self].
  2266     self checkModificationsAllowed ifFalse:[ ^ self].
  2267     list isNil ifTrue:[^ self].
  2267     list isNil ifTrue:[^ self].
  2268     startLine > list size ifTrue:[ ^ self]. "/ deleted space below text
  2268     startLine > list size ifTrue:[ ^ self]. "/ deleted space below text
  2269 
  2269 
  2297         "/ must add blanks, if startCol lies behond end of startLine
  2297         "/ must add blanks, if startCol lies behond end of startLine
  2298 
  2298 
  2299         line := list at:startLine.
  2299         line := list at:startLine.
  2300         lineSize := line size.
  2300         lineSize := line size.
  2301         (startCol > lineSize) ifTrue:[
  2301         (startCol > lineSize) ifTrue:[
       
  2302             newLine := line.
  2302             line isNil ifTrue:[
  2303             line isNil ifTrue:[
  2303                 line := String new:(startCol - 1)
  2304                 newLine := String new:(startCol - 1)
  2304             ] ifFalse:[
  2305             ] ifFalse:[
  2305                 line := line , (line species new:(startCol - 1 - lineSize))
  2306                 nMore := startCol - 1 - lineSize.
       
  2307                 nMore > 0 ifTrue:[
       
  2308                     newLine := line , (line species new:nMore)
       
  2309                 ]
  2306             ].
  2310             ].
  2307             list at:startLine put:line.
  2311             newLine ~~ line ifTrue:[
       
  2312                 list at:startLine put:newLine.
       
  2313             ].
  2308             "/ TODO: remember old maxwidth of linerange,
  2314             "/ TODO: remember old maxwidth of linerange,
  2309             "/ only clear widthOfWidestLine, if this max
  2315             "/ only clear widthOfWidestLine, if this max
  2310             "/ length was (one of) the longest.
  2316             "/ length was (one of) the longest.
  2311             "/ avoids slow delete with huge texts.
  2317             "/ avoids slow delete with huge texts.
  2312             widthOfWidestLine := nil. "/ i.e. unknown
  2318             widthOfWidestLine := nil. "/ i.e. unknown
  2313             self textChanged.
  2319             self textChanged.
  2314         ]
  2320         ]
  2315     ].
  2321     ].
  2316 
  2322 
  2317     "/ merge the left rest of 1st line with right rest of last line into one
  2323     "/ merge the left rest of 1st line with right rest of last line into one
  2318     self mergeLine:startLine
  2324     self mergeLine:startLine removeBlanks:false
  2319 
  2325 
  2320     "Modified: / 10.11.1998 / 23:52:59 / cg"
  2326     "Modified: / 10.11.1998 / 23:52:59 / cg"
  2321 !
  2327 !
  2322 
  2328 
  2323 deleteFromLine:startLineNr toLine:endLineNr
  2329 deleteFromLine:startLineNr toLine:endLineNr
  3590 !EditTextView methodsFor:'menu actions'!
  3596 !EditTextView methodsFor:'menu actions'!
  3591 
  3597 
  3592 cut
  3598 cut
  3593     "cut selection into copybuffer"
  3599     "cut selection into copybuffer"
  3594 
  3600 
  3595     |line col history sel|
  3601     |line col history sel s|
  3596 
  3602 
  3597     (self checkModificationsAllowed) ifFalse:[
  3603     (self checkModificationsAllowed) ifFalse:[
  3598         self flash.
  3604         self flash.
  3599         ^ self
  3605         ^ self
  3600     ].
  3606     ].
  3601 
  3607 
  3602     sel := self selection.
  3608     sel := self selection.
  3603     sel notNil ifTrue:[
  3609     sel notNil ifTrue:[
  3604         lastString := sel asStringWithCRs.
  3610         lastString := s := sel asStringWithCRs.
  3605         line := selectionStartLine.
  3611         line := selectionStartLine.
  3606         col := selectionStartCol.
  3612         col := selectionStartCol.
  3607         undoAction := [self insertString:lastString atLine:line col:col].
  3613         undoAction := [ self cursorLine:line col:col.
       
  3614                         self insertLines:(Array with:s) withCR:false.
       
  3615                       ].
  3608 
  3616 
  3609         "
  3617         "
  3610          remember in CopyBuffer
  3618          remember in CopyBuffer
  3611         "
  3619         "
  3612         self setTextSelection:lastString.
  3620         self setTextSelection:lastString.
  3658         items := #(
  3666         items := #(
  3659                         ('again (for all)'      multipleAgain)  
  3667                         ('again (for all)'      multipleAgain)  
  3660                   ).
  3668                   ).
  3661     ] ifFalse:[
  3669     ] ifFalse:[
  3662         items := #(
  3670         items := #(
  3663 "/                       ('undo'     undo                   )
  3671                         ('undo'     undo                   )
  3664                         ('again'   again            Again  )
  3672                         ('again'   again            Again  )
  3665                         ('-'                               )
  3673                         ('-'                               )
  3666                         ('copy'    copySelection    Copy   )
  3674                         ('copy'    copySelection    Copy   )
  3667                         ('cut'     cut              Cut    )
  3675                         ('cut'     cut              Cut    )
  3668                         ('paste'   pasteOrReplace   Paste  )
  3676                         ('paste'   pasteOrReplace   Paste  )
  3702         m disable:#copySelection.
  3710         m disable:#copySelection.
  3703     ].
  3711     ].
  3704     (self hasSelection not or:[self isReadOnly]) ifTrue:[
  3712     (self hasSelection not or:[self isReadOnly]) ifTrue:[
  3705         m disable:#cut.
  3713         m disable:#cut.
  3706     ].
  3714     ].
       
  3715     (undoAction isNil) ifTrue:[
       
  3716         m disable:#undo.
       
  3717     ].
  3707     acceptEnabled == false ifTrue:[
  3718     acceptEnabled == false ifTrue:[
  3708         m disable:#accept
  3719         m disable:#accept
  3709     ].
  3720     ].
  3710     ^ m.
  3721     ^ m.
  3711 
  3722 
  3733 !
  3744 !
  3734 
  3745 
  3735 paste:someText
  3746 paste:someText
  3736     "paste someText at cursor"
  3747     "paste someText at cursor"
  3737 
  3748 
  3738     |s nLines startLine startCol|
  3749     |s nLines startLine startCol l1 l2 c1 c2|
  3739 
  3750 
  3740     self checkModificationsAllowed ifFalse:[^ self].
  3751     self checkModificationsAllowed ifFalse:[^ self].
  3741 
  3752 
  3742     someText notNil ifTrue:[
  3753     someText notNil ifTrue:[
  3743         s := someText.
  3754         s := someText.
  3750             ]
  3761             ]
  3751         ].
  3762         ].
  3752         (nLines := s size) == 0 ifTrue:[^ self].
  3763         (nLines := s size) == 0 ifTrue:[^ self].
  3753         (nLines == 1 and:[(s at:1) size == 0]) ifTrue:[^ self].
  3764         (nLines == 1 and:[(s at:1) size == 0]) ifTrue:[^ self].
  3754 
  3765 
  3755         startLine := cursorLine.
  3766         startLine := l1 := cursorLine.
  3756         startCol := cursorCol.
  3767         startCol := c1 := cursorCol.
  3757         self insertLines:(s withTabsExpanded) withCR:false.
  3768         self insertLines:(s withTabsExpanded) withCR:false.
  3758         self selectFromLine:startLine col:startCol
  3769         l2 := cursorLine.
  3759                      toLine:cursorLine col:(cursorCol - 1).
  3770         c2 := (cursorCol - 1).
       
  3771         self selectFromLine:l1 col:c1 toLine:l2 col:c2.
  3760         typeOfSelection := #paste.
  3772         typeOfSelection := #paste.
  3761         undoAction := [self cut].
  3773         undoAction := [ self unselect.
       
  3774                         self deleteFromLine:l1 col:c1 toLine:l2 col:c2.
       
  3775                         self cursorLine:l1 col:c1.
       
  3776                       ].
  3762     ]
  3777     ]
  3763 
  3778 
  3764     "Modified: / 14.2.1996 / 11:14:14 / stefan"
  3779     "Modified: / 14.2.1996 / 11:14:14 / stefan"
  3765     "Modified: / 12.6.1998 / 22:12:00 / cg"
  3780     "Modified: / 12.6.1998 / 22:12:00 / cg"
  3766 !
  3781 !
  4516 
  4531 
  4517 undo
  4532 undo
  4518     "currently not implemented"
  4533     "currently not implemented"
  4519 
  4534 
  4520     undoAction notNil ifTrue:[
  4535     undoAction notNil ifTrue:[
  4521 	undoAction value
  4536         undoAction value.
       
  4537         undoAction := nil.
  4522     ]
  4538     ]
  4523 ! !
  4539 ! !
  4524 
  4540 
  4525 !EditTextView class methodsFor:'documentation'!
  4541 !EditTextView class methodsFor:'documentation'!
  4526 
  4542 
  4527 version
  4543 version
  4528     ^ '$Header: /cvs/stx/stx/libwidg/Attic/ETxtView.st,v 1.195 1999-03-23 12:45:43 cg Exp $'
  4544     ^ '$Header: /cvs/stx/stx/libwidg/Attic/ETxtView.st,v 1.196 1999-03-24 20:06:11 cg Exp $'
  4529 ! !
  4545 ! !