Skip to content

Commit

Permalink
Sidepanel: Keep revisions opening a new instance (gitextensions#10146)
Browse files Browse the repository at this point in the history
When launching a new GE instance from the sidepanel, set
first/last selected revisions in the grid as first/second in
the new instance.
  • Loading branch information
gerhardol committed Sep 1, 2022
1 parent 9788a28 commit 1952f2f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
19 changes: 18 additions & 1 deletion GitUI/BranchTreePanel/SubmoduleNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using GitCommands;
using GitCommands.Git;
using GitCommands.Submodules;
Expand Down Expand Up @@ -84,7 +85,23 @@ public void LaunchGitExtensions()
return;
}

GitUICommands.LaunchBrowse(workingDir: Info.Path.EnsureTrailingPathSeparator(), ObjectId.WorkTreeId, Info?.Detailed?.RawStatus?.OldCommit);
ObjectId? selected;
ObjectId? first;
if (IsCurrent)
{
// Get the current (most likely) selections from the grid
IReadOnlyList<GitRevision>? revs = UICommands.GetSelectedRevisions() ?? new List<GitRevision>();
selected = revs.Count > 0 ? revs[0].ObjectId : null;
first = revs.Count > 1 ? revs[revs.Count - 1].ObjectId : null;
}
else
{
// Try select a "diff" from the expected commit to worktree for a submodule
selected = ObjectId.WorkTreeId;
first = Info?.Detailed?.RawStatus?.OldCommit;
}

GitUICommands.LaunchBrowse(workingDir: Info.Path.EnsureTrailingPathSeparator(), selected, first);
}

internal override void OnSelected()
Expand Down
5 changes: 5 additions & 0 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,11 @@ public void GoToRef(string refName, bool showNoRevisionMsg, bool toggleSelection
}
}

public IReadOnlyList<GitRevision> GetSelectedRevisions()
{
return RevisionGrid.GetSelectedRevisions();
}

#endregion

public void SetPathFilter(string pathFilter)
Expand Down
5 changes: 5 additions & 0 deletions GitUI/GitUICommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,11 @@ public void BrowseSetWorkingDir(string path, ObjectId? selectedId = null, Object
BrowseRepo?.SetWorkingDir(path, selectedId, firstId);
}

public IReadOnlyList<GitRevision>? GetSelectedRevisions()
{
return BrowseRepo?.GetSelectedRevisions();
}

public IGitRemoteCommand CreateRemoteCommand()
{
return new GitRemoteCommand(this);
Expand Down
5 changes: 4 additions & 1 deletion Plugins/GitUIPluginInterfaces/IBrowseRepo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
namespace GitUIPluginInterfaces
using System.Collections.Generic;

namespace GitUIPluginInterfaces
{
public interface IBrowseRepo
{
void GoToRef(string refName, bool showNoRevisionMsg, bool toggleSelection = false);
void SetWorkingDir(string? path, ObjectId? selectedId = null, ObjectId? firstId = null);
IReadOnlyList<GitRevision> GetSelectedRevisions();
}
}

0 comments on commit 1952f2f

Please sign in to comment.