Building Dynamic Editors using the AlEditor class
 
 
 

The new technique for building editors in OpenAlias plug-ins is considered dynamic since a plug-in developer has control over when the editor is displayed. The older scheme editor boxes were only capable of being displayed when the user selected the tool from the menu.

Creating and managing editors follows general API programming principles:

To create the editor:

	apieditor = new AlEditor;
	if ( apieditor == NULL )
		return sFailure;
	if ( apieditor->create( "Dynamic Editor Example" ) != sSuccess )
		return sFailure;

Once the editor has been created, UI components can be added to it:

	ComponentDescriptor *descriptor = NULL;
	descriptor = new ComponentDescriptor("Enter some text");
	if ( apieditor->addString( descriptor, "Hello world!", idStringCallback ) != sSuccess )
		return sFailure;
	addToDesciptorList( descriptor );
	
	descriptor = new ComponentDescriptor("Separator");
	if ( apieditor->addSeparator( descriptor ) != sSuccess )
		return sFailure;
	addToDesciptorList( descriptor );
	descriptor = new ComponentDescriptor("Check Box");
	if ( apieditor->addCheckBox( descriptor, checkValue, idCallback ) != sSuccess )
		return sFailure;
	addToDesciptorList( descriptor );

The AlEditor class assigns dynamic identifiers to the descriptor for the UI component. Each descriptor must be kept for later look up and matching so that the correct action can be performed.

We then open the editor:

	if ( apieditor->open() != sSuccess )
		return sFailure;

To close the editor:

	if ( apieditor->close() != sSuccess )
		return sFailure;
	if ( apieditor->deleteEditor() != sSuccess )
		return sFailure;
	deleteDescriptorList();
	delete apieditor;

Events associated with the UI component on the editor are passed to the plug-in via a callback that is defined by the programmer.

	if ( apieditor->addCheckBox( descriptor, checkValue, idCallback ) != sSuccess )
		return sFailure;
	...
static void idCallback( ComponentId id )
{
	ComponentDescriptor *descriptor = idToDescriptor( id );
	if ( descriptor == NULL )
		return;
	if ( matchDescriptorToLabel( descriptor, "Check Box" ) )
	{
		HandleCheckBoxFunction();
	}
}