/* Adds this plug-in's menus.
*/
static AIErr AddMenu ( SPInterfaceMessage* message )
{
	AIErr error = kNoErr;
	g->aboutPluginMenu = nil;
	// Add a menu item to the About SDK Plug-ins menu group.
	SDKAboutPluginsHelper aboutPluginsHelper;
	error = aboutPluginsHelper.AddAboutPluginsMenuItem(message, 
				kSDKDefAboutSDKCompanyPluginsGroupName, 
				ai::UnicodeString(kSDKDefAboutSDKCompanyPluginsGroupNameString), 
				"Tutorial...", 
				&g->aboutPluginMenu);
	return error;
}
Exemple #2
0
ASErr Ai2VltPlugin::AddMenus(SPInterfaceMessage* message)
{
	ASErr error;
	SDKAboutPluginsHelper aboutPluginsHelper;
	error = aboutPluginsHelper.AddAboutPluginsMenuItem(message, 
		"AboutVioletPluginsGroupName", 
		ai::UnicodeString("About Violet Plug-Ins"),
		"Ai->Violet...", 
		&this->m_aboutMenu);
	if (error) return error;
	
	error = sAIMenu->AddMenuItemZString(message->d.self,
		"Violet Menu Item",
		kToolPalettesMenuGroup,
		ZREF("Violet"),
		kMenuItemWantsUpdateOption,
		&m_panelMenu);
	return error;
}
extern AIErr addMenu( SPInterfaceMessage *message ) {

	AIErr error = kNoErr;

	// Add a menu item to the About SDK Plug-ins menu group.
	SDKAboutPluginsHelper aboutPluginsHelper;
	aboutPluginsHelper.AddAboutPluginsMenuItem(message, 
				kSDKDefAboutSDKCompanyPluginsGroupName, 
				ai::UnicodeString(kSDKDefAboutSDKCompanyPluginsGroupNameString), 
				"MenuPlay...", 
				&g->aboutPluginMenu);

	// Add other menus.
	AIMenuItemHandle		throwAwayAIMenu;
	AIPlatformAddMenuItemData throwAwayMenuData;
	AIMenuGroup				throwAwayMenuGroup;
	char strBuffer[255];
	
	#define kMenuPlayMenuGroup	"Menu Play Group"
	#define kSDKMenuGroup	"SDK Group"
	
	// First we create a normal plug-in menu to use a hierarchical root							
	throwAwayMenuData.groupName = "Window Utilities";
	
	error = sADMBasic->GetIndexString(message->d.self, kMenuStringResID, 1, strBuffer, sizeof(strBuffer));
	if (error)
		goto error;
	throwAwayMenuData.itemText = SUctopstr ( strBuffer );
  
	error = sMenu->AddMenuItem( message->d.self, kSDKMenuGroup, &throwAwayMenuData, 
								0, &throwAwayAIMenu );
	if ( error )
		goto error;

	// Now we declare the menu item a menu group
	sMenu->AddMenuGroupAsSubMenu( kSDKMenuGroup, 0, throwAwayAIMenu, &throwAwayMenuGroup );
	
	// Now we can add menu items to it.
	throwAwayMenuData.groupName = kSDKMenuGroup;
	*strBuffer = '\0';
	error = sADMBasic->GetIndexString(message->d.self, kMenuStringResID, 8, strBuffer, sizeof(strBuffer));
	if (error)
		goto error;
	throwAwayMenuData.itemText = SUctopstr ( strBuffer );	

	error = sMenu->AddMenuItem( message->d.self, "Auto Update 1", &throwAwayMenuData, 0,
								&throwAwayAIMenu );
	if ( error )
		goto error;		

	// enabled for paths and no masks in the selection
	error = sMenu->UpdateMenuItemAutomatically( throwAwayAIMenu, kAutoEnableMenuItemAction,
				kIfPath | kIfGuide, kIfMask,
				0, 0,
				0, 0 );	 // don't care about other update options
		
	if ( error )
		goto error;	

	sMenu->AddMenuGroupAsSubMenu( kMenuPlayMenuGroup, 0, throwAwayAIMenu, &throwAwayMenuGroup );

	throwAwayMenuData.groupName = kMenuPlayMenuGroup;
	*strBuffer = '\0';
	error = sADMBasic->GetIndexString(message->d.self, kMenuStringResID, 2, strBuffer, sizeof(strBuffer));
	if (error)
		goto error;
	throwAwayMenuData.itemText = SUctopstr ( strBuffer );	

	error = sMenu->AddMenuItem( message->d.self, "Menu Play", &throwAwayMenuData, 0,
								&throwAwayAIMenu );
	if ( error )
		goto error;		

	error = sMenu->UpdateMenuItemAutomatically( throwAwayAIMenu, kAutoEnableMenuItemAction,
				0, 0,	 // don't care about what's in artwork
				kIfGroup, // is selected and
				kIfTextPath,	 // are not selected
				0, 0 );	 // don't care about other update options
		
	if ( error )
		goto error;		
	


	// The second item just auto dims if the layer is locked or has locked objects.
	throwAwayMenuData.groupName = kMenuPlayMenuGroup;	
	*strBuffer = '\0';
	error = sADMBasic->GetIndexString(message->d.self, kMenuStringResID, 3, strBuffer, sizeof(strBuffer));
	if (error)
		goto error;
	throwAwayMenuData.itemText = SUctopstr ( strBuffer );	
	error = sMenu->AddMenuItem( message->d.self, "Auto Update 2", &throwAwayMenuData, 0,
								&throwAwayAIMenu );
	if ( error )
		goto error;		
	error = sMenu->UpdateMenuItemAutomatically( throwAwayAIMenu, kAutoEnableMenuItemAction,
				0, 0,	 // don't care about what's in artwork
				0, // is selected and
				0,	 // are not selected
				kIfCurrentLayerIsEditable, // is true
				kIfAnyLockedObjects );	 // is false
						
	if ( error )
		goto error;		

	// The third item doesn't auto dim, but requests the update selector.
	// The automatic update option is the best way to handle menu updates.
	throwAwayMenuData.groupName = kMenuPlayMenuGroup;
	*strBuffer = '\0';
	error = sADMBasic->GetIndexString(message->d.self, kMenuStringResID, 4, strBuffer, sizeof(strBuffer));
	if (error)
		goto error;
	throwAwayMenuData.itemText = SUctopstr ( strBuffer );

	error = sMenu->AddMenuItem( message->d.self, "Manual Update 1", &throwAwayMenuData, 
								kMenuItemWantsUpdateOption, &g->manualUpdateAIMenu );
	if ( error )
		goto error;		


	// Seperators work just like std. mac menus
	throwAwayMenuData.groupName = kMenuPlayMenuGroup;	
	*strBuffer = '\0';
	error = sADMBasic->GetIndexString(message->d.self, kMenuStringResID, 5, strBuffer, sizeof(strBuffer));
	if (error)
		goto error;
	throwAwayMenuData.itemText = SUctopstr ( strBuffer );
	error = sMenu->AddMenuItem( message->d.self, "seperator", &throwAwayMenuData, 
								kMenuItemWantsUpdateOption, &throwAwayAIMenu );
	if ( error )
		goto error;		



	// These menus we'll actually make do something, in this case check and uncheck itself
	throwAwayMenuData.groupName = kMenuPlayMenuGroup;	
	*strBuffer = '\0';
	error = sADMBasic->GetIndexString(message->d.self, kMenuStringResID, 6, strBuffer, sizeof(strBuffer));
	if (error)
		goto error;
	throwAwayMenuData.itemText = SUctopstr ( strBuffer );

	// We keep the AIMenuItemHandle to figure out which menu was selected later
	error = sMenu->AddMenuItem( message->d.self, "Check me", &throwAwayMenuData, 
								0, &g->checkMeAIMenu );
	if ( error )
		goto error;		

	//sMenu->SetItemCmd( g->checkMeAIMenu, 'u', kMenuItemCmdShiftModifier );
	g->checkMeChecked = false;


	// This menu will dim the above menu and change it's own icon
	throwAwayMenuData.groupName = kMenuPlayMenuGroup;	
	*strBuffer = '\0';
	error = sADMBasic->GetIndexString(message->d.self, kMenuStringResID, 7, strBuffer, sizeof(strBuffer));
	if (error)
		goto error;
	throwAwayMenuData.itemText = SUctopstr ( strBuffer );
	error = sMenu->AddMenuItem( message->d.self, "Disable Check Me", &throwAwayMenuData, 
								0, &g->multiDemoAIMenu );
	if ( error )
		goto error;		
	
	sMenu->SetItemIcon( g->multiDemoAIMenu, 2 );

	g->checkMeEnabled = true;




error:
	return error;





}
extern AIErr addMenu( SPInterfaceMessage *message ) {
	AIErr error = kNoErr;

	// Add a menu item to the About SDK Plug-ins menu group.
	SDKAboutPluginsHelper aboutPluginsHelper;
	aboutPluginsHelper.AddAboutPluginsMenuItem(message, 
				kSDKDefAboutSDKCompanyPluginsGroupName, 
				ai::UnicodeString(kSDKDefAboutSDKCompanyPluginsGroupNameString), 
				"Add Color...", 
				&g->aboutPluginMenu);

	// Add other menus.
	AIPlatformAddMenuItemDataUS menuData;
	AIPlatformAddMenuItemDataUS pluginMenuData;
	const char *menuGroupCStr = "SDKEditGroup";
	const char *menuCStr = "Modify Swatches";
	const char *pluginCStr = "Add Color";
	AIMenuGroup	menuGroup;
	AIMenuGroup	pluginMenuGroup;
	AIMenuGroup dummyGroup;
	AIMenuItemHandle dummyItem;
	bool sdkGroupAlreadyMade = false;
	bool admGroupAlreadyMade = false;

//This line tells AI to put the new item in the Edit menu
	menuData.groupName = kEditMenuGroup;
	menuData.itemText = ai::UnicodeString(menuCStr);

	pluginMenuData.groupName = menuGroupCStr;
	pluginMenuData.itemText = ai::UnicodeString(pluginCStr);
	
	// search through the menus and 
	// see if another SDK plug in has already set up the group
	long count;
	error = sAIMenu->CountMenuGroups( &count );
	if ( error ) goto error;
	while (count > 0)
	{
		error = sAIMenu->GetNthMenuGroup( count-1, &dummyGroup );
		if ( error ) goto error;
		char *name;
		error = sAIMenu->GetMenuGroupName( dummyGroup, (const char**)&name );
		if ( error ) goto error;
		if ( std::strcmp(name, menuGroupCStr ) == 0 )
		{
			sdkGroupAlreadyMade = true;
			count = -1;
		}
		if(std::strcmp(name,pluginCStr) == 0)
		{
			admGroupAlreadyMade = true;
		}
		count--;
	}

	if ( !sdkGroupAlreadyMade )
	{
		error = sAIMenu->AddMenuItem( message->d.self, menuGroupCStr, &menuData, 0, &dummyItem );
		if ( error ) goto error;

		error = sAIMenu->AddMenuGroupAsSubMenu( menuGroupCStr, kMenuGroupSortedAlphabeticallyOption, dummyItem, &menuGroup );
		if ( error ) goto error;
	}
	
	if(!admGroupAlreadyMade)
	{
		error = sAIMenu->AddMenuItem( message->d.self, pluginCStr, &pluginMenuData, 0, &dummyItem );
		if ( error ) goto error;

		error = sAIMenu->AddMenuGroupAsSubMenu( pluginCStr, 0, dummyItem, &pluginMenuGroup );
		if ( error ) goto error;
	}
	pluginMenuData.groupName = pluginCStr;
	error = sAIMenu->AddMenuItem( message->d.self, pluginCStr, &pluginMenuData, kMenuItemWantsUpdateOption, &g->showADMNonModalDialog );
	if ( error ) goto error;

error:
	return error;
}