[Cuis-dev] How do I save code changes into CuisCore ?
Nicola Mingotti
nmingotti at gmail.com
Mon Aug 2 00:05:02 PDT 2021
Hi Ken,
For the moment what I need is the procedure [A].
But I mark procedure [B] for further study, thank you for sharing it !
bye
Nicola
On 8/1/21 11:00 PM, ken.dickey at whidbey.com wrote:
> On 2021-08-01 09:59, Nicola Mingotti via Cuis-dev wrote:
>
>> But now I need to save some changes into what the ChangeSorter calls
>> "CuisCore".
>>
>> How do I do that ?
>
> Two ways:
> [A] Post it here and convince everyone (i.e. Juan) that this is best
> for Cuis
> [B] Do it in a package, but do it safely.
>
> This last bit is a useful thing to know about in any case.
>
> You can subclass CodePackage and add a class method #prePackageInstall
> (there is also a #postPackageInstall). There you can check that you
> are overriding a base system method which has not been changed.
>
> https://github.com/Cuis-Smalltalk/Morphic/Morphic-Misc1 does this.
>
> In the Morphic-Misc1 Package, there is a class #MorphicMisc1Package
> which is a subclass of CodePackage.
>
> vvv======vvv
> MorphicMisc1Package class >> prePackageInstall
>
> "Check that any method in base image that I wish to override has not
> changed"
> "Morph>>changeColor Last updated 2013-03-05T13:29:00+00:00 @@"
>
> self assert:
> (Morph methodDictionary at: #changeColor) dateAndTime =
> (DateAndTime
> year: 2013
> month: 3
> day: 5
> hour: 13
> minute: 29
> second: 0).
> ^^^======^^^
>
> The Morphic-Misc1 Package has added a method to the Morph class in
> method category #'*morphic-misc1' in the same way as adding a
> non-override method to a base class. In this case, the overridden
> method #Morph>>changeColor.
>
> This means that when the Morphic-Misc1 Package is saved via the
> Package Browser, the overridden method #Morph>>changeColor is saved
> into the Morphic-Misc1 Package along with other base-added methods in
> method category #'*morphic-misc1'.
>
> So now, when you "Feature require: #'Morphic-Misc1'.", the assert is
> checked _before_ the package code is loaded, and the assert fails if
> the base class method was changed. You really want to be sure you are
> only overriding what you know about, right? The assert fails
> _before_ #Morph>>changeColor has been overridden, so no damage has
> been done to base.
>
> If the assert succeeds, the package is loaded and Morph>>changeColor
> is now overridden. If it fails, people complain until you check that
> you are still doing the right thing and update the timestamp.
>
> Another way you can do this is to put up a popup question to let the
> user decide, see next.
>
> I have a (very large) mess of code in
> https://github.com/KenDickey/BeeYourself which has a PowerLang
> Package. The salient bit of chunkified file source is below, but I
> don't think you will have a problem reading it.
>
> vvv======vvv
> !classDefinition: #PowerLangPackage category: #'Powerlang-Core'!
> CodePackage subclass: #PowerLangPackage
> instanceVariableNames: ''
> classVariableNames: ''
> poolDictionaries: ''
> category: 'Powerlang-Core'!
> !classDefinition: 'PowerLangPackage class' category: #'Powerlang-Core'!
> PowerLangPackage class
> instanceVariableNames: ''!
>
> !PowerLangPackage class methodsFor: 'installing' stamp: 'KenD 6/7/2021
> 14:34:38'!
> prePackageInstall
>
> "We override SystemDictionary>>globals.
> Let the user OK or bring up debugger.."
>
> self assert: (PopUpMenu confirm:
> 'PowerLang overrides SystemDictionary>>globals; Yes->OK |
> No->Debug').
>
> "We may have been loaded before. If not, capture COPY of
> Smalltalk SystemDictionary initial bindings."
> (Smalltalk includesKey: #globals)
> ifFalse: [ Smalltalk at: #globals put: Smalltalk copy ].
> "Might have nil globals; just in case.."
> (Smalltalk at: #globals)
> ifNil: [ Smalltalk at: #globals put: Smalltalk copy ].
> ! !
>
> !PowerLangPackage class methodsFor: 'installing' stamp: 'KenD 6/7/2021
> 14:10:45'!
> postPackageInstall
>
> self inform: 'PowerLang is PRE-alpha. Expect breakage'! !
>
> ^^^======^^^
>
> HTH,
> -KenD
>
More information about the Cuis-dev
mailing list