### Install Magritte for Pharo Smalltalk Source: https://github.com/magritte-metamodel/magritte/blob/master/README.md Instructions for installing Magritte on Pharo Smalltalk versions 6.x through 11.x using Metacello. It also mentions alternative methods for Pharo 4.x and previous versions. ```Smalltalk Metacello new baseline: 'Magritte'; repository: 'github://magritte-metamodel/Magritte'; load ``` -------------------------------- ### Using MAChainAccessor for Meta-Described Accessors Source: https://github.com/magritte-metamodel/magritte/wiki/Features Illustrates how to use Magritte's MAChainAccessor and MASelectorAccessor to read object properties dynamically. This example shows how to access `Smalltalk os isMacOSX:` through a chain of selectors. ```smalltalk myDescription read: Smalltalk "==> true | false" ``` -------------------------------- ### Displaying Alternate Descriptions in Glamour Browser Source: https://github.com/magritte-metamodel/magritte/wiki/Alternate-Descriptions-(Experimental) An example of how to use the retrieved alternate descriptions to populate a Glamour browser. It iterates through all descriptions for '#descriptionMessages' and displays them with their respective labels and content. ```smalltalk projectPresentationsIn: container for: messages (projectList magritteAllDescriptionsFor: #descriptionMessages) do: [ :d | container fastTree display: [ :l | d read: messages ]; title: d label; children: #children ] ``` -------------------------------- ### Description-Aware Lazy Initialization Source: https://github.com/magritte-metamodel/magritte/wiki/Cookbook Provides an example of description-aware lazy initialization, where a field's value is returned, or a default value from its description is used if the field is not yet initialized. ```smalltalk MyDomainObject>>#getter ^ self maLazyFromDescriptionOf: #getter ``` ```smalltalk MyDomainObject>>#getterDescription ^ MAElementDescription new accessor: #getter; default: 1; yourself ``` -------------------------------- ### Automatic Merging Condition in Smalltalk Source: https://github.com/magritte-metamodel/magritte/blob/master/FEATURES.md This Smalltalk code snippet demonstrates how to define an automatic merging condition for a field. It uses the `#shouldAutoMergeBlock` property on a `MAStringDescription` to specify logic for merging when a first name changes, ensuring the new name starts with the same letter as the old one (after removing any trailing period). ```smalltalk Name>>#descriptionFirstName ^ MAStringDescription new accessor: #firstName; propertyAt: #shouldAutoMergeBlock put: [ :old :new | | oldNoPeriod | oldNoPeriod := old trimRight: [ :e | e = $. ]. oldNoPeriod size = 1 and: [ new beginsWith: oldNoPeriod ] ]; yourself ``` -------------------------------- ### Add New Object Source: https://github.com/magritte-metamodel/magritte/wiki/Cookbook Demonstrates how to add a new object using Magritte, including setting up its morphic representation, adding buttons and windows, and handling the answer callback to add the new project to a collection. ```smalltalk add self new asMagritteMorph addButtons; addWindow; onAnswer: [ :newProject | self projects add: newProject ]; openInWorld ``` -------------------------------- ### Define Magritte Action Description Source: https://github.com/magritte-metamodel/magritte/wiki/Actions Demonstrates how to create a Magritte action description. It sets a label for the action and defines the behavior to be executed when the action is triggered, in this case, copying a baseline load snippet to the clipboard. ```smalltalk descriptionClipBaseline MAActionDescription new label: 'Copy Baseline Load Snippet'; "[1]" action: [ Clipboard clipboardText: self baselineLoadSnippet ]; yourself ``` -------------------------------- ### Object Equality and Hashing with Magritte Source: https://github.com/magritte-metamodel/magritte/wiki/Features Demonstrates how to implement object equality and hashing using Magritte's `#isSameAs:` and `#maHash` methods. It shows delegation patterns for redefining the `=` and `hash` methods. ```smalltalk = rhs re^ self isSameAs: rhs ``` ```smalltalk hash ^ self maHash ``` -------------------------------- ### Smalltalk Description Property Management Source: https://github.com/magritte-metamodel/magritte/wiki/Storing-(i.e.,-` This Smalltalk snippet demonstrates an experimental approach to managing description properties within the Magritte metamodel. It defines a required boolean description with specific accessors, labels, priorities, and default values, aiming to resolve data storage inconsistencies. ```smalltalk descriptionRequired ^ MABooleanDescription new accessor: (MAPropertySelectorAccessor selector: #required); label: 'Required'; priority: 220; default: self class defaultRequired; yourself ``` -------------------------------- ### Dynamic Descriptions in Magritte Source: https://github.com/magritte-metamodel/magritte/wiki/FAQ This snippet explains two primary methods for creating dynamic descriptions in Magritte. The first involves overriding the #description method on the instance side and programmatically building descriptions, emphasizing the need to copy descriptions if calling super. The second method uses blocks passed to #asDynamicObject, with considerations for proxy object behavior, serialization, debugging, and access to the described object. ```Smalltalk "Method 1: Override #description" MyClass>>description | desc | desc := super description. "Modify desc programmatically" ^ desc copy. "Method 2: Use #asDynamicObject" MyClass>>someProperty ^ self property: #someProperty value: ([:obj | obj calculateDynamicDescription] asDynamicObject) ``` -------------------------------- ### Meta-describe ZnUrl with MAStringDescription Source: https://github.com/magritte-metamodel/magritte/wiki/Describing-Basic-Types This snippet demonstrates how to define a Magritte description for the ZnUrl class using MAStringDescription. It configures the accessor to read the URL as a string and parse it back for writing, highlighting a common technique for describing basic classes. ```smalltalk ZnUrl >> #descriptionString ^ MAStringDescription new accessor: (MASelectorAccessor read: #asString write: #parseFrom:); yourself ``` -------------------------------- ### Add Magritte as a Project Dependency Source: https://github.com/magritte-metamodel/magritte/blob/master/README.md This snippet shows how to add Magritte as a project dependency in a Baseline or Configuration definition for Smalltalk projects. It specifies the repository and the 'Core' group to load, with a note to adjust the release version as needed. ```Smalltalk baseline: 'Magritte' with: [ spec repository: 'github://magritte-metamodel/magritte:v3.8'; loads: #(Core) ]; ``` -------------------------------- ### Extend Description with Annotation Source: https://github.com/magritte-metamodel/magritte/wiki/Cookbook Shows how to extend an existing Magritte description from an external package using the `magritteDescription:` annotation. This is useful when the original description's package cannot be modified. ```smalltalk MARelationDescription>>#descriptionClassesWithMorphic: description ^ description morphClass: MATokenCompletionMorph; yourself ``` -------------------------------- ### GT-Inspector Integration (Smalltalk) Source: https://github.com/magritte-metamodel/magritte/wiki/Developer-Tools Annotates description constructors using `ClyTagInspectorExtensionCommand` to display them as tabs within the GT-Inspector. This allows for easier inspection and interaction with the described fields. ```smalltalk ClyTagInspectorExtensionCommand ``` -------------------------------- ### Generate Boilerplate from Descriptions (Smalltalk) Source: https://github.com/magritte-metamodel/magritte/wiki/Developer-Tools Generates instance variables, getters, and setters from description objects. This process is typically initiated by calling a method like `instVarBoilerplateFromDescriptions` on a class that has defined its descriptions. ```smalltalk MyObject >> #fieldDescription ^ MAStringDescription new accessor: #field; yourself ``` ```smalltalk MyObject instVarBoilerplateFromDescriptions ``` -------------------------------- ### Print Object Using Magritte Descriptions Source: https://github.com/magritte-metamodel/magritte/wiki/Cookbook Illustrates how to use the `printMagritteOn:` method to concatenate child descriptions into a print string for an object. This method is inherited by Object. ```smalltalk MyDescribedObject>>#printOn: aStream self printMagritteOn: aStream ``` -------------------------------- ### Retrieving Alternate Descriptions Source: https://github.com/magritte-metamodel/magritte/wiki/Alternate-Descriptions-(Experimental) Demonstrates how to retrieve alternate descriptions for a given field using Magritte's hooks. 'magritteAlternatesFor:' retrieves only the alternates, while 'magritteAllDescriptionsFor:' retrieves all descriptions within the group. ```smalltalk myObject magritteAlternatesFor: #descriptionMessages myObject magritteAllDescriptionsFor: #descriptionMessages ``` -------------------------------- ### Adding Conditions to Container Description Source: https://github.com/magritte-metamodel/magritte/wiki/Conditions Demonstrates how to add a condition to a container description that checks if either day or night is selected. It uses the `#readUsing:` method to access fields polymorphically. ```smalltalk descriptionContainer d^ super descriptionContainer addCondition: [ :obj | (obj readUsing: self descriptionIncludesDay) or: [ obj readUsing: self descriptionIncludesNight ] ] labelled: 'Neither day or night is selected' yourself ``` -------------------------------- ### Add Magritte Actions to Browser Context Menu Source: https://github.com/magritte-metamodel/magritte/wiki/Glamour This function automatically makes Magritte actions available in the context menu of a browser. It's a utility for enhancing user interaction within Magritte-powered applications. ```Python aPresentation glmAddSelectionActions ``` -------------------------------- ### Custom CSS Styling for Magritte Descriptions Source: https://github.com/magritte-metamodel/magritte/wiki/FAQ This snippet demonstrates how to apply custom CSS styling to a specific description within a Seaside form using the Magritte metamodel. It shows how to send the #cssClass: message to add an additional CSS class to the element associated with the description. ```Smalltalk "Applying custom CSS class to a description" MyForm>>descriptionForMyField ^ super descriptionForMyField cssClass: 'my-custom-class' ``` -------------------------------- ### In-Place Merging Override Source: https://github.com/magritte-metamodel/magritte/wiki/Merging This code snippet demonstrates how to override the `patchRelativeToBase:as:of:` method to enable in-place merging of object fields instead of a full replacement. This allows for more granular control over updates to individual fields within an object. ```smalltalk patchRelativeToBase: oldValue as: description of: receiver "Edit me in place instead of full replacement like a value object" ^ self patchRelativeToBase: oldValue ``` -------------------------------- ### Handling Inter-Condition Dependencies Source: https://github.com/magritte-metamodel/magritte/wiki/Conditions Illustrates how to use `MADescription>>#addCondition:labelled:ifValid:` to ensure a condition is only validated if another condition has already passed. This is useful for scenarios like validating a holiday date only if the date itself is valid. ```smalltalk "Example of a guard for inter-condition dependencies (pre-formal API)" addCondition: [ :obj | ("check dependency") or: [ "validation requiring a date" ] ] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.