Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Commands"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private Commands(AsyncPackage package, OleMenuCommandService commandService)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            _package       = package as P4EditVS ?? throw new ArgumentNullException(nameof(package));
            commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
            _application   = ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2 ?? throw new ArgumentNullException(nameof(_application));

            foreach (var cmdId in CommandIds)
            {
                var menuCommandID = new CommandID(CommandSet, cmdId);
                var menuItem      = new OleMenuCommand(this.Execute, menuCommandID);
                menuItem.BeforeQueryStatus += new EventHandler(OnBeforeQueryStatus);
                menuItem.Visible            = true;
                commandService.AddCommand(menuItem);
            }

            foreach (var cmdId in CtxtCommandIds)
            {
                var menuCommandID = new CommandID(CommandSet, cmdId);
                var menuItem      = new OleMenuCommand(this.Execute, menuCommandID);
                menuItem.BeforeQueryStatus += new EventHandler(OnBeforeQueryStatusCtxt);
                menuItem.Visible            = true;
                commandService.AddCommand(menuItem);
            }

            foreach (var cmdId in WorkspaceCommandIds)
            {
                var menuCommandID = new CommandID(CommandSet, cmdId);
                var menuItem      = new OleMenuCommand(this.ExecuteWorkspace, menuCommandID);
                menuItem.BeforeQueryStatus += new EventHandler(OnBeforeQueryStatusWorkspace);
                menuItem.Visible            = true;
                commandService.AddCommand(menuItem);
            }

            if (_package.AutoCheckoutOnEdit)
            {
                _textDocEvents = ((EnvDTE80.Events2)_application.Events).get_TextDocumentKeyPressEvents(null);
                _textDocEvents.BeforeKeyPress += new _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler(OnBeforeKeyPress);
            }
            //_textEditorEvents = ((EnvDTE80.Events2)_application.Events).get_TextEditorEvents(null);
            //_textEditorEvents.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(OnLineChanged);

            // Subscribe to events so we can do auto-checkout
            //_updateSolutionEvents = new UpdateSolutionEvents(this);
            _runningDocTableEvents = new RunningDocTableEvents(this, _application as DTE);

            // Setup output log
            var outputWindowPaneStream = new OutputWindowStream(_application, "P4EditVS");

            _outputWindow           = new StreamWriter(outputWindowPaneStream);
            _outputWindow.AutoFlush = true;
            //_outputWindow.WriteLine("hello from P4EditVS\n");
        }
Beispiel #2
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void ExecuteWorkspace(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            P4EditVS package   = _package as P4EditVS;
            var      myCommand = sender as OleMenuCommand;

            if (null != myCommand)
            {
                int workspaceId = GetWorkspaceIndexForCommandId(myCommand.CommandID.ID);
                package.SelectedWorkspace = workspaceId;
                myCommand.Checked         = true;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Called before menu button is shown so we can update text and active state
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeQueryStatusWorkspace(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            P4EditVS package   = _package as P4EditVS;
            var      myCommand = sender as OleMenuCommand;

            if (null != myCommand)
            {
                int workspaceIndex = GetWorkspaceIndexForCommandId(myCommand.CommandID.ID);
                myCommand.Checked = (package.SelectedWorkspace == workspaceIndex);
                string text = package.GetWorkspaceName(workspaceIndex);
                myCommand.Enabled = (text != "");
                myCommand.Visible = myCommand.Enabled;
                myCommand.Text    = text;
            }
        }