Skip to content

Commit

Permalink
Browse Diff tab menu alternatives and presentation
Browse files Browse the repository at this point in the history
Fixes gitextensions#4564
Fixes gitextensions#4387
Fixes gitextensions#4396

Depends on gitextensions#4562 gitextensions#4663 gitextensions#4365 gitextensions#4366 gitextensions#4367 gitextensions#4368
Submitted to allow review of the outcome to gitextensions#4564
Note: Due to the structure of tests in a separate class, it is very difficult to split this issue in several commits

Rewrote RevisionDiffController to make it possible to have some kind of tests. The tests are retrofitted to the current functionality as they are just testing the menu items and not the actions themselves. (The tests adds may more maintenance than they give benefits but the formal test coverage increases.)

Browse Diff:
Submodules actions available for multi select (gitextensions#4568)
Presents the Reset options for the correct parent in multi select situations
No longer differ between parent-child and first-second for Reset
Difftool: Describes A and B revisions in the menu
Difftool arguments depends on parent availability
Better detection of parents to A/B for diffs

Commit:
Limit DiffTool and FileHistory to tracked

FormDiff:
Limit FileHistory to Tracked
Use RevisionDiffController to align to Browse-Diff
  • Loading branch information
gerhardol committed Mar 10, 2018
1 parent 37cd7d2 commit 9cd527e
Show file tree
Hide file tree
Showing 10 changed files with 615 additions and 298 deletions.
3 changes: 3 additions & 0 deletions GitUI/CommandsDialogs/FormCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,10 +1346,13 @@ private void UnstagedFileContext_Opening(object sender, System.ComponentModel.Ca
var isAssumeUnchangedExist = Unstaged.SelectedItems.Any(s => s.IsAssumeUnchanged);
var isAssumeUnchangedAll = Unstaged.SelectedItems.All(s => s.IsAssumeUnchanged);
var isSkipWorktreeAll = Unstaged.SelectedItems.All(s => s.IsSkipWorktree);

openWithDifftoolToolStripMenuItem.Enabled = isTrackedSelected;
assumeUnchangedToolStripMenuItem.Visible = isTrackedSelected && !isSkipWorktreeExist && !isAssumeUnchangedAll;
doNotAssumeUnchangedToolStripMenuItem.Visible = showAssumeUnchangedFilesToolStripMenuItem.Checked && !isSkipWorktreeExist && isAssumeUnchangedExist;
skipWorktreeToolStripMenuItem.Visible = isTrackedSelected && !isAssumeUnchangedExist && !isSkipWorktreeAll;
doNotSkipWorktreeToolStripMenuItem.Visible = showSkipWorktreeFilesToolStripMenuItem.Checked && !isAssumeUnchangedExist && isSkipWorktreeExist;
viewFileHistoryToolStripItem.Enabled = isTrackedSelected;
}

private void Unstaged_Enter(object sender, EventArgs e)
Expand Down
13 changes: 7 additions & 6 deletions GitUI/CommandsDialogs/FormDiff.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 48 additions & 6 deletions GitUI/CommandsDialogs/FormDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public partial class FormDiff : GitModuleForm
private GitRevision _baseRevision;
private GitRevision _headRevision;
private readonly GitRevision _mergeBase;
private IRevisionDiffController _revisionDiffController;
private readonly IFullPathResolver _fullPathResolver;
private readonly IFindFilePredicateProvider _findFilePredicateProvider;

private ToolTip _toolTipControl = new ToolTip();
Expand Down Expand Up @@ -52,6 +54,7 @@ public FormDiff(GitUICommands commands, RevisionGrid revisionGrid, string baseCo
_baseRevision = new GitRevision(baseCommitSha);
_headRevision = new GitRevision(headCommitSha);
_mergeBase = new GitRevision(Module.GetMergeBase(_baseRevision.Guid, _headRevision.Guid));
_fullPathResolver = new FullPathResolver(() => Module.WorkingDir);
_findFilePredicateProvider = new FindFilePredicateProvider();

lblBaseCommit.BackColor = AppSettings.DiffRemovedColor;
Expand All @@ -65,6 +68,12 @@ public FormDiff(GitUICommands commands, RevisionGrid revisionGrid, string baseCo
DiffText.ExtraDiffArgumentsChanged += DiffTextOnExtraDiffArgumentsChanged;
}

protected override void OnRuntimeLoad(EventArgs e)
{
_revisionDiffController = new RevisionDiffController();
base.OnRuntimeLoad(e);
}

private void DiffTextOnExtraDiffArgumentsChanged(object sender, EventArgs eventArgs)
{
ShowSelectedFileDiff();
Expand Down Expand Up @@ -240,14 +249,47 @@ private void btnAnotherHeadCommit_Click(object sender, EventArgs e)
PickAnotherCommit(_headRevision, ref _headCommitDisplayStr, ref _headRevision);
}

private void openWithDifftoolToolStripMenuItem_DropDownOpening(object sender, System.ComponentModel.CancelEventArgs e)
private void diffContextToolStripMenuItem_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
aLocalToolStripMenuItem.Enabled = _baseRevision != null && _baseRevision.Guid != GitRevision.UnstagedGuid && !Module.IsBareRepository();
bLocalToolStripMenuItem.Enabled = _headRevision != null && _headRevision.Guid != GitRevision.UnstagedGuid && !Module.IsBareRepository();
parentOfALocalToolStripMenuItem.Enabled = parentOfBLocalToolStripMenuItem.Enabled = !Module.IsBareRepository();

bool isAnyTracked = DiffFiles.SelectedItems.Any(item => item.IsTracked);
bool isExactlyOneItemSelected = DiffFiles.SelectedItems.Count() == 1;
blameToolStripMenuItem.Visible = isExactlyOneItemSelected && !(DiffFiles.SelectedItem.IsSubmodule || _baseRevision.IsArtificial);

openWithDifftoolToolStripMenuItem.Enabled = isAnyTracked;
fileHistoryDiffToolstripMenuItem.Enabled = isAnyTracked && isExactlyOneItemSelected;
blameToolStripMenuItem.Enabled = fileHistoryDiffToolstripMenuItem.Enabled && !DiffFiles.SelectedItem.IsSubmodule;
}

private ContextMenuDiffToolInfo GetContextMenuDiffToolInfo()
{
bool firstIsParent = _revisionDiffController.AisParent(DiffFiles.Revision.ParentGuids, DiffFiles.SelectedItemParents.Select(i => i.Guid));
bool localExists = _revisionDiffController.LocalExists(DiffFiles.SelectedItemsWithParent, _fullPathResolver);

IEnumerable<string> selectedItemParentRevs = DiffFiles.Revision.ParentGuids;
bool allAreNew = DiffFiles.SelectedItemsWithParent.All(i => i.Item.IsNew);
bool allAreDeleted = DiffFiles.SelectedItemsWithParent.All(i => i.Item.IsDeleted);
var revisions = _revisionGrid.GetSelectedRevisions();
bool firstParentsValid = revisions != null && revisions.Count > 1;

var selectionInfo = new ContextMenuDiffToolInfo(_headRevision, selectedItemParentRevs,
allAreNew: allAreNew,
allAreDeleted: allAreDeleted,
firstIsParent: firstIsParent,
firstParentsValid: firstParentsValid,
localExists: localExists);
return selectionInfo;
}

private void openWithDifftoolToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
{
ContextMenuDiffToolInfo selectionInfo = GetContextMenuDiffToolInfo();

aBToolStripMenuItem.Enabled = _revisionDiffController.ShouldShowMenuAB(selectionInfo);
aLocalToolStripMenuItem.Enabled = _revisionDiffController.ShouldShowMenuALocal(selectionInfo);
bLocalToolStripMenuItem.Enabled = _revisionDiffController.ShouldShowMenuBLocal(selectionInfo);
parentOfALocalToolStripMenuItem.Enabled = _revisionDiffController.ShouldShowMenuAParentLocal(selectionInfo);
parentOfBLocalToolStripMenuItem.Enabled = _revisionDiffController.ShouldShowMenuBParentLocal(selectionInfo);
parentOfALocalToolStripMenuItem.Visible = _revisionDiffController.ShouldDisplayMenuAParentLocal(selectionInfo);
parentOfBLocalToolStripMenuItem.Visible = _revisionDiffController.ShouldDisplayMenuBParentLocal(selectionInfo);
}

private void PickAnotherBranch(GitRevision preSelectCommit, ref string displayStr, ref GitRevision revision)
Expand Down
Loading

0 comments on commit 9cd527e

Please sign in to comment.