'From Squeak3.8gamma of ''24 November 2004'' [latest update: #6662] on 8 May 2005 at 9:58:12 pm'! "Change Set: TextToolFix Date: 7 May 2005 Author: Takashi Yamamiya Fixing text tool with test case. Previous version has a problem that text font and emphasis were changed mandatorly even if you don't want to change them. (Other bug when more than one tool in the screen remains...) "! CWidgetTest subclass: #CTextToolTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Tweak-Tools-TextTool'! !CTextToolTest commentStamp: 'tak 5/7/2005 07:24' prior: 0! CTextToolTest buildSuite run! !CTextTool methodsFor: 'intialize' stamp: 'tak 5/8/2005 21:36'! setupCostume super setupCostume. self extent: 187@76. self fillStyle: #solid. self fillColors: (Array with: (Color r: 1.0 g: 1.0 b: 1.0) with: (Color r: 1.0 g: 0.677 b: 0.032)). self borderWidth: 1. self roundCorners: true. self dropShadowEnabled: true. self borderColor: (Color r: 0.987 g: 0.725 b: 0.188). self borderStyle: #simple. self fillStyle: #solid. layout := CTableLayout new. layout listDirection: #leftToRight. layout wrapDirection: #topToBottom. layout hResizing: #shrinkWrap; vResizing: #shrinkWrap. layout layoutInset: 4. layout cellInset: 2. fontNames addAll: StrikeFont actualFamilyNames. fontNames width: 108. fontNames costume hResizing: #rigid. self add: fontNames. fontSizes addAll: #(9 10 12 14 18 24 36 48). fontSizes width: 64. fontSizes costume hResizing: #rigid. self add: fontSizes. boldButton label: ('B' asText allBold addAttribute: TextEmphasis bold). boldButton extent: 20@20. self add: boldButton. italicButton label: (' I ' asText allBold addAttribute: TextEmphasis italic). italicButton extent: 20@20. self add: italicButton. underlineButton label: ('U' asText allBold addAttribute: TextEmphasis underlined). underlineButton extent: 20@20. self add: underlineButton. struckoutButton label: ('S' asText allBold addAttribute: TextEmphasis struckOut). struckoutButton extent: 20@20. self add: struckoutButton. leftAlign extent: 20@20. self add: leftAlign. centerAlign extent: 20@20. self add: centerAlign. rightAlign extent: 20@20. self add: rightAlign. blockAlign extent: 20@20. self add: blockAlign. ! ! !CTextTool methodsFor: 'events' stamp: 'tak 5/7/2005 19:57'! currentFont "Font on the editor" editor ifNil: [^ self selectedFont]. ^ editor font ifNil: [TextStyle defaultFont]! ! !CTextTool methodsFor: 'events' stamp: 'tak 5/8/2005 20:41'! onClose self pauseScript: #onKeyboardFocusChanged ! ! !CTextTool methodsFor: 'events' stamp: 'tak 5/7/2005 20:03'! onFontNameChanged self currentFont familyName = fontNames selection ifTrue: [^self]. self onUpdateFont.! ! !CTextTool methodsFor: 'events' stamp: 'tak 5/7/2005 20:02'! onFontSizeChanged self currentFont pointSize = fontSizes selection ifTrue: [^self]. self onUpdateFont. ! ! !CTextTool methodsFor: 'events' stamp: 'tak 5/8/2005 20:49'! onKeyboardFocusChanged | newFocus | newFocus := hand keyboardFocus. newFocus ifNil:[^self]. newFocus := newFocus asPlayer. newFocus textHolder ifNil:[^self]. editor := newFocus textHolder getEditor. self onTextSelectionChanged! ! !CTextTool methodsFor: 'events' stamp: 'tak 5/8/2005 20:45'! onOpen self resumeScript: #onKeyboardFocusChanged. self onKeyboardFocusChanged ! ! !CTextTool methodsFor: 'events' stamp: 'tak 5/7/2005 20:01'! onTextSelectionChanged | code | "Refresh widget from the font of current editor." self selectFont. code := editor emphasis. boldButton selected: (code anyMask: 1). italicButton selected: (code anyMask: 2). underlineButton selected: (code anyMask: 4). struckoutButton selected: (code anyMask: 16). ! ! !CTextTool methodsFor: 'events' stamp: 'tak 5/7/2005 21:42'! selectedFont "Font on the tool" | fontSize fontStyle | fontSize _ fontSizes selection. fontStyle _ (TextStyle named: fontNames selection) ifNil: [TextStyle default]. fontSize ifNotNil: [^ fontStyle fontOfPointSize: fontSize]. ^ fontStyle defaultFont! ! !CTextTool methodsFor: 'events' stamp: 'tak 5/7/2005 20:01'! selectFont "Refresh widget from the font of current editor." | aFont | aFont _ self currentFont. fontNames selection: aFont familyName asSymbol. fontSizes contents: aFont textStyle pointSizes. fontSizes selection: aFont pointSize! ! !CTextToolTest methodsFor: 'testing' stamp: 'tak 5/6/2005 19:06'! testBold "self debug: #testBold" | tool textEditor | tool _ CTextTool new. textEditor _ CTextEditor new. textEditor contents: 'Hello'. textEditor editor selectAll. tool boldButton fire. self waitTick. self assert: tool boldButton selected. tool editor: textEditor editor. self waitTick. self assert: tool boldButton selected not. tool boldButton fire. self waitTick. self assert: tool boldButton selected. self assert: textEditor emphasis = 1. ! ! !CTextToolTest methodsFor: 'testing' stamp: 'tak 5/6/2005 19:14'! testBoldItalic "self debug: #testBoldItalic" | tool textEditor | tool _ CTextTool new. textEditor _ CTextEditor new. textEditor contents: 'Hello'. textEditor editor selectAll. tool editor: textEditor editor. tool boldButton fire. tool italicButton fire. self waitTick. self assert: tool boldButton selected. self assert: textEditor emphasis = 3. ! ! !CTextToolTest methodsFor: 'testing' stamp: 'tak 5/6/2005 19:28'! testFontName "self debug: #testFontName" | tool textEditor | tool _ CTextTool new. textEditor _ CTextEditor new. textEditor contents: 'Hello'. textEditor editor selectAll. tool editor: textEditor editor. tool fontNames value: #Accushi. self waitTick. textEditor contents font name = 'Accushi'. tool fontNames value: #Atlanta. self waitTick. textEditor contents font name = 'Atlanta'. ! ! !CTextToolTest methodsFor: 'testing' stamp: 'tak 5/7/2005 21:40'! testInitialize "self debug: #testInitialize" | tool | tool _ CTextTool new. self assert: tool selectedFont = TextStyle defaultFont! ! !CTextToolTest methodsFor: 'testing' stamp: 'tak 5/8/2005 21:47'! testOpen "self debug: #testOpen" | tool | tool _ CTextTool new. self waitTick. self assert: (world hand handlesEvent: #keyboardFocusChanged) not. tool open. self waitTick. self assert: (world hand handlesEvent: #keyboardFocusChanged). tool close. self waitTick. self assert: (world hand handlesEvent: #keyboardFocusChanged) not. ! ! !CTextToolTest methodsFor: 'testing' stamp: 'tak 5/7/2005 19:38'! testSelectAfterSetFont "self debug: #testSelectAfterSetFont" | tool textEditor | tool := CTextTool new. textEditor := CTextEditor new. textEditor contents: 'Hello'. tool editor: textEditor editor. textEditor selectFrom: 1 to: 2. self waitTick. self assert: textEditor selection font isNil. tool fontSizes selection: 24. self waitTick. self assert: textEditor selection font pointSize = 24. textEditor selectFrom: 2 to: 3. self waitTick. self assert: textEditor selection font isNil. ! ! !CTextToolTest methodsFor: 'testing' stamp: 'tak 5/6/2005 19:17'! testSelectedBold "self debug: #testSelectedBold" | tool textEditor textEditor2 | tool _ CTextTool new. textEditor _ CTextEditor new. textEditor contents: 'Hello'. textEditor editor selectAll. textEditor2 _ CTextEditor new. textEditor2 contents: 'Hello' asText allBold. textEditor2 editor selectAll. tool editor: textEditor editor. self waitTick. self assert: tool boldButton selected not. tool editor: textEditor2. self waitTick. self assert: tool boldButton selected. ! ! !CTextToolTest methodsFor: 'testing' stamp: 'tak 5/7/2005 00:29'! testSelectedFontName "self debug: #testSelectedFontName" | tool textEditor text | text := 'Hello' asText. text addAttribute: (TextFontReference toFont: (StrikeFont familyName: 'Accusf' size: 18)). tool := CTextTool new. textEditor := CTextEditor new. self waitTick. textEditor contents: text. textEditor editor selectAll. tool editor: textEditor editor. self waitTick. self assert: tool fontNames value = 'Accusf'. self assert: tool fontSizes value = 18! ! !CTextToolTest methodsFor: 'testing' stamp: 'tak 5/7/2005 22:25'! testText "This test case is not finished..." "self debug: #testText" | tool textEditor text | tool := CTextTool new. textEditor := CTextEditor new. text _ 'Hello' asText. text makeBoldFrom: 1 to: 1. text makeItalicFrom: 3 to: 3. textEditor contents: text. textEditor selectFrom: 1 to: 2. tool editor: textEditor editor. self waitTick. self assert: (textEditor emphasis anyMask: 1). self assert: tool boldButton selected. ! ! CTextTool removeSelector: #selectedFontSize! CTextTool removeSelector: #selectedFontStyle! CTextTool removeSelector: #selectFont:!