[squeak-dev] The Trunk: System-mt.1240.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Jul 21 08:50:48 UTC 2021


Marcel Taeumel uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-mt.1240.mcz

==================== Summary ====================

Name: System-mt.1240
Author: mt
Time: 21 July 2021, 10:50:42.926807 am
UUID: 6c7a59f2-afd8-467e-b0f2-80197d8ae3e1
Ancestors: System-mt.1239

Adds new AppRegistry to manage text stylers for different language syntaxes. With this, you can make you app independent from the particular styler being present in the system.

In Trunk we only have a Shout styler for Smalltalk: #SHTextStylerST80. Yet, there is also one for #Markdown here: https://github.com/hpi-swa-teaching/MarkdownEditor -- There might be more in the future.

Especially Squeak's HelpBrowser can benefit from decoupling the concept of syntax highlighting on help pages from the actual implementation of such stylers. There might not only be Smalltalk code to be styled on the many pages of a help book.

Finally, this AppRegistry removes the need of sprinkling #SHTextStylerST80 all over the place. Just write "TextStyler for: #Smalltalk".

=============== Diff against System-mt.1239 ===============

Item was added:
+ AppRegistry subclass: #TextStyler
+ 	instanceVariableNames: ''
+ 	classVariableNames: ''
+ 	poolDictionaries: ''
+ 	category: 'System-Applications'!
+ 
+ !TextStyler commentStamp: 'mt 7/21/2021 10:30' prior: 0!
+ I am an AppRegistry that manages multiple provider classes that can style multiple language syntaxes.
+ 
+ All providers are expected to have the public Shout interface for text styling. For the view-callback protocol, this encompasses:
+   #view:
+   #style: (with #stylerStyled: callback)
+   #styleInBackgroundProcess: (with #stylerStyledInBackground: callack)
+ There is also more direct way to control text attributes in text objects via #styledTextFor: und #unstyledTextFrom:.
+ 
+ Note that existing model-view composites for text editing apply an extra check on top of such stylers via #okToStyle and #aboutToStyle:(requestor:). From there, models tend to configure text stylers as follows:
+   #environment:
+   #classOrMetaClass:
+   #context:
+   #parseAMethod:
+   #sourceMap:
+   #workspace:
+ While this only applies to #Smalltalk code styling, it might be advisable to stub those methods for better compatibility -- especially if you plan to use your custom styler in models such as Debugger, Inspector, SyntaxError, and Workspace.!

Item was added:
+ ----- Method: TextStyler class>>askForDefault (in category 'defaults - Smalltalk') -----
+ askForDefault
+ 
+ 	^ self askForDefaultFor: #Smalltalk!

Item was added:
+ ----- Method: TextStyler class>>askForDefaultFor: (in category 'defaults') -----
+ askForDefaultFor: syntax
+ 
+ 	| knownStylerClasses newDefault |
+ 	knownStylerClasses := registeredClasses at: syntax ifAbsent: [#()].
+ 	knownStylerClasses ifEmpty:
+ 		[self inform: 'There are no stylers for ', syntax printString, ' registered.'.
+ 		^ self default: nil for: syntax].
+ 	knownStylerClasses size = 1 ifTrue:
+ 		[^ self default: knownStylerClasses anyOne for: syntax].
+ 	newDefault := UIManager default 
+ 		chooseFrom: (knownStylerClasses collect: [:ea | ea nameForViewer])
+ 		values: knownStylerClasses
+ 		title: 'Which styler for ', syntax printString, ' would you prefer?'.
+ 	self
+ 		default: (newDefault ifNil: [knownStylerClasses anyOne])
+ 		for: syntax.
+ 	^ self defaultFor: syntax!

Item was added:
+ ----- Method: TextStyler class>>default (in category 'accessing - Smalltalk') -----
+ default
+ 	
+ 	^ self defaultFor: #Smalltalk!

Item was added:
+ ----- Method: TextStyler class>>default: (in category 'accessing - Smalltalk') -----
+ default: aClassOrNil
+ 
+ 	^ self default: aClassOrNil for: #Smalltalk.!

Item was added:
+ ----- Method: TextStyler class>>default:for: (in category 'accessing') -----
+ default: aClassOrNil for: syntax
+ 
+ 	| oldDefault |
+ 	oldDefault := default at: syntax ifAbsent: [].
+ 	aClassOrNil
+ 		ifNil: [ default removeKey: syntax ifAbsent: []]
+ 		ifNotNil: [
+ 			self register: aClassOrNil for: syntax.
+ 			default at: syntax put: aClassOrNil ].
+ 	^ oldDefault!

Item was added:
+ ----- Method: TextStyler class>>defaultFor: (in category 'accessing') -----
+ defaultFor: syntax
+ 
+ 	^ default
+ 		at: syntax
+ 		ifAbsent: [self askForDefaultFor: syntax]!

Item was added:
+ ----- Method: TextStyler class>>defaultOrNil (in category 'accessing - Smalltalk') -----
+ defaultOrNil
+ 
+ 	^ self defaultOrNilFor: #Smalltalk!

Item was added:
+ ----- Method: TextStyler class>>defaultOrNilFor: (in category 'accessing') -----
+ defaultOrNilFor: syntax
+ 
+ 	^ default at: syntax ifAbsent: []!

Item was added:
+ ----- Method: TextStyler class>>for: (in category 'accessing') -----
+ for: syntax
+ 	"For convenience."
+ 	
+ 	^ self defaultOrNilFor: syntax!

Item was added:
+ ----- Method: TextStyler class>>initialize (in category 'class initialization') -----
+ initialize
+ 	"Manage syntax-specific stylers."
+ 	
+ 	registeredClasses := Dictionary new.
+ 	default := Dictionary new.!

Item was added:
+ ----- Method: TextStyler class>>register: (in category 'registration - Smalltalk') -----
+ register: aProviderClass
+ 
+ 	self register: aProviderClass for: #Smalltalk.!

Item was added:
+ ----- Method: TextStyler class>>register:for: (in category 'registration') -----
+ register: aProviderClass for: syntax
+ 
+ 	| knownStylers |
+ 	knownStylers := registeredClasses at: syntax ifAbsentPut: [Set new].
+ 	(knownStylers ifAbsentAdd: aProviderClass) ifTrue: [
+ 		knownStylers size > 1
+ 			ifTrue: ["Ask for a new default if there are alternatives."
+ 				self default: nil for: syntax]
+ 			ifFalse: [
+ 				self default: aProviderClass for: syntax]].!

Item was added:
+ ----- Method: TextStyler class>>unregister: (in category 'registration - Smalltalk') -----
+ unregister: aProviderClass
+ 
+ 	self unregister: aProviderClass for: #Smalltalk.!

Item was added:
+ ----- Method: TextStyler class>>unregister:for: (in category 'registration') -----
+ unregister: aProviderClass for: syntax
+ 	((self defaultFor: syntax) = aProviderClass)
+ 		ifTrue: [self default: nil for: syntax].
+ 	(self registeredClasses at: syntax ifAbsent: [Set new])
+ 		remove: aProviderClass ifAbsent: [].!



More information about the Squeak-dev mailing list