示例#1
0
        /// <inheritdoc/>
        int IOleCommandTarget.QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
        {
            using (OleCommandText oleCommandText = OleCommandText.FromQueryStatus(pCmdText))
            {
                Guid cmdGroup = guidCmdGroup;
                for (uint i = 0; i < cCmds; i++)
                {
                    OLECMDF status = QueryCommandStatus(ref cmdGroup, prgCmds[i].cmdID, oleCommandText);
                    if (status == default(OLECMDF) && _next != null)
                    {
                        int hr = _next.QueryStatus(ref cmdGroup, cCmds, prgCmds, pCmdText);
                        if (ErrorHandler.Failed(hr))
                        {
                            return(hr);
                        }
                    }
                    else
                    {
                        prgCmds[i].cmdf = (uint)status;
                    }
                }

                return(VSConstants.S_OK);
            }
        }
        protected override OLECMDF QueryCommandStatus(ref Guid commandGroup, uint commandId, OleCommandText oleCommandText)
        {
            if (commandGroup == typeof(GitDiffMarginCommand).GUID)
            {
                switch ((GitDiffMarginCommand)commandId)
                {
                case GitDiffMarginCommand.ShowPopup:
                {
                    EditorDiffMarginViewModel viewModel;
                    if (!TryGetMarginViewModel(out viewModel))
                    {
                        return(0);
                    }

                    var diffViewModel = GetCurrentDiffViewModel(viewModel);

                    if (diffViewModel != null)
                    {
                        return(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);
                    }
                    else
                    {
                        return(OLECMDF.OLECMDF_SUPPORTED);
                    }
                }

                case GitDiffMarginCommand.PreviousChange:
                case GitDiffMarginCommand.NextChange:
                {
                    EditorDiffMarginViewModel viewModel;
                    if (!TryGetMarginViewModel(out viewModel))
                    {
                        return(0);
                    }

                    // First look for a diff already showing a popup
                    EditorDiffViewModel diffViewModel = viewModel.DiffViewModels.OfType <EditorDiffViewModel>().FirstOrDefault(i => i.ShowPopup);
                    if (diffViewModel != null)
                    {
                        RelayCommand <DiffViewModel> command = (GitDiffMarginCommand)commandId == GitDiffMarginCommand.NextChange ? viewModel.NextChangeCommand : viewModel.PreviousChangeCommand;
                        if (command.CanExecute(diffViewModel))
                        {
                            return(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);
                        }
                        else
                        {
                            return(OLECMDF.OLECMDF_SUPPORTED);
                        }
                    }

                    diffViewModel = GetDiffViewModelToMoveTo(commandId, viewModel);

                    if (diffViewModel != null)
                    {
                        return(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);
                    }
                    else
                    {
                        return(OLECMDF.OLECMDF_SUPPORTED);
                    }
                }

                case GitDiffMarginCommand.RollbackChange:
                case GitDiffMarginCommand.CopyOldText:
                {
                    EditorDiffMarginViewModel viewModel;
                    if (!TryGetMarginViewModel(out viewModel))
                    {
                        return(0);
                    }

                    EditorDiffViewModel diffViewModel = viewModel.DiffViewModels.OfType <EditorDiffViewModel>().FirstOrDefault(i => i.ShowPopup);
                    if (diffViewModel != null)
                    {
                        ICommand command = (GitDiffMarginCommand)commandId == GitDiffMarginCommand.RollbackChange ? diffViewModel.RollbackCommand : diffViewModel.CopyOldTextCommand;
                        if (command.CanExecute(diffViewModel))
                        {
                            return(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);
                        }
                    }

                    // This command only works when a popup is open
                    return(OLECMDF.OLECMDF_SUPPORTED);
                }

                case GitDiffMarginCommand.ShowDiff:
                {
                    EditorDiffMarginViewModel viewModel;
                    if (!TryGetMarginViewModel(out viewModel))
                    {
                        return(0);
                    }

                    if (viewModel.DiffViewModels.Any())
                    {
                        return(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);
                    }
                    else
                    {
                        return(OLECMDF.OLECMDF_SUPPORTED);
                    }
                }

                case GitDiffMarginCommand.GitDiffToolbar:
                case GitDiffMarginCommand.GitDiffToolbarGroup:
                    // these aren't actually commands, but IDs of the command bars and groups
                    break;

                default:
                    break;
                }
            }

            return(0);
        }
示例#3
0
 /// <summary>
 /// Gets the current status of a particular command.
 /// </summary>
 /// <remarks>
 /// The base implementation returns 0 for all commands, indicating the command is not supported by this command
 /// filter.
 /// </remarks>
 /// <param name="commandGroup">The command group.</param>
 /// <param name="commandId">The command ID.</param>
 /// <param name="oleCommandText">A wrapper around the <see cref="OLECMDTEXT"/> object passed to
 /// <see cref="IOleCommandTarget.QueryStatus"/>, or <see langword="null"/> if this parameter should be
 /// ignored.</param>
 /// <returns>A combination of values from the <see cref="OLECMDF"/> enumeration indicating the current status of
 /// a particular command, or 0 if the command is not recognized by the current command filter.</returns>
 protected virtual OLECMDF QueryCommandStatus(ref Guid commandGroup, uint commandId, OleCommandText oleCommandText)
 {
     return(default(OLECMDF));
 }