Ejemplo n.º 1
0
        private void DiffContextMenu_Opening(object sender, CancelEventArgs e)
        {
            var selectionInfo = GetSelectionInfo();

            // Many options have no meaning for artificial commits or submodules
            // Hide the obviously no action options when single selected, handle them in actions if multi select

            openWithDifftoolToolStripMenuItem.Enabled         = _revisionDiffController.ShouldShowDifftoolMenus(selectionInfo);
            saveAsToolStripMenuItem1.Visible                  = _revisionDiffController.ShouldShowMenuSaveAs(selectionInfo);
            copyFilenameToClipboardToolStripMenuItem1.Enabled = _revisionDiffController.ShouldShowMenuCopyFileName(selectionInfo);

            stageFileToolStripMenuItem.Visible   = _revisionDiffController.ShouldShowMenuStage(selectionInfo);
            unstageFileToolStripMenuItem.Visible = _revisionDiffController.ShouldShowMenuUnstage(selectionInfo);

            cherryPickSelectedDiffFileToolStripMenuItem.Visible = _revisionDiffController.ShouldShowMenuCherryPick(selectionInfo);

            // Visibility of FileTree is not known, assume (CommitInfoTabControl.Contains(TreeTabPage);)
            diffShowInFileTreeToolStripMenuItem.Visible = _revisionDiffController.ShouldShowMenuShowInFileTree(selectionInfo);
            fileHistoryDiffToolstripMenuItem.Enabled    = _revisionDiffController.ShouldShowMenuFileHistory(selectionInfo);
            blameToolStripMenuItem.Enabled       = _revisionDiffController.ShouldShowMenuBlame(selectionInfo);
            resetFileToToolStripMenuItem.Enabled = _revisionDiffController.ShouldShowResetFileMenus(selectionInfo);

            diffDeleteFileToolStripMenuItem.Visible = _revisionDiffController.ShouldShowMenuDeleteFile(selectionInfo);
            diffEditWorkingDirectoryFileToolStripMenuItem.Visible     = _revisionDiffController.ShouldShowMenuEditWorkingDirectoryFile(selectionInfo);
            diffOpenWorkingDirectoryFileWithToolStripMenuItem.Visible = _revisionDiffController.ShouldShowMenuEditWorkingDirectoryFile(selectionInfo);
            diffOpenRevisionFileToolStripMenuItem.Visible             = _revisionDiffController.ShouldShowMenuOpenRevision(selectionInfo);
            diffOpenRevisionFileWithToolStripMenuItem.Visible         = _revisionDiffController.ShouldShowMenuOpenRevision(selectionInfo);

            diffCommitSubmoduleChanges.Visible    =
                diffResetSubmoduleChanges.Visible =
                    diffStashSubmoduleChangesToolStripMenuItem.Visible =
                        diffSubmoduleSummaryMenuItem.Visible           =
                            diffUpdateSubmoduleMenuItem.Visible        = _revisionDiffController.ShouldShowSubmoduleMenus(selectionInfo);

            diffToolStripSeparator13.Visible = _revisionDiffController.ShouldShowMenuDeleteFile(selectionInfo) ||
                                               _revisionDiffController.ShouldShowSubmoduleMenus(selectionInfo) ||
                                               _revisionDiffController.ShouldShowMenuEditWorkingDirectoryFile(selectionInfo) ||
                                               _revisionDiffController.ShouldShowMenuOpenRevision(selectionInfo);

            // openContainingFolderToolStripMenuItem.Enabled or not
            {
                openContainingFolderToolStripMenuItem.Enabled = false;

                foreach (var item in DiffFiles.SelectedItems)
                {
                    string filePath = _fullPathResolver.Resolve(item.Name);
                    if (FormBrowseUtil.FileOrParentDirectoryExists(filePath))
                    {
                        openContainingFolderToolStripMenuItem.Enabled = true;
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void DiffContextMenu_Opening(object sender, CancelEventArgs e)
        {
            bool artificialRevSelected;

            IList <GitRevision> selectedRevisions = _revisionGrid.GetSelectedRevisions();

            if (selectedRevisions.Count == 0)
            {
                artificialRevSelected = false;
            }
            else
            {
                artificialRevSelected = selectedRevisions[0].IsArtificial();
            }
            if (selectedRevisions.Count > 1)
            {
                artificialRevSelected = artificialRevSelected || selectedRevisions[selectedRevisions.Count - 1].IsArtificial();
            }

            //Many options have no meaning for artificial commits or submodules
            //Hide the obviously no action options when single selected, handle them in actions if multi select

            // disable items that need exactly one selected item
            bool isExactlyOneItemSelected = DiffFiles.SelectedItems.Count() == 1;
            var  isCombinedDiff           = isExactlyOneItemSelected &&
                                            DiffFiles.CombinedDiff.Text == DiffFiles.SelectedItemParent;
            var isAnyCombinedDiff = DiffFiles.SelectedItemParents.Any(item => item == DiffFiles.CombinedDiff.Text);

            openWithDifftoolToolStripMenuItem.Enabled           = !isAnyCombinedDiff;
            saveAsToolStripMenuItem1.Visible                    = !isCombinedDiff && isExactlyOneItemSelected && !DiffFiles.SelectedItem.IsSubmodule;
            cherryPickSelectedDiffFileToolStripMenuItem.Visible = !isCombinedDiff && isExactlyOneItemSelected &&
                                                                  !(DiffFiles.SelectedItem.IsSubmodule || selectedRevisions[0].Guid == GitRevision.UnstagedGuid ||
                                                                    (DiffFiles.SelectedItem.IsNew || DiffFiles.SelectedItem.IsDeleted) && selectedRevisions[0].Guid == GitRevision.IndexGuid);
            //Visibility of FileTree is not known, assume (CommitInfoTabControl.Contains(TreeTabPage);)
            diffShowInFileTreeToolStripMenuItem.Visible = isExactlyOneItemSelected && !selectedRevisions[0].IsArtificial();
            fileHistoryDiffToolstripMenuItem.Enabled    = isExactlyOneItemSelected && !(DiffFiles.SelectedItem.IsNew && selectedRevisions[0].IsArtificial());
            blameToolStripMenuItem.Enabled       = isExactlyOneItemSelected && !(DiffFiles.SelectedItem.IsSubmodule || selectedRevisions[0].IsArtificial());
            resetFileToToolStripMenuItem.Enabled = !isCombinedDiff &&
                                                   !(isExactlyOneItemSelected &&
                                                     (DiffFiles.SelectedItem.IsSubmodule || DiffFiles.SelectedItem.IsNew) && selectedRevisions[0].Guid == GitRevision.UnstagedGuid);

            this.diffEditFileToolStripMenuItem.Visible       =
                this.diffDeleteFileToolStripMenuItem.Visible =
                    isExactlyOneItemSelected && !DiffFiles.SelectedItem.IsSubmodule && selectedRevisions[0].IsArtificial();

            this.diffCommitSubmoduleChanges.Visible    =
                this.diffResetSubmoduleChanges.Visible =
                    this.diffStashSubmoduleChangesToolStripMenuItem.Visible =
                        this.diffUpdateSubmoduleMenuItem.Visible            =
                            this.diffSubmoduleSummaryMenuItem.Visible       =
                                isExactlyOneItemSelected && DiffFiles.SelectedItem.IsSubmodule && selectedRevisions[0].Guid == GitRevision.UnstagedGuid;
            this.diffUpdateSubmoduleMenuItem.Visible = false; //TBD

            this.diffToolStripSeparator13.Visible = isExactlyOneItemSelected &&
                                                    (!DiffFiles.SelectedItem.IsSubmodule && selectedRevisions[0].IsArtificial() ||
                                                     DiffFiles.SelectedItem.IsSubmodule && selectedRevisions[0].Guid == GitRevision.UnstagedGuid);

            // openContainingFolderToolStripMenuItem.Enabled or not
            {
                openContainingFolderToolStripMenuItem.Enabled = false;

                foreach (var item in DiffFiles.SelectedItems)
                {
                    string filePath = FormBrowseUtil.GetFullPathFromGitItemStatus(Module, item);
                    if (FormBrowseUtil.FileOrParentDirectoryExists(filePath))
                    {
                        openContainingFolderToolStripMenuItem.Enabled = true;
                        break;
                    }
                }
            }
        }