예제 #1
0
파일: VsAddin.cs 프로젝트: radtek/csql
        /// <summary>
        /// Removes a command added to the visual studio ide.
        /// </summary>
        private void RemoveIdeCommand(VsCommand vsCommand)
        {
            Command ideCommand = FindIdeCommand(vsCommand);

            if (ideCommand != null)
            {
                ideCommand.Delete();
            }
        }
예제 #2
0
파일: VsAddin.cs 프로젝트: radtek/csql
 void IDTCommandTarget.Exec(string CmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled)
 {
     Handled = false;
     if (ExecuteOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
     {
         if (this.vsCommands.ContainsKey(CmdName))
         {
             VsCommand vsCommand = this.vsCommands[CmdName];
             vsCommand.Execute(new VsCommandEventArgs(this.application, this.addin));
             Handled = true;
         }
     }
 }
예제 #3
0
파일: VsAddin.cs 프로젝트: radtek/csql
        /// <summary>
        /// Seeks for an existing Visual Studio IDE command with the name name as the specified command.
        /// </summary>
        /// <param name="vsCommand">The command that is seeked.</param>
        /// <returns>
        /// The existing IDE command or <c>null</c> if the command is not yet added to
        /// the Visual Studio IDE.
        /// </returns>
        private Command FindIdeCommand(VsCommand vsCommand)
        {
            Commands2 ideCommands = (Commands2)this.Application.Commands;
            string    commandName = GetFullCommandName(vsCommand.Name);

            foreach (object item in ideCommands)
            {
                Command ideCommand = item as Command;
                if (ideCommand == null)
                {
                    continue;
                }

                if (ideCommand.Name.Equals(commandName))
                {
                    return(ideCommand);
                }
            }
            return(null);
        }
예제 #4
0
파일: VsAddin.cs 프로젝트: radtek/csql
        void IDTCommandTarget.QueryStatus(string CmdName, vsCommandStatusTextWanted neededText, ref vsCommandStatus statusOption, ref object commandText)
        {
            Debug.WriteLine("QueryStatus(" + CmdName + ")");

            if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
            {
                if (this.vsCommands.ContainsKey(CmdName))
                {
                    VsCommand vsCommand = this.vsCommands[CmdName];
                    if (vsCommand.CanExecute(new VsCommandEventArgs(this.application, this.addin)))
                    {
                        statusOption = vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    }
                    else
                    {
                        statusOption = vsCommandStatus.vsCommandStatusSupported;
                    }
                }
            }
        }
예제 #5
0
파일: VsAddin.cs 프로젝트: radtek/csql
        /// <summary>
        /// Registers a command for later integration (during <see cref="M:OnConnection"/>)
        /// </summary>
        /// <param name="command">The command to register.</param>
        protected void RegisterCommand(VsCommand command)
        {
            string fullCommandName = GetFullCommandName(command.Name);

            if (this.vsCommands.ContainsKey(fullCommandName))
            {
                throw new ArgumentException("The command " + fullCommandName + " is already registered", "command");
            }

            this.vsCommands.Add(fullCommandName, command);
            if (command.Position == 0)
            {
                int maxPosition = 0;
                foreach (var c in this.vsCommands.Values)
                {
                    if (c.Position > maxPosition)
                    {
                        maxPosition = c.Position;
                    }
                }
                command.Position = maxPosition + 1;
            }
        }
예제 #6
0
파일: VsAddin.cs 프로젝트: radtek/csql
        /// <summary>
        /// Add a command to the Visual Studio shell.
        /// </summary>
        /// <param name="vsCommand">The add in command properties</param>
        private void AddIdeCommand(VsCommand vsCommand)
        {
            Debug.WriteLine("AddIdeCommand(" + vsCommand.Name + ")");

            Command ideCommand = FindIdeCommand(vsCommand);

            if (ideCommand == null)
            {
                Commands2 ideCommands   = (Commands2)this.Application.Commands;
                bool      useMsoButtons = vsCommand.IconId == 0;
                object[]  contextGuids  = vsCommand.VsContextGuidsObjectArray;
                ideCommand = ideCommands.AddNamedCommand2(
                    this.Addin,
                    vsCommand.Name,
                    vsCommand.Title,
                    String.Empty,
                    useMsoButtons,
                    vsCommand.IconId,
                    ref contextGuids,
                    (int)vsCommandStatus.vsCommandStatusSupported | (int)vsCommandStatus.vsCommandStatusEnabled,
                    (int)vsCommandStyle.vsCommandStylePictAndText,
                    vsCommandControlType.vsCommandControlTypeButton);
            }

            string commandBarName = vsCommand.CommandBarName;

            string[]   temp       = commandBarName.Split('.');
            CommandBar commandBar = GetCommandBar(temp[0]);

            if (commandBar == null)
            {
                return;
            }

            object commandControl = null;

            if (temp.Length == 1)
            {
                if (!ContainsCommand(commandBar.Controls, ideCommand))
                {
                    commandControl = ideCommand.AddControl(commandBar, vsCommand.Position);
                }
            }
            else if (temp.Length == 2)
            {
                CommandBarPopup commandBarPopup = (CommandBarPopup)commandBar.Controls[temp[1]];
                if (!ContainsCommand(commandBarPopup.Controls, ideCommand))
                {
                    commandControl = ideCommand.AddControl(commandBarPopup.CommandBar, vsCommand.Position);
                }
            }
            else
            {
                throw new NotSupportedException("A command hierarchy greater than two is not supported yet");
            }

            if (commandControl != null)
            {
                CommandBarButton commandButton = (CommandBarButton)commandControl;
                bool             useMsoButtons = vsCommand.IconId == 0;
                if (useMsoButtons && vsCommand.Icon != null)
                {
                    StdPicture iconPicture = vsCommand.Icon.IconPicture;
                    commandButton.Picture = iconPicture;
                    StdPicture iconMask = vsCommand.Icon.IconMask;
                    commandButton.Mask  = iconMask;
                    commandButton.Style = MsoButtonStyle.msoButtonIconAndCaption;
                }
                else
                {
                    commandButton.Style = MsoButtonStyle.msoButtonAutomatic;
                }
            }
        }