Пример #1
0
        public static void WrapBeforeQueryStatus(OleMenuCommand command, IPackageCommandHandler handler)
        {
            command.Supported = handler.Supported;
            if (!command.Supported)
            {
                // Ensures OleMenuCommandService returns OLECMDERR_E_NOTSUPPORTED.
                command.Enabled = false;
                command.Checked = false;
                command.Visible = true;
            }
            else
            {
                command.Checked = handler.Checked;
                command.Enabled = handler.Enabled;
                command.Visible = handler.Visible;
            }

            if (LogCommand(command.CommandID))
            {
                Logger.LogInfo(
                    "BeforeQueryStatus: cmd={0}, handler={1}: Supported={2}, Checked={3}, Enabled={4}, Visible={5}",
                    command,
                    handler,
                    command.Supported,
                    command.Checked,
                    command.Enabled,
                    command.Visible);
            }
        }
Пример #2
0
        /// <summary>
        /// Convert an instance of <see cref="IPackageCommandHandler"/> to an <see
        /// cref="OleMenuCommand"/>. Note: When using the <see
        /// cref="OleMenuCommand"/> with an implementation of <see
        /// cref="OleMenuCommandService"/>, make sure to override <see
        /// cref="Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget "/> and forward calls to <see
        /// cref="OleCommandTargetSpy"/>.
        /// </summary>
        public static OleMenuCommand ToOleMenuCommand(this IPackageCommandHandler handler)
        {
            var command = new OleMenuCommand(handler.Execute, handler.CommandId);

            command.BeforeQueryStatus += (sender, args) =>
                                         OleCommandTargetSpy.WrapBeforeQueryStatus(command, handler);
            return(command);
        }
Пример #3
0
    public static void WrapBeforeQueryStatus(OleMenuCommand command, IPackageCommandHandler handler) {
      command.Supported = handler.Supported;
      if (!command.Supported) {
        // Ensures OleMenuCommandService returns OLECMDERR_E_NOTSUPPORTED.
        command.Enabled = false;
        command.Checked = false;
        command.Visible = true;
      } else {
        command.Checked = handler.Checked;
        command.Enabled = handler.Enabled;
        command.Visible = handler.Visible;
      }

      if (LogCommand(command.CommandID)) {
        Logger.LogInfo(
          "BeforeQueryStatus: cmd={0}, handler={1}: Supported={2}, Checked={3}, Enabled={4}, Visible={5}",
          command,
          handler,
          command.Supported,
          command.Checked,
          command.Enabled,
          command.Visible);
      }
    }