Ejemplo n.º 1
0
        private ContextMenuSelectionInfo GetSelectionInfo()
        {
            var selectedItems = DiffFiles.SelectedItems.ToList();

            // Some items are not supported if more than one revision is selected
            var revisions   = selectedItems.SecondRevs().ToList();
            var selectedRev = revisions.Count() != 1 ? null : revisions.FirstOrDefault();

            // First (A) is parent if one revision selected or if parent, then selected
            var parentIds = selectedItems.FirstIds().ToList();

            // Combined diff, range diff etc are for display only, no manipulations
            bool isStatusOnly         = selectedItems.Any(item => item.Item.IsRangeDiff || item.Item.IsStatusOnly);
            bool isDisplayOnlyDiff    = parentIds.Contains(ObjectId.CombinedDiffId) || isStatusOnly;
            int  selectedGitItemCount = selectedItems.Count();

            // No changes to files in bare repos
            bool isBareRepository = Module.IsBareRepository();
            bool isAnyTracked     = selectedItems.Any(item => item.Item.IsTracked);
            bool isAnyIndex       = selectedItems.Any(item => item.Item.Staged == StagedStatus.Index);
            bool isAnyWorkTree    = selectedItems.Any(item => item.Item.Staged == StagedStatus.WorkTree);
            bool supportPatches   = selectedGitItemCount == 1 && DiffText.HasAnyPatches();
            bool isDeleted        = selectedItems.Any(item => item.Item.IsDeleted);
            bool isAnySubmodule   = selectedItems.Any(item => item.Item.IsSubmodule);

            (bool allFilesExist, bool allDirectoriesExist, bool allFilesOrUntrackedDirectoriesExist) = FileOrUntrackedDirExists(selectedItems, _fullPathResolver);

            var selectionInfo = new ContextMenuSelectionInfo(
                selectedRevision: selectedRev,
                isDisplayOnlyDiff: isDisplayOnlyDiff,
                isStatusOnly: isStatusOnly,
                selectedGitItemCount: selectedGitItemCount,
                isAnyItemIndex: isAnyIndex,
                isAnyItemWorkTree: isAnyWorkTree,
                isBareRepository: isBareRepository,
                allFilesExist: allFilesExist,
                allDirectoriesExist: allDirectoriesExist,
                allFilesOrUntrackedDirectoriesExist: allFilesOrUntrackedDirectoriesExist,
                isAnyTracked: isAnyTracked,
                supportPatches: supportPatches,
                isDeleted: isDeleted,
                isAnySubmodule: isAnySubmodule);

            return(selectionInfo);