'From Squeak3.2alpha of 4 November 2001 [latest update: #4518] on 22 November 2001 at 1:04:47 pm'! "Change Set: ColorLinkMenu-dew Date: 20 November 2001 Author: Doug Way Adds a menu item for the previously hidden alt-6 menu for creating DoIt/comment/etc links and for changing the color of selected text. It's added as 'color/link menu (6)' near the bottom of the shift-yellow-button menu. (Had to do some refactoring as part of this.) Also fixes an error when someone tries to create a class link with an empty selection."! !ParagraphEditor methodsFor: 'menu messages' stamp: 'dew 11/9/2001 00:55'! colorLinkMenu | selectionAndAttribute newSelection attribute | selectionAndAttribute _ self selectionFromColorLinkMenu. selectionAndAttribute ifNil: [^ self]. newSelection _ selectionAndAttribute key. attribute _ selectionAndAttribute value. self replaceSelectionWith: (newSelection asText addAttribute: attribute).! ! !ParagraphEditor methodsFor: 'editing keys' stamp: 'dew 11/20/2001 01:16'! 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 thisSel selectionAndAttribute | "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: [selectionAndAttribute _ self selectionFromColorLinkMenu. selectionAndAttribute ifNil: [^ true]. "Could not figure out what to link to" thisSel _ selectionAndAttribute key. attribute _ selectionAndAttribute value]. (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: 'dew 11/20/2001 00:45'! selectionFromColorLinkMenu "Bring up the color/link menu and return the selection and attribute based on the choice. Return nil if a link cannot be created." | attribute index thisSel colors extras | thisSel _ self selection. colors _ #(black magenta red yellow green blue cyan white). extras _ ((self class name = #TextMorphEditor) and: [(self morph isKindOf: TextMorphForEditView) not]) "not a system window" ifTrue: [#()] ifFalse: [#('Link to comment of class' 'Link to definition of class' 'Link to hierarchy of class' 'Link to method')]. index _ (PopUpMenu labelArray: colors , #('choose color...' 'Do it' 'Print it'), extras, #('be a web URL link' 'Edit hidden info' 'Copy hidden info') lines: (Array with: colors size +1)) startUp. index = 0 ifTrue: [^ nil]. 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 _ TextPrintIt new. thisSel _ attribute analyze: self selection asString]. (extras size = 0) & (index > 2) ifTrue: [index _ index + 5]. "skip those" index = 3 ifTrue: [attribute _ TextLink new. thisSel _ attribute analyze: self selection asString with: 'Comment']. index = 4 ifTrue: [attribute _ TextLink new. thisSel _ attribute analyze: self selection asString with: 'Definition']. index = 5 ifTrue: [attribute _ TextLink new. thisSel _ attribute analyze: self selection asString with: 'Hierarchy']. index = 6 ifTrue: [attribute _ TextLink new. thisSel _ attribute analyze: self selection asString]. index = 7 ifTrue: [attribute _ TextURL new. thisSel _ attribute analyze: self selection asString]. index = 8 ifTrue: ["Edit hidden info" thisSel _ self hiddenInfo. "includes selection" attribute _ TextEmphasis normal]. index = 9 ifTrue: ["Copy hidden info" self copyHiddenInfo. ^ nil]. "no other action" ]. thisSel ifNil: [^ nil]. ^ thisSel -> attribute! ! !ParagraphEditor class methodsFor: 'class initialization' stamp: 'dew 11/8/2001 19:40'! shiftedYellowButtonMenu "Answer the menu to be presented when the yellow button is pressed while the shift key is down" ^ SelectionMenu fromArray: #( ('set font... (k)' offerFontMenu) ('set style... (K)' changeStyle) ('set alignment...' chooseAlignment) - ('explain' explain) ('pretty print' prettyPrint) ('pretty print with color' prettyPrintWithColor) ('file it in (G)' fileItIn) ('tiles from it' selectionAsTiles) ('recognizer (r)' recognizeCharacters) ('spawn (o)' spawn) - ('definition of word' wordDefinition) ('verify spelling of word' verifyWordSpelling) " ('spell check it' spellCheckIt) " ('translate it' translateIt) ('choose language' languagePrefs) - ('browse it (b)' browseIt) ('senders of it (n)' sendersOfIt) ('implementors of it (m)' implementorsOfIt) ('references to it (N)' referencesToIt) - ('selectors containing it (W)' methodNamesContainingIt) ('method strings with it (E)' methodStringsContainingit) ('method source with it' methodSourceContainingIt) ('class comments with it' classCommentsContainingIt) ('change sets with it' browseChangeSetsWithSelector) - ('save contents to file...' saveContentsInFile) ('send contents to printer' sendContentsToPrinter) ('printer setup' printerSetup) - ('color/link menu... (6)' colorLinkMenu) ('special menu...' presentSpecialMenu) ('more...' yellowButtonActivity))! ! !PluggableTextMorph methodsFor: 'menu commands' stamp: 'dew 11/9/2001 00:58'! colorLinkMenu self handleEdit: [textMorph editor colorLinkMenu]! ! !TextLink methodsFor: 'as yet unclassified' stamp: 'dew 11/22/2001 13:00'! analyze: aString with: nonMethod "Initialize this attribute holder with a piece of text the user typed into a paragraph. Returns the text to emphasize (may be different from selection). Does not return self!! nonMethod is what to show when clicked, i.e. the last part of specifier (Comment, Definition, or Hierarchy). May be of the form: Point Click Here Click Here " "Obtain the showing text and the instructions" | b1 b2 trim | aString isEmpty ifTrue: [^ nil]. b1 _ aString indexOf: $<. b2 _ aString indexOf: $>. (b1 < b2) & (b1 > 0) ifFalse: ["only one part" classAndMethod _ self validate: aString, ' ', nonMethod. ^ classAndMethod ifNotNil: [aString]]. "Two parts" trim _ aString withBlanksTrimmed. (trim at: 1) == $< ifTrue: [(trim last) == $> ifTrue: ["only instructions" classAndMethod _ self validate: (aString copyFrom: b1+1 to: b2-1), ' ', nonMethod. ^ classAndMethod ifNotNil: [classAndMethod]] ifFalse: ["at the front" classAndMethod _ self validate: (aString copyFrom: b1+1 to: b2-1), ' ', nonMethod. ^ classAndMethod ifNotNil: [aString copyFrom: b2+1 to: aString size]]] ifFalse: [(trim last) == $> ifTrue: ["at the end" classAndMethod _ self validate: (aString copyFrom: b1+1 to: b2-1), ' ', nonMethod. ^ classAndMethod ifNotNil: [aString copyFrom: 1 to: b1-1]] ifFalse: ["Illegal -- <> has text on both sides" ^ nil]] ! !