User Tools

Site Tools


Find Action Classname

Summary

Below is an example demonstrating how you can find the classname of an action using its label, via script.

API Areas of Interest

Example

Action_Find_Classname.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	/*********************************************************************/
	// String : A function for finding the classname of an action
	function findActionClassName( sActionLabel )
	{
		// Get the action manager
		var oActionMgr = MainWindow.getActionMgr();
		// If we do not have an action manager
		if( !oActionMgr ){
			// We are done...
			return "";
		}
 
		// Define a regular expression for stripping accelerators from the label
		var regxAccelerator = new RegExp( "&(.)", "g" );
 
		// Declare working variable
		var oAction;
		// Iterate over the actions
		for( var i = 0, nActions = oActionMgr.getNumActions(); i < nActions; i += 1 ){
			// Get the 'current' action
			oAction = oActionMgr.getAction( i );
			// If the label of the action does not match the one we are looking for
			if( oAction.text.replace( regxAccelerator, "$1" ) != sActionLabel ){
				// Next!!
				continue;
			}
			// Return the class name
			return oAction.className();
		}
 
		// Return an empty string
		return "";
	};
 
	/*********************************************************************/
	// Find the class name of the action
	var sClassName = findActionClassName( "Home..." );
	// If the action was not found
	if( sClassName.isEmpty() ){
		// We are done...
		return;
	}
 
	// Provide feedback
	print( sClassName );
 
// Finalize the function and invoke
})();