[ENH] Colored self-removing error messages (was: Squeak textbox and events)

Hans-Martin Mosner hm.mosner at cityweb.de
Sun May 13 16:28:38 UTC 2001


While I do agree that Squeak's text editing model is somewhat
simple-minded and does not scale well to really large applications, the
compiler error functionality that Scott wished for is quite easily
achieved.
Squeak does indeed have 'tags' for Text, just as the TK textbox model as
far as I understand it. These are called TextAttributes and can affect
rendering as well as clickable links. Look at the hierarchy of
TextAttribute and you'll find that most of the stuff you'll normally
want is just there.
Now, for the automatically disappearing inline compiler errors, here's a
ready-to-type in example. If you open this text in Squeak, you can just
select the relevant lines and do a 'file it in':

1. Define a class TextCompilerError as a subclass of TextAttribute:
TextAttribute subclass: #TextCompilerError
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Collections-Text'

2. Define TextCompilerError's behavior:
!TextCompilerError methodsFor: 'comparing' stamp: 'hmm 5/13/2001 17:49'!

= aTextAttribute
    "All compiler errors are created equal, for our purposes"
    ^aTextAttribute class == self class! !

!TextCompilerError methodsFor: 'testing' stamp: 'hmm 5/13/2001 17:43'!
mayBeExtended
    "You don't want to add this attribute to typed-in text."
    ^false! !

!TextCompilerError methodsFor: 'scanning' stamp: 'hmm 5/13/2001 17:42'!
emphasizeScanner: scanner
    "Set up for bold red text"
    scanner textColor: Color red; addEmphasis: 1! !

3. Link it into ParagraphEditor's handling of compiler input and output:

!ParagraphEditor methodsFor: 'editing keys' stamp: 'hmm 5/13/2001
17:53'!
save: characterStream
    | interval |
    "Submit the current text.  Equivalent to 'accept' 1/18/96 sw
    Keeps typeahead."
    "Removes any text spans tagged with compiler error attribute"

    sensor keyboard.  "flush character"
    self closeTypeIn: characterStream.
    [interval := paragraph text find: TextCompilerError new.
    interval notNil] whileTrue: [
        self selectFrom: interval first to: interval last.
        self replaceSelectionWith: self nullText].
    self terminateAndInitializeAround: [self accept].
    ^ true! !

!ParagraphEditor methodsFor: 'new selection' stamp: 'hmm 5/13/2001
17:56'!
insertAndSelect: aStringOrText at: anInteger
    "Modified to accept a Text and use its first attribute to emphasize
the leading space"
    self replace: (anInteger to: anInteger - 1)
        with: (aStringOrText isString
            ifTrue: [Text string: ' ', aStringOrText attributes:
emphasisHere]
            ifFalse: [(Text string: ' ' attributes: (aStringOrText
attributesAt: 1)), aStringOrText])
        and: [self selectAndScroll]! !

!ParagraphEditor methodsFor: 'new selection' stamp: 'hmm 5/13/2001
17:46'!
notify: aString at: anInteger in: aStream
    "The compilation of text failed. The syntax error is noted as the
argument,
    aString. Insert it in the text at starting character position
anInteger."
    "Modified to add the compiler error attribute to the string"

    self insertAndSelect: (Text string: aString attribute:
TextCompilerError new) at: (anInteger max: 1)! !

4. As always, the hard issues are left as an exercise for the reader:
(a) Modify the code above to leave the selection where it was before the
compiler errors were deleted.
(b) Add support for do it, print it and inspect it (requires (a))

For me, the weekend is almost over. But you guys in the US of A have
some hours left, so hurry :-)

Cheers,
Hans-Martin





More information about the Squeak-dev mailing list