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

FormCheckoutRevision: make similar to CreateBranch/Tag dialogs and use in RevisionGrid #1685

Merged
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
4 changes: 2 additions & 2 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ private void GitcommandLogToolStripMenuItemClick(object sender, EventArgs e)

private void CheckoutBranchToolStripMenuItemClick(object sender, EventArgs e)
{
UICommands.StartCheckoutBranchDialog(this);
UICommands.StartCheckoutBranch(this);
}

private void StashToolStripMenuItemClick(object sender, EventArgs e)
Expand Down Expand Up @@ -2057,7 +2057,7 @@ private void CurrentBranchDropDownOpening(object sender, EventArgs e)
void BranchSelectToolStripItem_Click(object sender, EventArgs e)
{
var toolStripItem = (ToolStripItem)sender;
UICommands.StartCheckoutBranchDialog(this, toolStripItem.Text, false);
UICommands.StartCheckoutBranch(this, toolStripItem.Text, false);
}

private void _forkCloneMenuItem_Click(object sender, EventArgs e)
Expand Down
85 changes: 64 additions & 21 deletions GitUI/CommandsDialogs/FormCheckoutRevision.Designer.cs

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

24 changes: 16 additions & 8 deletions GitUI/CommandsDialogs/FormCheckoutRevision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,40 @@ public FormCheckoutRevision(GitUICommands aCommands)
Translate();
}

private void FormCheckoutLoad(object sender, EventArgs e)
{

}

public void SetRevision(string commitHash)
{
commitPickerSmallControl1.SetSelectedCommitHash(commitHash);
}

private void OkClick(object sender, EventArgs e)
{
try
{
if (RevisionGrid.GetSelectedRevisions().Count != 1)
var commitHash = commitPickerSmallControl1.SelectedCommitHash;

if (commitHash.IsNullOrEmpty())
{
MessageBox.Show(this, _noRevisionSelectedMsgBox.Text, _noRevisionSelectedMsgBoxCaption.Text);
return;
}

string command = GitCommandHelpers.CheckoutCmd(RevisionGrid.GetSelectedRevisions()[0].Guid,
Force.Checked ? LocalChangesAction.Reset : 0);
string command = GitCommandHelpers.CheckoutCmd(commitHash, Force.Checked ? LocalChangesAction.Reset : 0);

FormProcess.ShowDialog(this, command);

DialogResult = System.Windows.Forms.DialogResult.OK;

Close();
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}
}

private void FormCheckoutLoad(object sender, EventArgs e)
{
RevisionGrid.Load();
}
}
}
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ private void DoCommit(bool amend, bool push)
{
case 0:
string revision = _editedCommit != null ? _editedCommit.Guid : "";
if (!UICommands.StartCheckoutBranchDialog(this, revision))
if (!UICommands.StartCheckoutBranch(this, revision))
return;
break;
case -1:
Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormCreateBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public GitRevision Revision
set
{
_revision = value;
commitPickerSmallControl1.SelectedCommitHash = _revision.Guid;
commitPickerSmallControl1.SetSelectedCommitHash(_revision.Guid);
}
}

Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormCreateTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public FormCreateTag(GitUICommands aCommands, GitRevision revision)

commitPickerSmallControl1.UICommandsSource = this;
tagMessage.MistakeFont = new Font(SystemFonts.MessageBoxFont, FontStyle.Underline);
commitPickerSmallControl1.SelectedCommitHash = revision == null ? null : revision.Guid;
commitPickerSmallControl1.SetSelectedCommitHash(revision == null ? null : revision.Guid);
}

