[Cuis-dev] Advanced: Dealing with optional Class uses.

Mark Volkmann r.mark.volkmann at gmail.com
Thu Jul 25 17:20:53 PDT 2024


Thanks so much for this detail!

On Thu, Jul 25, 2024 at 2:32 PM <ken.dickey at whidbey.com> wrote:

> Mark,
>
> This is an advanced usage, but I thought to mention it because you will
> sometimes load a package which references undefined classes.
>
> E.g. when you `Feature require: 'UI-MetaProperties'.` you will see
> Transcript entries like the following.
>
> vvv===vvv
> Package UI-DragAndDrop successfully installed
> Undeclared: a Dictionary(#MetaProperty->nil
> #MetaPropertyMultiSelect->nil)
> ^^^===^^^
>
> This is a case of "forward reference" where one needs to break circular
> Package dependencies.
>
> In these cases, you should see some "guard code" as in the following.
>
> VVV===VVV==UI-DragAndDrop.pck.st==V
> !FontMorph methodsFor: 'dropping/grabbing' stamp: 'KenD 2/9/2022
> 06:50:39'!
> dropAction: aDropTargetMorph
>         "Find accepting MetaProperties of target morph
>          and allow user to choose action."
>
>         | metaPropsForMyValue myValue choices selection |
>         (Smalltalk includesKey: #MetaProperty) ifFalse: [^nil ].
>
>         myValue := self valueWhenDropped.
>         metaPropsForMyValue :=
>                 (MetaProperty metaPropsForMorph:
>                                 aDropTargetMorph targetMorph)
>                         select: [ :metaProp | metaProp accepts: myValue ].
>         (metaPropsForMyValue size isZero) ifTrue: [^nil ].
>
>         choices := OrderedCollection with: #Cancel.
>         choices addAll: (metaPropsForMyValue keys).
>
>         "I am being carried by the hand.  Disappear and let user make a
> choice."
>         self delete.
>         selection := PopUpMenu withCaption: 'Choose setter'
>                                                 chooseFrom: choices.
>         (selection = 1) ifFalse: [ "1 -> Cancel" | propName setterSym |
>                 propName := choices at: selection.
>                 setterSym := (propName , ':') asSymbol.
>                 aDropTargetMorph targetMorph
>                         perform: setterSym
>                         with: myValue ;
>                         triggerEvent: #propertyChanged.
>         ].! !
> ^^^===^^^
>
> In this case DragAndDrop code uses MetaProperties only if they are
> loaded.
> [NB: UI-MetaProperties requires UI-DragAndDrop].
>
> So expect to see something like
>    (Smalltalk includesKey: #MetaProperty) ifFalse: [ ^nil ]. "guard"
>
> If you see a dependency which is not handled this way, it is a sign that
> someone forget to add a Feature/Package dependency to the package you
> are loading.  Easy to being up the Installed Packages browser and add,
> then recheck.
>
> Perhaps a mention if/when you describe making a package.  Note:
>
>
> https://github.com/Cuis-Smalltalk/Learning-Cuis/blob/master/SamplePackage1.md
>
> Cheers,
> -KenD
>
>

-- 
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240725/3fc17081/attachment.htm>


More information about the Cuis-dev mailing list