TextCollector.st
changeset 4045 0b461045f76a
parent 3969 a914bce039b7
child 4073 5b4cf996f5d6
equal deleted inserted replaced
4044:fa9fcf02aed8 4045:0b461045f76a
   641 !
   641 !
   642 
   642 
   643 show:anObject
   643 show:anObject
   644     "insert the argument aString at current cursor position"
   644     "insert the argument aString at current cursor position"
   645 
   645 
   646     |aString lines|
   646     |printString lines|
   647 
   647 
   648     aString := anObject printString.
   648     printString := anObject printString.
   649 
   649 
   650     (aString includes:(Character cr)) ifTrue:[
   650     (printString includes:(Character cr)) ifTrue:[
   651         lines := aString asStringCollection.
   651         lines := printString asStringCollection.
   652         lines keysAndValuesDo:[:nr :line |
   652         lines keysAndValuesDo:[:nr :line |
   653             (nr == lines size 
   653             (nr == lines size 
   654             and:[(aString endsWith:(Character cr)) not]) ifTrue:[
   654             and:[(printString endsWith:(Character cr)) not]) ifTrue:[
   655                 "/ the last one.
   655                 "/ the last one.
   656                 self show:line
   656                 self show:line
   657             ] ifFalse:[
   657             ] ifFalse:[
   658                 self showCR:line
   658                 self showCR:line
   659             ].
   659             ].
   661         ^ self.
   661         ^ self.
   662     ].
   662     ].
   663 
   663 
   664     access critical:[
   664     access critical:[
   665         outstandingLine size ~~ 0 ifTrue:[
   665         outstandingLine size ~~ 0 ifTrue:[
   666             outstandingLine := outstandingLine , aString
   666             outstandingLine := outstandingLine , printString
   667         ] ifFalse:[
   667         ] ifFalse:[
   668             outstandingLine := aString
   668             outstandingLine := printString
   669         ].
   669         ].
   670         collecting ifTrue:[
   670         collecting ifTrue:[
   671             flushPending ifFalse:[
   671             flushPending ifFalse:[
   672                 self installDelayedUpdate
   672                 self installDelayedUpdate
   673             ] ifTrue:[
   673             ] ifTrue:[
   686 showCR:anObject
   686 showCR:anObject
   687     "insert the argument aString at current cursor position,
   687     "insert the argument aString at current cursor position,
   688      and advance to the next line. This is the same as a #show:
   688      and advance to the next line. This is the same as a #show:
   689      followed by a #cr."
   689      followed by a #cr."
   690 
   690 
   691     |aString lines|
   691     |printString lines|
   692 
   692 
   693     aString := anObject printString.
   693     printString := anObject printString.
   694     aString size == 0 ifTrue:[
   694     printString size == 0 ifTrue:[
   695         self cr.
   695         self cr.
   696         ^ self.
   696         ^ self.
   697     ].
   697     ].
   698 
   698 
   699     (aString includesAny:(String with:(Character cr) with:(Character return))) ifTrue:[
   699     (printString includesAny:(String with:(Character cr) with:(Character return))) ifTrue:[
   700         lines := aString asStringCollection.
   700         lines := printString asStringCollection.
   701         lines do:[:line|
   701         lines do:[:line|
   702             (line endsWith:Character return) ifTrue:[
   702             (line endsWith:Character return) ifTrue:[
   703                 self showCR:(line copyWithoutLast:1).
   703                 self showCR:(line copyWithoutLast:1).
   704             ] ifFalse:[
   704             ] ifFalse:[
   705                 self showCR:line
   705                 self showCR:line
   708         ^ self.
   708         ^ self.
   709     ].
   709     ].
   710 
   710 
   711     access critical:[
   711     access critical:[
   712         outstandingLine size ~~ 0 ifTrue:[
   712         outstandingLine size ~~ 0 ifTrue:[
   713             outstandingLine := outstandingLine , aString
   713             outstandingLine := outstandingLine , printString
   714         ] ifFalse:[
   714         ] ifFalse:[
   715             outstandingLine := aString
   715             outstandingLine := printString
   716         ].
   716         ].
   717         outstandingLines isNil ifTrue:[
   717         outstandingLines isNil ifTrue:[
   718             outstandingLines := OrderedCollection with:outstandingLine
   718             outstandingLines := OrderedCollection with:outstandingLine
   719         ] ifFalse:[
   719         ] ifFalse:[
   720             outstandingLines add:outstandingLine.
   720             outstandingLines add:outstandingLine.
   847 ! !
   847 ! !
   848 
   848 
   849 !TextCollector class methodsFor:'documentation'!
   849 !TextCollector class methodsFor:'documentation'!
   850 
   850 
   851 version
   851 version
   852     ^ '$Header: /cvs/stx/stx/libwidg/TextCollector.st,v 1.97 2009-10-12 11:39:09 cg Exp $'
   852     ^ '$Header: /cvs/stx/stx/libwidg/TextCollector.st,v 1.98 2009-10-28 18:26:30 cg Exp $'
   853 !
   853 !
   854 
   854 
   855 version_CVS
   855 version_CVS
   856     ^ '$Header: /cvs/stx/stx/libwidg/TextCollector.st,v 1.97 2009-10-12 11:39:09 cg Exp $'
   856     ^ '$Header: /cvs/stx/stx/libwidg/TextCollector.st,v 1.98 2009-10-28 18:26:30 cg Exp $'
   857 ! !
   857 ! !
   858 
   858 
   859 TextCollector initialize!
   859 TextCollector initialize!