Introduction to MetaTypes (Script)

From Lianjapedia
Jump to: navigation, search

Watch the Video

What are MetaTypes (0:00)

What are MetaTypes


MetaTypes provide a powerful means of defining components and then subclassing them in Pages, Sections and FormItems.


Each MetaType that you define in the MetaType Editor can contain attribute/value pairs as well as delegates and their procedure or function names.


Essentially a MetaType is a 'class' which can be inherited simply by specifying its name in the 'Meta Types' attribute for user interface elements.


For example, here the 'searchMenu' MetaType defines 5 attributes and one delegate.


And it has been applied to 2 field Formitems and 1 Section.


When applied to Formitems, it specifies that they should appear in their section's automatically created Search Panel.


When applied to sections, it specifies that they should have a visible, automatically created Search Panel,


A visible menu, with the option 'Search'


And a custom delegate to be run when a menu is selected.

MetaTypes Files (1:30)

MetaTypes Files


Before opening the MetaType Editor, decide whether you want these MetaTypes to apply just to the current App or whether you want to use them for multiple Apps.


For multiple Apps, first open a Project.


That way, when you save MetaTypes in the Editor, they will be saved to a file with the same basename as the project in the metatypes folder.


This will be the default file used by the MetaType Editor in all Apps in this project.


It will also be listed in the headerbar, allowing it to be selected as the metatypes file for any App.


If you do not have a project open, the metatypes file will be created in the App and will not appear in the headerbar list for other Apps.


The name and location of the metatypes file, and the metatypes library file - where the delegate code is stored - are in the 'General App Configuration' App Settings, so can be viewed or changed as required.


Note the 'app:/' prefix showing that the files are located in the App.


And when the files are in the shared metatypes folder, they have a 'metatypes:/' prefix.

The MetaType Editor (3:11)

The MetaType Editor


The MetaType Editor is accessed from the system menu or from its headerbar toolbutton - these operate as toggles.


To create a MetaType, click the + button then enter a name for the MetaType - this should be unique in this metatypes file.


I'm going to call it 'searchPanelToggle'.


Then in the Attributes panel, select Page, Section or Formitem, then double-click the attribute to be defined.


I am starting here with the Section 'searchPanelVisible' attribute.


The help panel displays information about the attribute.


And the 'Value' field changes depending on its type.


So I now have the options of 'True' or 'False'.


I'll select 'True' and click the green tick to save.


I can edit this Attribute definition by double-clicking in the MetaTypes panel or clicking the edit icon in the actionbar.


To delete it, use the delete icon.


To define another attribute for the searchPanelToggle metatype, just double-click on its name.


So specify that this should be an auto-create Search Panel (searchPanelAutoCreate = True).


Make the Section menu visible (sectionMenuVisible = True).


And specify a Search menuitem (customSectionMenu = Search).


I'm also going to define the delegate to be called when the menu option is selected.


Click the button to create and edit the code in a floating Script Editor.


The usual Script Editor right-click menu options are available.


When you have finished editing, click 'Done' to save and exit.


MetaTypes can of course be applied to different element types.


To define attributes or delegates for Pages or Formitems, select using the pulldown, then double-click the attribute as before.


Here, Formitems with this MetaType will be included in their section's auto-created search panel.


Once you have completed entering MetaTypes and their attributes, click 'Save' to commit them to the metatypes file.


'Undo' will delete uncommitted changes.


'Apply' will apply changes to UI elements that have metatypes already specified.


The system menu or headerbar toggles or the window x can be used to close the MetaType Editor.

Applying MetaTypes (6:07)

Applying MetaTypes


To specify a MetaTypes for a particular UI element, access its Attributes from its Attributes dialog or the Attributes tab if you have the App Inspector open.


Click the button to display all currently available MetaTypes.


Use the checkboxes to select or deselect them.


Reorder the MetaTypes using the row selection icons.


The order of the MetaTypes is important if they change the same attribute: the last defined MetaTypes will be the last applied so will overwrite earlier changes.


Once MetaTypes have been specified for a UI element, when you make any changes to a MetaTypes in the MetaType Editor you can just click 'Apply' to have the elements updated with the changes.


Remember you need to click the 'Save' button to commit changes to the metatypes file.