'From Squeak3.1alpha of 28 February 2001 [latest update: #3968] on 7 May 2001 at 9:39:46 am'! "Change Set: TextAttribute-tk Date: 7 May 2001 Author: Ted Kaehler Cmd-6 lets you modify the attributes of text. At the request of Richard O'Keefe, I've added 'Edit Hidden Info'. This shows you the text that created the URL link (or other attribute). You can go back and forth between a live link and the text that created it. Useful for editing active text with URLs and DoIts. Also adds 'choose color...' for text, so that you can create text of any color. Gives you a color picker."! !ParagraphEditor methodsFor: 'editing keys' stamp: 'tk 5/7/2001 09:11'! changeEmphasis: characterStream "Change the emphasis of the current selection or prepare to accept characters with the change in emphasis. Emphasis change amounts to a font change. Keeps typeahead." | keyCode attribute oldAttributes index thisSel colors | "control 0..9 -> 0..9" keyCode _ ('0123456789-=' indexOf: sensor keyboard ifAbsent: [1]) - 1. oldAttributes _ paragraph text attributesAt: startBlock stringIndex forStyle: paragraph textStyle. thisSel _ self selection. "Decipher keyCodes for Command 0-9..." (keyCode between: 1 and: 5) ifTrue: [attribute _ TextFontChange fontNumber: keyCode]. keyCode = 6 ifTrue: [colors _ #(black magenta red yellow green blue cyan white). index _ (PopUpMenu labelArray: colors , #('choose color...' 'Do it' 'Link to comment of class' 'Link to definition of class' 'Link to hierarchy of class' 'Link to method' 'be a web URL link' 'Edit hidden info' 'Copy hidden info') lines: (Array with: colors size +1)) startUp. index = 0 ifTrue: [^ true]. index <= colors size ifTrue: [attribute _ TextColor color: (Color perform: (colors at: index))] ifFalse: [index _ index - colors size - 1. "Re-number!!!!!!" index = 0 ifTrue: [attribute _ self chooseColor]. index = 1 ifTrue: [attribute _ TextDoIt new. thisSel _ attribute analyze: self selection asString]. index = 2 ifTrue: [attribute _ TextLink new. thisSel _ attribute analyze: self selection asString with: 'Comment']. index = 3 ifTrue: [attribute _ TextLink new. thisSel _ attribute analyze: self selection asString with: 'Definition']. index = 4 ifTrue: [attribute _ TextLink new. thisSel _ attribute analyze: self selection asString with: 'Hierarchy']. index = 5 ifTrue: [attribute _ TextLink new. thisSel _ attribute analyze: self selection asString]. index = 6 ifTrue: [attribute _ TextURL new. thisSel _ attribute analyze: self selection asString]. index = 7 ifTrue: ["Edit hidden info" thisSel _ self hiddenInfo. "includes selection" attribute _ TextEmphasis normal]. index = 8 ifTrue: ["Copy hidden info" self copyHiddenInfo. ^ true]. "no other action" thisSel ifNil: [^ true]]. "Could not figure out what to link to" ]. (keyCode between: 7 and: 11) ifTrue: [sensor leftShiftDown ifTrue: [keyCode = 10 ifTrue: [attribute _ TextKern kern: -1]. keyCode = 11 ifTrue: [attribute _ TextKern kern: 1]] ifFalse: [attribute _ TextEmphasis perform: (#(bold italic narrow underlined struckOut) at: keyCode - 6). oldAttributes do: [:att | (att dominates: attribute) ifTrue: [attribute turnOff]]]]. (keyCode = 0) ifTrue: [attribute _ TextEmphasis normal]. beginTypeInBlock ~~ nil ifTrue: "only change emphasisHere while typing" [self insertTypeAhead: characterStream. emphasisHere _ Text addAttribute: attribute toArray: oldAttributes. ^ true]. self replaceSelectionWith: (thisSel asText addAttribute: attribute). ^ true! ! !ParagraphEditor methodsFor: 'editing keys' stamp: 'tk 5/7/2001 09:11'! chooseColor "Make a new Text Color Attribute, let the user pick a color, and return the attribute. This is the non-Morphic version." ^ TextColor color: (Color fromUser)! ! !ParagraphEditor methodsFor: 'editing keys' stamp: 'tk 5/7/2001 08:47'! copyHiddenInfo "In TextLinks, TextDoits, TextColor, and TextURLs, there is hidden info. Copy that to the clipboard. You can paste it and see what it is. Usually enclosed in <>." ^ self clipboardTextPut: self hiddenInfo asText! ! !ParagraphEditor methodsFor: 'editing keys' stamp: 'tk 5/7/2001 08:48'! hiddenInfo "In TextLinks, TextDoits, TextColor, and TextURLs, there is hidden info. Return the entire string that was used by Cmd-6 to create this text attribute. Usually enclosed in < >." | attrList | attrList _ paragraph text attributesAt: (startBlock stringIndex + stopBlock stringIndex)//2 forStyle: paragraph textStyle. attrList do: [:attr | (attr isKindOf: TextAction) ifTrue: [^ self selection asString, '<', attr info, '>']]. "If none of the above" attrList do: [:attr | attr class == TextColor ifTrue: [^ self selection asString, '<', attr color printString, '>']]. ^ self selection asString, '[No hidden info]'! ! !TextLink methodsFor: 'as yet unclassified' stamp: 'tk 5/7/2001 09:30'! validate: specString "Can this string be decoded to be Class space Method (or Comment, Definition, Hierarchy)? If so, return it in valid format, else nil" | list first mid last | list _ specString findTokens: ' .|'. last _ list last. last first isUppercase ifTrue: [ (#('Comment' 'Definition' 'Hierarchy') includes: last) ifFalse: [^ nil]. "Check for 'Rectangle Comment Comment' and remove last one" (list at: list size - 1) = last ifTrue: [list _ list allButLast]]. list size > 3 ifTrue: [^ nil]. list size < 2 ifTrue: [^ nil]. Symbol hasInterned: list first ifTrue: [:sym | first _ sym]. first ifNil: [^ nil]. Smalltalk at: first ifAbsent: [^ nil]. mid _ list size = 3 ifTrue: [(list at: 2) = 'class' ifTrue: ['class '] ifFalse: [^ nil]] ifFalse: ['']. "OK if method name is not interned -- may not be defined yet" ^ first, ' ', mid, last! ! !TextMorphEditor methodsFor: 'attributes' stamp: 'tk 5/7/2001 09:10'! chooseColor | attribute | "Make a new Text Color Attribute, let the user pick a color, and return the attribute" ColorPickerMorph new choseModalityFromPreference; sourceHand: morph activeHand; target: (attribute _ TextColor color: Color black "default"); selector: #color:; originalColor: Color black; putUpFor: morph near: morph fullBoundsInWorld. ^ attribute ! !