Tools__CodeHighlightingService.st
changeset 13867 9b47144adc96
parent 13588 0701806de907
child 14486 c8b1e2d7dc46
equal deleted inserted replaced
13866:7b45431bb24e 13867:9b47144adc96
   132     "Modified: / 28-09-2011 / 00:23:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   132     "Modified: / 28-09-2011 / 00:23:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   133     "Modified: / 22-07-2013 / 13:33:46 / cg"
   133     "Modified: / 22-07-2013 / 13:33:46 / cg"
   134 !
   134 !
   135 
   135 
   136 syntaxHighlighters
   136 syntaxHighlighters
   137     | highlighters |
   137 
   138 
   138     | highlighters highlighter |
   139     highlighters := OrderedCollection new.
   139 
       
   140     highlighters := OrderedCollection new: 4.
       
   141     highlighter := self syntaxHighlighter.
       
   142     highlighter notNil ifTrue:[
       
   143         highlighters add: highlighter 
       
   144     ].
   140 
   145 
   141     codeView services do:[:service|
   146     codeView services do:[:service|
   142         | highlighter |
   147         service ~~ self ifTrue:[
   143         highlighter := service syntaxHighlighter.        
   148             highlighter := service syntaxHighlighter.        
   144         highlighter notNil ifTrue:[
   149             highlighter notNil ifTrue:[
   145             "HACK, since AbstractSyntaxHighlighter overwrites
       
   146              emphasis instead of adding it..."
       
   147             (highlighter isKindOf: AbstractSyntaxHighlighter class) ifTrue:[
       
   148                 highlighters addFirst: highlighter                    
       
   149             ] ifFalse:[
       
   150                 highlighters add: highlighter
   150                 highlighters add: highlighter
   151             ].
   151             ].
   152         ]
   152         ]
   153     ].
   153     ].
   154     ^highlighters
   154     ^highlighters
   155 
   155 
   156     "Created: / 05-08-2011 / 10:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   156     "Created: / 05-08-2011 / 10:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   157     "Modified: / 30-07-2013 / 19:29:59 / cg"
   157     "Modified: / 19-07-2012 / 12:58:48 / cg"
       
   158     "Modified: / 23-04-2013 / 01:49:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   158 ! !
   159 ! !
   159 
   160 
   160 !CodeHighlightingService methodsFor:'acessing-defaults'!
   161 !CodeHighlightingService methodsFor:'acessing-defaults'!
   161 
   162 
   162 defaultJobName
   163 defaultJobName
   185     "Modified: / 26-09-2011 / 15:40:23 / cg"
   186     "Modified: / 26-09-2011 / 15:40:23 / cg"
   186     "Created: / 24-01-2012 / 12:11:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   187     "Created: / 24-01-2012 / 12:11:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   187 !
   188 !
   188 
   189 
   189 process: delayed
   190 process: delayed
       
   191 
   190     |oldCode oldCodeList newCode elements cls mthd highlighterClasses|
   192     |oldCode oldCodeList newCode elements cls mthd highlighterClasses|
   191 
       
   192     enabled == false ifTrue:[^ self].      
       
   193 "/    codeView topView class == DebugView ifTrue:[^ self].
   193 "/    codeView topView class == DebugView ifTrue:[^ self].
   194 
   194 
   195     done := false.
   195     done := false.
   196     modified := false.
   196     modified := false.
   197     codeView syntaxElements: nil.
   197     codeView syntaxElements: nil.
   215             oldCodeList := textView list copy.
   215             oldCodeList := textView list copy.
   216         ] valueUninterruptably.
   216         ] valueUninterruptably.
   217 
   217 
   218         "textView" modified ifFalse:[
   218         "textView" modified ifFalse:[
   219             oldCodeList isNil ifFalse:[
   219             oldCodeList isNil ifFalse:[
   220                 oldCode := oldCodeList asStringCollection asStringWithoutEmphasis.
   220                 oldCode := oldCodeList asStringWithoutEmphasis.
   221                 "textView" modified ifFalse:[
   221                 "textView" modified ifFalse:[
   222                     Screen currentScreenQuerySignal answer:codeView device
   222                     Screen currentScreenQuerySignal answer:codeView device
   223                     do:[
   223                     do:[
   224                         Parser parseErrorSignal handle:[:ex |
   224                         Parser parseErrorSignal handle:[:ex |
   225                             |errMsg|
   225                             |errMsg|
   230                             "/ Transcript showCR:'ParseError: ', ex description.
   230                             "/ Transcript showCR:'ParseError: ', ex description.
   231 "/ self halt.
   231 "/ self halt.
   232                             "/ self showInfo:(errMsg colorizeAllWith:Color red).
   232                             "/ self showInfo:(errMsg colorizeAllWith:Color red).
   233                             newCode := nil.
   233                             newCode := nil.
   234                         ] do:[
   234                         ] do:[
   235                             |codeAspect|
   235                             | codeAspect |
   236 
   236                             
   237                             elements := SortedCollection new.
   237                             elements := ParseTreeIndex new.
   238                             newCode := oldCode asText.
   238                             newCode := oldCode asText.
   239                             codeAspect := codeView codeAspect.
   239                             codeAspect := codeView codeAspect.
   240                             codeAspect == SyntaxHighlighter codeAspectMethod ifTrue:[
   240                             codeAspect == SyntaxHighlighter codeAspectMethod ifTrue:[
   241                                 highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using:syntaxPreferences elementsInto: elements].
   241                                 highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using:syntaxPreferences elementsInto: elements].
   242                             ] ifFalse:[
   242                             ] ifFalse:[
   243                                 codeAspect == (SyntaxHighlighter codeAspectExpression) ifTrue:[
   243                                 codeAspect == (SyntaxHighlighter codeAspectExpression) ifTrue:[
   244                                     highlighterClasses do:[:e|newCode := e formatStatementList:newCode in:cls elementsInto: elements].
   244                                     highlighterClasses do:[:e|newCode := e formatExpression:newCode in:cls elementsInto: elements].
   245                                 ] ifFalse:[
   245                                 ] ifFalse:[
   246                                     codeAspect == (SyntaxHighlighter codeAspectClassDefinition) ifTrue:[
   246                                     codeAspect == (SyntaxHighlighter codeAspectClassDefinition) ifTrue:[
   247                                         highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode string in:cls elementsInto: elements].
   247                                         highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode string in:cls elementsInto: elements].
   248                                     ]
   248                                     ]
   249                                 ].
   249                                 ].
   266                                                 for:self
   266                                                 for:self
   267                                                 withArguments:(Array with:newCode with: elements).
   267                                                 withArguments:(Array with:newCode with: elements).
   268                                                 "/self delayedUpdateBufferLabelWithCheckIfModified
   268                                                 "/self delayedUpdateBufferLabelWithCheckIfModified
   269                                         ] ifFalse:[
   269                                         ] ifFalse:[
   270                                             textView contents: newCode.
   270                                             textView contents: newCode.
       
   271                                             codeView syntaxElements: elements.
       
   272                                             gutterView invalidate.
   271                                         ]
   273                                         ]
   272                                     ]
   274                                     ]
   273                                 ]
   275                                 ]
   274                             ].
   276                             ].
   275                         ]
   277                         ]
   277                 ]
   279                 ]
   278             ]
   280             ]
   279         ]
   281         ]
   280     ]
   282     ]
   281 
   283 
   282     "Modified: / 16-09-2011 / 17:01:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   284     "Modified: / 22-08-2011 / 14:17:47 / cg"
   283     "Created: / 24-01-2012 / 12:21:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   285     "Created: / 24-01-2012 / 12:21:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   284     "Modified: / 22-07-2013 / 13:33:40 / cg"
   286     "Modified: / 22-07-2013 / 13:33:40 / cg"
   285 !
   287 !
   286 
   288 
   287 setHighlightedCode:newCode elements: elements
   289 setHighlightedCode:newCode elements: elements
   315                     "/ when the text is converted. This detects the
   317                     "/ when the text is converted. This detects the
   316                     "/ resulting error.
   318                     "/ resulting error.
   317                     "/ Certainly a kludge.
   319                     "/ Certainly a kludge.
   318 
   320 
   319                     oldLine string = line string ifTrue:[
   321                     oldLine string = line string ifTrue:[
       
   322                         | i |
       
   323 
       
   324                         "JV@2012-02-01: Remove any emphasis on leading whitespace"
       
   325                         "(presumably created by LintHighlighter)"
       
   326                         i := line string indexOfNonSeparator.
       
   327                         i > 1 ifTrue:[
       
   328                             | e |
       
   329 
       
   330                             (e := (line emphasisAt: i - 1)) notNil ifTrue:[
       
   331                                 line emphasisFrom: 1 to: i - 1 remove: e.
       
   332                             ]
       
   333                         ].
       
   334 
   320                         oldLine emphasis ~= line emphasis ifTrue:[
   335                         oldLine emphasis ~= line emphasis ifTrue:[
   321                             textView modifiedChannel removeDependent:self.
   336                             textView modifiedChannel removeDependent:self.
   322                             list at:lNr put:line.
   337                             list at:lNr put:line.
   323                             textView modifiedChannel addDependent:self.
   338                             textView modifiedChannel addDependent:self.
   324                             (lNr between:firstShown and:lastShown) ifTrue:[
   339                             (lNr between:firstShown and:lastShown) ifTrue:[
   351             cursorWasOn ifTrue:[
   366             cursorWasOn ifTrue:[
   352                 textView showCursor
   367                 textView showCursor
   353             ]
   368             ]
   354         ]
   369         ]
   355     ].
   370     ].
   356     codeView syntaxElements: elements
   371     codeView syntaxElements: elements.
       
   372     gutterView invalidate.
       
   373 
       
   374 "/    Transcript showCR:'--> rehighlighted ', self identityHash printString.
   357 
   375 
   358     "Modified: / 09-10-2006 / 11:50:17 / cg"
   376     "Modified: / 09-10-2006 / 11:50:17 / cg"
   359     "Created: / 14-02-2010 / 16:10:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   377     "Created: / 14-02-2010 / 16:10:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   360     "Modified: / 16-09-2011 / 17:33:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   378     "Modified (format): / 21-08-2011 / 09:38:22 / cg"
   361     "Modified (format): / 19-07-2012 / 12:07:05 / cg"
   379     "Modified: / 01-02-2012 / 19:18:00 / jv"
       
   380     "Modified: / 17-03-2012 / 19:33:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   362 ! !
   381 ! !
   363 
   382 
   364 !CodeHighlightingService class methodsFor:'documentation'!
   383 !CodeHighlightingService class methodsFor:'documentation'!
   365 
   384 
   366 version
   385 version
   367     ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.46 2013-09-27 15:13:42 cg Exp $'
   386     ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.47 2014-02-05 19:08:27 cg Exp $'
   368 !
   387 !
   369 
   388 
   370 version_CVS
   389 version_CVS
   371     ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.46 2013-09-27 15:13:42 cg Exp $'
   390     ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.47 2014-02-05 19:08:27 cg Exp $'
   372 !
   391 !
   373 
   392 
   374 version_SVN
   393 version_SVN
   375     ^ '$Id: Tools__CodeHighlightingService.st,v 1.46 2013-09-27 15:13:42 cg Exp $'
   394     ^ '$Id: Tools__CodeHighlightingService.st,v 1.47 2014-02-05 19:08:27 cg Exp $'
   376 ! !
   395 ! !
   377 
   396