private void FormTagSmall_Load(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormPull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public DialogResult PullChanges(IWin32Window owner)
switch (idx)
{
case 0:
if (!UICommands.StartCheckoutBranchDialog(owner, ""))
if (!UICommands.StartCheckoutBranch(owner, ""))
return DialogResult.Cancel;
break;
case -1:
Expand Down
49 changes: 26 additions & 23 deletions GitUI/GitUICommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,15 @@ public bool StartDeleteBranchDialog(string branch)
return StartDeleteBranchDialog(null, branch);
}

public bool StartCheckoutRevisionDialog(IWin32Window owner)
public bool StartCheckoutRevisionDialog(IWin32Window owner, string revision = null)
{
return DoActionOnRepo(owner, true, true, PreCheckoutRevision, PostCheckoutRevision, () =>
{
using (var form = new FormCheckoutRevision(this))
form.ShowDialog(owner);
return true;
{
form.SetRevision(revision);
return form.ShowDialog(owner) == DialogResult.OK;
}
}
);
}
Expand Down Expand Up @@ -365,8 +367,8 @@ public void InvokeEventOnClose(Form form, GitUIEventHandler ev)
/// <param name="changesRepo">if successfuly done action changes repo state</param>
/// <param name="preEvent">Event invoked before performing action</param>
/// <param name="postEvent">Event invoked after performing action</param>
/// <param name="action">Action to do</param>
/// <returns>true if action was done, false otherwise</returns>
/// <param name="action">Action to do. Return true to indicate that the action was successfully done.</param>
/// <returns>true if action was sccessfully done, false otherwise</returns>
public bool DoActionOnRepo(IWin32Window owner, bool requiresValidWorkingDir, bool changesRepo,
GitUIEventHandler preEvent, GitUIPostActionEventHandler postEvent, Func<bool> action)
{
Expand Down Expand Up @@ -411,7 +413,7 @@ public bool DoActionOnRepo(Func<bool> action)
return DoActionOnRepo(null, false, true, null, null, action);
}

public bool StartCheckoutBranchDialog(IWin32Window owner, string branch, bool remote, string containRevison)
public bool StartCheckoutBranch(IWin32Window owner, string branch, bool remote, string containRevison)
{
return DoActionOnRepo(owner, true, true, PreCheckoutBranch, PostCheckoutBranch, () =>
{
Expand All @@ -421,41 +423,42 @@ public bool StartCheckoutBranchDialog(IWin32Window owner, string branch, bool re
);
}

public bool StartCheckoutBranchDialog(IWin32Window owner, string branch, bool remote)
public bool StartCheckoutBranch(IWin32Window owner, string branch, bool remote)
{
return StartCheckoutBranchDialog(owner, branch, remote, null);
return StartCheckoutBranch(owner, branch, remote, null);
}

public bool StartCheckoutBranchDialog(IWin32Window owner, string containRevison)
public bool StartCheckoutBranch(IWin32Window owner, string containRevison)
{
return StartCheckoutBranchDialog(owner, "", false, containRevison);
return StartCheckoutBranch(owner, "", false, containRevison);
}

public bool StartCheckoutBranchDialog(IWin32Window owner)
public bool StartCheckoutBranch(IWin32Window owner)
{
return StartCheckoutBranchDialog(owner, "", false, null);
return StartCheckoutBranch(owner, "", false, null);
}

public bool StartCheckoutBranchDialog()
public bool StartCheckoutBranch()
{
return StartCheckoutBranchDialog(null, "", false, null);
return StartCheckoutBranch(null, "", false, null);
}

public bool StartCheckoutRemoteBranchDialog(IWin32Window owner, string branch)
public bool StartCheckoutRemoteBranch(IWin32Window owner, string branch)
{
return StartCheckoutBranchDialog(owner, branch, true);
return StartCheckoutBranch(owner, branch, true);
}

public bool StartCompareRevisionsDialog(IWin32Window owner)
{
Func<bool> action = () =>
{
using (var form = new FormLog(this))
form.ShowDialog(owner);
return true;
{
return form.ShowDialog(owner) == DialogResult.OK;
}
};

return DoActionOnRepo(owner, true, false, PreCompareRevisions, PostCompareRevisions, action);
return DoActionOnRepo(owner, true, true, PreCompareRevisions, PostCompareRevisions, action);
}

public bool StartCompareRevisionsDialog()
Expand Down Expand Up @@ -1081,9 +1084,9 @@ public bool StartCreateTagDialog(IWin32Window owner)
Func<bool> action = () =>
{
using (var form = new FormCreateTag(this, null))
form.ShowDialog(owner);

return true;
{
return form.ShowDialog(owner) == DialogResult.OK;
}
};

return DoActionOnRepo(owner, true, true, PreCreateTag, PostCreateTag, action);
Expand Down Expand Up @@ -1742,7 +1745,7 @@ private void RunCommandBasedOnArgument(string[] args, Dictionary<string, string>
return;
case "checkout":
case "checkoutbranch":
StartCheckoutBranchDialog();
StartCheckoutBranch();
return;
case "checkoutrevision":
StartCheckoutRevisionDialog();
Expand Down