Esempio n. 1
0
        private ContextMenuDiffToolInfo GetContextMenuDiffToolInfo()
        {
            IList <GitRevision> selectedRevisions = _revisionGrid.GetSelectedRevisions();

            //Should be blocked in the GUI but not an error to show to the user
            Debug.Assert(selectedRevisions.Count == 1 || selectedRevisions.Count == 2,
                         "Unexpectedly number of revisions for difftool" + selectedRevisions.Count);
            if (selectedRevisions.Count < 1)
            {
                return(null);
            }

            bool aIsLocal        = false;
            bool bIsLocal        = false;
            bool showParentItems = selectedRevisions.Count == 2;

            bool localExists = false;
            bool bIsNormal   = false; //B is not new or deleted (we cannot easily check A)

            bIsLocal = selectedRevisions[0].Guid == GitRevision.UnstagedGuid;

            if (selectedRevisions.Count == 2)
            {
                aIsLocal = selectedRevisions[0].Guid == GitRevision.UnstagedGuid;
            }
            //Temporary, until parent is set to HEAD instead of staged
            else
            {
                aIsLocal = bIsLocal;
                bIsLocal = bIsLocal || selectedRevisions[0].Guid == GitRevision.IndexGuid;
            }

            //enable *<->Local items only when local file exists
            //no simple way to check if A (or A/B parents) is normal, ignore that some menus should be disabled
            foreach (var item in DiffFiles.SelectedItems)
            {
                bIsNormal = bIsNormal || !(item.IsNew || item.IsDeleted);
                string filePath = FormBrowseUtil.GetFullPathFromGitItemStatus(Module, item);
                if (File.Exists(filePath) || Directory.Exists(filePath))
                {
                    localExists = true;
                    if (localExists && bIsNormal)
                    {
                        break;
                    }
                }
            }

            var selectionInfo = new ContextMenuDiffToolInfo(aIsLocal, bIsLocal, bIsNormal, localExists, showParentItems);

            return(selectionInfo);
        }
Esempio n. 2
0
        private void openWithDifftoolToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
        {
            bool artificialRevSelected = false;
            bool enableDiffDropDown    = true;
            bool showParentItems       = false;

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

            if (revisions.Count > 0)
            {
                artificialRevSelected = revisions[0].IsArtificial();

                if (revisions.Count == 2)
                {
                    artificialRevSelected = artificialRevSelected || revisions[revisions.Count - 1].IsArtificial();
                    showParentItems       = true;
                }
                else
                {
                    enableDiffDropDown = revisions.Count == 1;
                }
            }

            aBToolStripMenuItem.Enabled             = enableDiffDropDown;
            bLocalToolStripMenuItem.Enabled         = enableDiffDropDown;
            aLocalToolStripMenuItem.Enabled         = enableDiffDropDown;
            parentOfALocalToolStripMenuItem.Enabled = enableDiffDropDown;
            parentOfBLocalToolStripMenuItem.Enabled = enableDiffDropDown;

            parentOfALocalToolStripMenuItem.Visible = showParentItems;
            parentOfBLocalToolStripMenuItem.Visible = showParentItems;

            if (!enableDiffDropDown)
            {
                return;
            }
            //enable *<->Local items only when local file exists
            foreach (var item in DiffFiles.SelectedItems)
            {
                string filePath = FormBrowseUtil.GetFullPathFromGitItemStatus(Module, item);
                if (File.Exists(filePath))
                {
                    bLocalToolStripMenuItem.Enabled         = !artificialRevSelected;
                    aLocalToolStripMenuItem.Enabled         = !artificialRevSelected;
                    parentOfALocalToolStripMenuItem.Enabled = !artificialRevSelected;
                    parentOfBLocalToolStripMenuItem.Enabled = !artificialRevSelected;
                    return;
                }
            }
        }
Esempio n. 3
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.ShouldShowMenuResetFile(selectionInfo);

            diffEditFileToolStripMenuItem.Visible       =
                diffDeleteFileToolStripMenuItem.Visible = _revisionDiffController.ShouldShowMenuEditFile(selectionInfo);

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

            diffToolStripSeparator13.Visible = _revisionDiffController.ShouldShowMenuEditFile(selectionInfo) || _revisionDiffController.ShouldShowSubmoduleMenus(selectionInfo);

            // 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;
                    }
                }
            }
        }
Esempio n. 4
0
        private ContextMenuSelectionInfo GetSelectionInfo()
        {
            IList <GitRevision> selectedRevisions = _revisionGrid.GetSelectedRevisions();

            bool isAnyCombinedDiff        = DiffFiles.SelectedItemParents.Any(item => item == DiffFiles.CombinedDiff.Text);
            bool isExactlyOneItemSelected = DiffFiles.SelectedItems.Count() == 1;
            bool isAnyItemSelected        = DiffFiles.SelectedItems.Count() > 0;
            var  isCombinedDiff           = isExactlyOneItemSelected && DiffFiles.CombinedDiff.Text == DiffFiles.SelectedItemParent;
            var  selectedItemStatus       = DiffFiles.SelectedItem;
            bool isBareRepository         = Module.IsBareRepository();
            bool singleFileExists         = isExactlyOneItemSelected && File.Exists(FormBrowseUtil.GetFullPathFromGitItemStatus(Module, DiffFiles.SelectedItem));

            var selectionInfo = new ContextMenuSelectionInfo(selectedRevisions, selectedItemStatus, isAnyCombinedDiff, isExactlyOneItemSelected, isCombinedDiff, isAnyItemSelected, isBareRepository, singleFileExists);

            return(selectionInfo);
        }
Esempio n. 5
0
        private ContextMenuDiffToolInfo GetContextMenuDiffToolInfo()
        {
            IList <GitRevision> selectedRevisions = _revisionGrid.GetSelectedRevisions();

            //Should be blocked in the GUI but not an error to show to the user
            Debug.Assert(selectedRevisions.Count == 1 || selectedRevisions.Count == 2,
                         "Unexpectedly number of revisions for difftool" + selectedRevisions.Count);
            if (selectedRevisions.Count < 1 || selectedRevisions.Count > 2)
            {
                return(null);
            }

            bool aIsLocal = selectedRevisions.Count == 2 && selectedRevisions[1].Guid == GitRevision.UnstagedGuid;
            bool bIsLocal = selectedRevisions[0].Guid == GitRevision.UnstagedGuid;
            bool multipleRevisionsSelected = selectedRevisions.Count == 2;

            bool localExists = false;
            bool bIsNormal   = false; //B is assumed to be new or deleted (check from DiffFiles)

            //enable *<->Local items only when (any) local file exists
            foreach (var item in DiffFiles.SelectedItems)
            {
                bIsNormal = bIsNormal || !(item.IsNew || item.IsDeleted);
                string filePath = FormBrowseUtil.GetFullPathFromGitItemStatus(Module, item);
                if (File.Exists(filePath) || Directory.Exists(filePath))
                {
                    localExists = true;
                    if (localExists && bIsNormal)
                    {
                        break;
                    }
                }
            }

            var selectionInfo = new ContextMenuDiffToolInfo(aIsLocal, bIsLocal, bIsNormal, localExists, multipleRevisionsSelected);

            return(selectionInfo);
        }
Esempio n. 6
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;
                    }
                }
            }
        }