The first step in attaching plug-in functionality to a menu is to create an AlFunction object. The AlFunction class encapsulates information about what actions to perform when your plug-in is selected. It represents the ‘back end’ of a menu item. In particular, a plug-in would create an AlMomentaryFunction or an AlContinuousFunction to describe its operation.
To actually define the menu item which will invoke that AlFunction, use the AlFunctionHandle class, which provides a C++ interface to Scheme.
The file AlFunctionHandle.h must be included by the plug-in to use AlFunctionHandle. AlFunction.h must be included to use either AlMomentaryFunction or AlContinuousFunction.
In the plugin_init() function of the plug-in the various methods of the AlFunctionHandle are used to define the menu item (or menu items) that is added to OpenAlias, and the AlFunction classes are used to register the functions which make up the functionality of the plug-in. In the case of using Scheme instead of AlFunctionHandle, plugin_init() would at some point invoke a Scheme file that performs the necessary UI initialization.
General momentary plug-in code would look like the following:
Includes:
#include <AlLiveData.h> #include <AlFunction.h> #include <AlFunctionHandle.h>
Declaration of function and function handles:
static AlFunctionHandle h; static AlMomentaryFunction hFunc;
Attaching to the Alias menus, during plugin_init():
// All plug-ins must initialize the universe AlUniverse::initialize( ); // Create the function and associate the // callback to be invoked. hFunc.create( "plugin_func_name", plugin_callback ); h.create( "PluginFunction", &hFunc ); h.setAttributeString( "PluginFunction" ); // Alias will search for icons named // plugin_func_name.M and plugin_func_name.S // in this directory. h.setIconPath( makeAltPath( dirName, NULL ) ); // Which menu to install on. h.installOnMenu( "al_goto", FALSE /* top */ ); // Let the user know where the plug-in is AlPrintf( kPrompt, "Plug-in function installed under the ’Utilities’ menu."); // All is ok, let Alias know. return 0;
Removing the plug-in from the menus at plugin_exit() time:
// Cleanup any private programmed defined data.
if ( pluginData != NULL )
removeData( pluginData );
// Remove the plugin from the menu and free the FunctionHandle.
h.deleteObject();
hFunc.deleteObject();
// All is ok, let Alias know.
return 0;
Continuous plug-ins follow a similar programming pattern.
Declaration of function handles:
static AlFunctionHandle h; static AlContinuousFunction hFunc;
Attaching to the Alias menus, during plugin_init():
AlUniverse::initialize(); // Continuous callbacks are specified. hFunc.create( "Continuous", init_func, down_func, move_func, up_func, cleanup_func, TRUE ); hFunc.setPrompt( my_prompt, inbuf, kFilterNone ); h.create( "Cont Test", &hFunc ); h.setAttributeString( "cont" ); h.setIconPath( makeAltPath( dirName, NULL ) ); h.addToMenu( "mp_objtools" ); AlPrintf( kPrompt, "Continuous example installed on Palette ’Object Edit."); return 0;
Removing a plug-in’s menus at plugin_exit() time is the same for both continuous and momentary plug-ins.