Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show FormDiff modeless. #4807

Merged
merged 3 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions GitUI/CommandsDialogs/FormDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace GitUI.CommandsDialogs
{
public partial class FormDiff : GitModuleForm
{
private readonly RevisionGrid _revisionGrid;
private string _baseCommitDisplayStr;
private string _headCommitDisplayStr;
private GitRevision _baseRevision;
Expand All @@ -22,6 +21,7 @@ public partial class FormDiff : GitModuleForm
private IFileStatusListContextMenuController _revisionDiffContextMenuController;
private readonly IFullPathResolver _fullPathResolver;
private readonly IFindFilePredicateProvider _findFilePredicateProvider;
private readonly bool _firstParentIsValid;

private readonly ToolTip _toolTipControl = new ToolTip();

Expand All @@ -32,12 +32,12 @@ public partial class FormDiff : GitModuleForm
private readonly TranslationString _btnSwapTooltip =
new TranslationString("Swap BASE and Compare commits");

public FormDiff(GitUICommands commands, RevisionGrid revisionGrid, string baseCommitSha,
public FormDiff(GitUICommands commands, bool firstParentIsValid, string baseCommitSha,
string headCommitSha, string baseCommitDisplayStr, string headCommitDisplayStr) : base(commands)
{
_revisionGrid = revisionGrid;
_baseCommitDisplayStr = baseCommitDisplayStr;
_headCommitDisplayStr = headCommitDisplayStr;
_firstParentIsValid = firstParentIsValid;

InitializeComponent();
Translate();
Expand Down Expand Up @@ -161,7 +161,7 @@ private void openWithDifftoolToolStripMenuItem_Click(object sender, EventArgs e)
foreach (var itemWithParent in DiffFiles.SelectedItemsWithParent)
{
var revs = new[] { DiffFiles.Revision, itemWithParent.ParentRevision };
_revisionGrid.OpenWithDifftool(revs, itemWithParent.Item.Name, itemWithParent.Item.OldName, diffKind, itemWithParent.Item.IsTracked);
UICommands.OpenWithDifftool(this, revs, itemWithParent.Item.Name, itemWithParent.Item.OldName, diffKind, itemWithParent.Item.IsTracked);
}
}

Expand Down Expand Up @@ -264,14 +264,12 @@ private ContextMenuDiffToolInfo GetContextMenuDiffToolInfo()
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,
firstParentsValid: _firstParentIsValid,
localExists: localExists);
return selectionInfo;
}
Expand Down
4 changes: 2 additions & 2 deletions GitUI/CommandsDialogs/FormFileHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private void OpenWithDifftoolToolStripMenuItemClick(object sender, EventArgs e)
? selectedRevisions[0].Name
: null;

FileChanges.OpenWithDifftool(selectedRevisions, FileName, orgFileName, RevisionDiffKind.DiffAB, true);
UICommands.OpenWithDifftool(this, selectedRevisions, FileName, orgFileName, RevisionDiffKind.DiffAB, true);
}

private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -482,7 +482,7 @@ public override void TranslateItems(ITranslation translation)

private void diffToolremotelocalStripMenuItem_Click(object sender, EventArgs e)
{
FileChanges.OpenWithDifftool(FileChanges.GetSelectedRevisions(), FileName, string.Empty, RevisionDiffKind.DiffBLocal, true);
UICommands.OpenWithDifftool(this, FileChanges.GetSelectedRevisions(), FileName, string.Empty, RevisionDiffKind.DiffBLocal, true);
}

private void toolStripSplitLoad_ButtonClick(object sender, EventArgs e)
Expand Down
8 changes: 2 additions & 6 deletions GitUI/CommandsDialogs/RevisionDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ private void openWithDifftoolToolStripMenuItem_Click(object sender, EventArgs e)
foreach (var itemWithParent in DiffFiles.SelectedItemsWithParent)
{
var revs = new[] { DiffFiles.Revision, itemWithParent.ParentRevision };
_revisionGrid.OpenWithDifftool(revs, itemWithParent.Item.Name, itemWithParent.Item.OldName, diffKind, itemWithParent.Item.IsTracked);
UICommands.OpenWithDifftool(this, revs, itemWithParent.Item.Name, itemWithParent.Item.OldName, diffKind, itemWithParent.Item.IsTracked);
}
}

Expand All @@ -584,16 +584,12 @@ private ContextMenuDiffToolInfo GetContextMenuDiffToolInfo()
IEnumerable<string> selectedItemParentRevs = DiffFiles.SelectedItemParents.Select(i => i.Guid);
bool allAreNew = DiffFiles.SelectedItemsWithParent.All(i => i.Item.IsNew);
bool allAreDeleted = DiffFiles.SelectedItemsWithParent.All(i => i.Item.IsDeleted);
var revisions = _revisionGrid.GetSelectedRevisions();

// Parents to First (A) are only known if A is explicitly selected (there is no explicit search for parents to parents of a single selected revision)
bool firstParentsValid = revisions != null && revisions.Count > 1;

