Loaded method examples
You can create a class method called loaded that performs any initialization your application needs after it is loaded into a user's image.
Adding parts to the palette
In Adding parts to the palette, you learned how to write a method that added your part to the parts palette. The loaded method of your edit application is a good place to call this code, by sending the addPartToCatalog message to your part's class:
loaded
"Add the timer to the parts palette."
MyTimer addPartToCatalog.
You must do this in the edit application, not the runtime application.
Adding your own category
If you have several parts, consider adding your own category to the parts palette, instead of placing your parts in one of the existing categories. To do this, you use the abtAddPartsToCatalog message in your loaded method, and you implement class methods that describe your category and its parts.
loaded
"Add the parts to the parts palette"
self abtAddPartsToCatalog.
VA Smalltalk implements the abtAddPartsToCatalog method for you, but you must implement the following methods that describe your parts and your category. You must implement these methods in the edit application, not the runtime application. Replace the category name, the descriptive category name, the icon descriptor, the open icon descriptor, and the names of the parts to match your parts:
abtPaletteCategoryName
"Answer my category name"
^'Sample Parts'
abtPaletteCategoryDisplayName
"Answer the descriptive (translated) name of the category"
^'Sample Parts'
abtPaletteCategoryGraphicsDescriptor
"Answer the icon for the category"
^(AbtIconDescriptor new
moduleName: 'abtico50';
id: 9902).
abtPaletteOpenCategoryGraphicsDescriptor
"Answer the opened icon for the category"
^(AbtIconDescriptor new
moduleName: 'abtico50';
id: 9912).
abtPaletteParts
"Answer the list of parts"
^#(MyTimer MyClipboardToolsView MyShape)
Loading message files
To register and load a message file, use a loaded method like the one below, which uses the information provided in abtExternalizedStringBuildingInfo. Substitute your message file name for 'mymri?00'. To learn more about creating message files and loading message files for different national languages, refer to National language support.
loaded
self abtRegisterExternalStrings.
abtRegisterExternalStrings
"Register the receiver's MPR."
AbtNLSCoordinator addRegistration: AbtMRIManager nlsRegistrationType
registrationObject: self.
System imageStarted ifTrue: AbtNLSCoordinator processRegistrations ].
abtRegisterExternalStrings uses the information provided in abtExternalizedStringBuildingInfo to register the correct MPR. Provide a class method as follows:
abtExternalizedStringBuildingInfo
^Array
with: 'mymri?00' "filename without extension"
with: false "NOT platform dependent"
with: true. "DO recurse subApplications"
Setting class variables
You can also initialize class variables in your loaded method. This example sets a variable that represents an error message threshold level:
loaded
"Initialize a class variable"
ErrorNotifier messageLevel: 3.
A method like this one is appropriate for either your runtime or your edit application's loaded method.
Last modified date: 06/12/2018