示例#1
0
        private Command RegisterCommandPrivate(string name, CommandBase commandHandler, bool toolbarOnly)
        {
            Command vscommand = null;

            try
            {
                vscommand = mPlugin.Commands.Item(Absname(name), -1);
                return(vscommand);
            }
            catch (System.ArgumentException)
            {
            }

            Log.Info("Registering the command {0} from scratch", name);
            object[] contextGuids = new object[] { };

            int commandStatus = (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled;

            if (0 == commandHandler.IconIndex)
            {
                vscommand = mPlugin.Commands.AddNamedCommand2(mPlugin.AddIn, name, name /*commandHandler.Name*/, commandHandler.Tooltip, true, -1, ref contextGuids, commandStatus, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);
            }
            else
            {
                int style = (int)vsCommandStyle.vsCommandStylePictAndText;
                if (toolbarOnly)
                {
                    style = (int)vsCommandStyle.vsCommandStylePict;
                }

                vscommand = mPlugin.Commands.AddNamedCommand2(mPlugin.AddIn, name, name /*commandHandler.Name*/, commandHandler.Tooltip, false, commandHandler.IconIndex, ref contextGuids, commandStatus, style, vsCommandControlType.vsCommandControlTypeButton);
            }

            // Register the graphics controls for this command as well.
            // First let the command itself have a stab at register whatever it needs.
            // Then by default we always register ourselves in the main toolbar of the application.
            if (!commandHandler.RegisterGUI(vscommand, mCommandBar, toolbarOnly))
            {
            }

            return(vscommand);
        }
		private Command RegisterCommandPrivate(string name, CommandBase commandHandler, bool toolbarOnly)
		{
			Command vscommand = null;

			try
			{
				vscommand = mPlugin.Commands.Item(Absname(name), -1);
				return vscommand;
			}
			catch(System.ArgumentException)
			{
			}

			Log.Info("Registering the command {0} from scratch", name);
			object[] contextGuids = new object[] { };

			int commandStatus = (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled;

			if(0 == commandHandler.IconIndex)
			{
				vscommand = mPlugin.Commands.AddNamedCommand2(mPlugin.AddIn, name, name/*commandHandler.Name*/, commandHandler.Tooltip, true, -1, ref contextGuids, commandStatus, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);
			}
			else
			{
				int style = (int)vsCommandStyle.vsCommandStylePictAndText;
				if(toolbarOnly)
				{
					style = (int)vsCommandStyle.vsCommandStylePict;
				}
			
				vscommand = mPlugin.Commands.AddNamedCommand2(mPlugin.AddIn, name, name/*commandHandler.Name*/, commandHandler.Tooltip, false, commandHandler.IconIndex, ref contextGuids, commandStatus, style, vsCommandControlType.vsCommandControlTypeButton);
			}

			// Register the graphics controls for this command as well.
			// First let the command itself have a stab at register whatever it needs.
			// Then by default we always register ourselves in the main toolbar of the application.
			if(!commandHandler.RegisterGUI(vscommand, mCommandBar, toolbarOnly))
			{
			}

			return vscommand;
		}
        private OleMenuCommand RegisterCommandPrivate(CommandBase commandHandler, bool toolbarOnly)
        {
            OleMenuCommand vscommand = null;
            uint           cmdId     = 0;

            try
            {
                Command existingCmd = mPlugin.Commands.Item(commandHandler.CanonicalName, -1);
                cmdId = (uint)existingCmd.ID;
            }
            catch (System.ArgumentException)
            {
            }

            if (cmdId == 0)
            {
                Log.Info("Registering the command {0} from scratch", commandHandler.Name);
                int result = mPlugin.ProfferCommands.AddNamedCommand(mPackageGuid, mCmdGroupGuid, commandHandler.CanonicalName, out cmdId, commandHandler.CanonicalName, commandHandler.CanonicalName, commandHandler.Tooltip, null, 0, (uint)commandHandler.IconIndex, 0, 0, null);
            }

            if (cmdId != 0)
            {
                OleMenuCommandService menuCommandService = mPlugin.MenuCommandService;
                CommandID             commandID          = new CommandID(mCmdGroupGuid, (int)cmdId);

                vscommand = new OleMenuCommand(OleMenuCommandCallback, commandID);
                vscommand.BeforeQueryStatus += this.OleMenuCommandBeforeQueryStatus;
                menuCommandService.AddCommand(vscommand);
                mCommandsById[cmdId] = commandHandler;
            }
            // Register the graphics controls for this command as well.
            // First let the command itself have a stab at register whatever it needs.
            // Then by default we always register ourselves in the main toolbar of the application.
            if (!commandHandler.RegisterGUI(vscommand, mCommandBar, toolbarOnly))
            {
            }

            return(vscommand);
        }
示例#4
0
        private OleMenuCommand RegisterCommandPrivate(CommandBase commandHandler, bool toolbarOnly)
        {
            OleMenuCommand vscommand = null;
            uint cmdId = 0;
            try
            {
                Command existingCmd = mPlugin.Commands.Item(commandHandler.CanonicalName, -1);
                cmdId = (uint)existingCmd.ID;
            }
            catch(System.ArgumentException)
            {
            }

            if (cmdId == 0)
            {
                Log.Info("Registering the command {0} from scratch", commandHandler.Name);
                int result = mPlugin.ProfferCommands.AddNamedCommand(mPackageGuid, mCmdGroupGuid, commandHandler.CanonicalName, out cmdId, commandHandler.CanonicalName, commandHandler.CanonicalName, commandHandler.Tooltip, null, 0, (uint)commandHandler.IconIndex, 0, 0, null);
            }

            if (cmdId != 0)
            {
                OleMenuCommandService menuCommandService = mPlugin.MenuCommandService;
                CommandID commandID = new CommandID(mCmdGroupGuid, (int)cmdId);

                vscommand = new OleMenuCommand(OleMenuCommandCallback, commandID);
                vscommand.BeforeQueryStatus += this.OleMenuCommandBeforeQueryStatus;
                menuCommandService.AddCommand(vscommand);
                mCommandsById[cmdId] = commandHandler;
            }
            // Register the graphics controls for this command as well.
            // First let the command itself have a stab at register whatever it needs.
            // Then by default we always register ourselves in the main toolbar of the application.
            if(!commandHandler.RegisterGUI(vscommand, mCommandBar, toolbarOnly))
            {
            }

            return vscommand;
        }