var selectionInfo = new ContextMenuDiffToolInfo(DiffFiles.Revision, selectedItemParentRevs,
allAreNew: allAreNew,
allAreDeleted: allAreDeleted,
firstIsParent: firstIsParent,
firstParentsValid: firstParentsValid,
firstParentsValid: _revisionGrid.IsFirstParentValid(),
localExists: localExists);
return selectionInfo;
}
Expand Down
32 changes: 32 additions & 0 deletions GitUI/GitUICommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,38 @@ public void StartFileHistoryDialog(string fileName)
StartFileHistoryDialog(fileName, null);
}

public void OpenWithDifftool(IWin32Window owner, IReadOnlyList<GitRevision> revisions, string fileName, string oldFileName, GitUI.RevisionDiffKind diffKind, bool isTracked)
{
// Note: Order in revisions is that first clicked is last in array

string error = RevisionDiffInfoProvider.Get(revisions, diffKind,
out var extraDiffArgs, out var firstRevision, out var secondRevision);

if (!string.IsNullOrEmpty(error))
{
MessageBox.Show(owner, error);
}
else
{
string output = Module.OpenWithDifftool(fileName, oldFileName, firstRevision, secondRevision, extraDiffArgs, isTracked);
if (!string.IsNullOrEmpty(output))
{
MessageBox.Show(owner, output);
}
}
}

public FormDiff ShowFormDiff(bool firstParentIsValid, string baseCommitSha,
string headCommitSha, string baseCommitDisplayStr, string headCommitDisplayStr)
{
var diffForm = new FormDiff(this, firstParentIsValid, baseCommitSha,
headCommitSha, baseCommitDisplayStr, headCommitDisplayStr);
diffForm.Show();
diffForm.ShowInTaskbar = true;

return diffForm;
}

public bool StartPushDialog()
{
return StartPushDialog(false);
Expand Down
21 changes: 0 additions & 21 deletions GitUI/GitUIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,6 @@ namespace GitUI
{
public static class GitUIExtensions
{
public static void OpenWithDifftool(this RevisionGrid grid, IReadOnlyList<GitRevision> revisions, string fileName, string oldFileName, GitUI.RevisionDiffKind diffKind, bool isTracked)
{
// Note: Order in revisions is that first clicked is last in array

string error = RevisionDiffInfoProvider.Get(revisions, diffKind,
out var extraDiffArgs, out var firstRevision, out var secondRevision);

if (!string.IsNullOrEmpty(error))
{
MessageBox.Show(grid, error);
}
else
{
string output = grid.Module.OpenWithDifftool(fileName, oldFileName, firstRevision, secondRevision, extraDiffArgs, isTracked);
if (!string.IsNullOrEmpty(output))
{
MessageBox.Show(grid, output);
}
}
}

[CanBeNull]
private static Patch GetItemPatch(
[NotNull] GitModule module,
Expand Down
29 changes: 14 additions & 15 deletions GitUI/UserControls/RevisionGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,14 @@ public IReadOnlyList<GitRevision> GetSelectedRevisions(SortDirection? direction
.ToList();
}

public bool IsFirstParentValid()
{
var revisions = GetSelectedRevisions();

// Parents to First (A) are only known if A is explicitly selected (there is no explicit search for parents to parents of a single selected revision)
return revisions != null && revisions.Count > 1;
}

public IReadOnlyList<string> GetRevisionChildren(string revision)
{
return Revisions.GetRevisionChildren(revision);
Expand Down Expand Up @@ -3732,11 +3740,8 @@ private void CompareToBranchToolStripMenuItem_Click(object sender, EventArgs e)
if (form.ShowDialog(this) == DialogResult.OK)
{
var baseCommit = Module.RevParse(form.BranchName);
using (var diffForm = new FormDiff(UICommands, this, baseCommit, headCommit.Guid,
form.BranchName, headCommit.Subject))
{
diffForm.ShowDialog(this);
}
UICommands.ShowFormDiff(IsFirstParentValid(), baseCommit, headCommit.Guid,
form.BranchName, headCommit.Subject);
}
}
}
Expand All @@ -3746,11 +3751,8 @@ private void CompareWithCurrentBranchToolStripMenuItem_Click(object sender, Even
var baseCommit = GetSelectedRevisions().First();
var headBranch = Module.GetSelectedBranch();
var headBranchName = Module.RevParse(headBranch);
using (var diffForm = new FormDiff(UICommands, this, baseCommit.Guid, headBranchName,
baseCommit.Subject, headBranch))
{
diffForm.ShowDialog(this);
}
UICommands.ShowFormDiff(IsFirstParentValid(), baseCommit.Guid, headBranchName,
baseCommit.Subject, headBranch);
}

private void selectAsBaseToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -3768,11 +3770,8 @@ private void compareToBaseToolStripMenuItem_Click(object sender, EventArgs e)
}

var headCommit = GetSelectedRevisions().First();
using (var diffForm = new FormDiff(UICommands, this, _baseCommitToCompare.Guid, headCommit.Guid,
_baseCommitToCompare.Subject, headCommit.Subject))
{
diffForm.ShowDialog(this);
}
UICommands.ShowFormDiff(IsFirstParentValid(), _baseCommitToCompare.Guid, headCommit.Guid,
_baseCommitToCompare.Subject, headCommit.Subject);
}

private void getHelpOnHowToUseTheseFeaturesToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down