Skip to content

Commit

Permalink
Merge pull request #8499 from lanfeust69/fix_jumplist
Browse files Browse the repository at this point in the history
Fix JumpList being created too soon
  • Loading branch information
RussKie committed Oct 2, 2020
2 parents fde9a6e + c91a780 commit c713a39
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
17 changes: 11 additions & 6 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,12 +579,6 @@ protected override void OnApplicationActivated()

protected override void OnLoad(EventArgs e)
{
_windowsJumpListManager.CreateJumpList(
Handle,
new WindowsThumbnailToolbarButtons(
new WindowsThumbnailToolbarButton(toolStripButtonCommit.Text, toolStripButtonCommit.Image, CommitToolStripMenuItemClick),
new WindowsThumbnailToolbarButton(toolStripButtonPush.Text, toolStripButtonPush.Image, PushToolStripMenuItemClick),
new WindowsThumbnailToolbarButton(toolStripButtonPull.Text, toolStripButtonPull.Image, PullToolStripMenuItemClick)));
SetSplitterPositions();
HideVariableMainMenuItems();
RefreshSplitViewLayout();
Expand Down Expand Up @@ -630,6 +624,17 @@ protected override void OnLoad(EventArgs e)

protected override void OnActivated(EventArgs e)
{
// wait for windows to really be displayed, which isn't necessarily the case in OnLoad()
if (_windowsJumpListManager.NeedsJumpListCreation)
{
_windowsJumpListManager.CreateJumpList(
Handle,
new WindowsThumbnailToolbarButtons(
new WindowsThumbnailToolbarButton(toolStripButtonCommit.Text, toolStripButtonCommit.Image, CommitToolStripMenuItemClick),
new WindowsThumbnailToolbarButton(toolStripButtonPush.Text, toolStripButtonPush.Image, PushToolStripMenuItemClick),
new WindowsThumbnailToolbarButton(toolStripButtonPull.Text, toolStripButtonPull.Image, PullToolStripMenuItemClick)));
}

this.InvokeAsync(OnActivate).FileAndForget();
base.OnActivated(e);
}
Expand Down
21 changes: 20 additions & 1 deletion GitUI/WindowsJumpListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class WindowsJumpListManager : IDisposable
private ThumbnailToolBarButton _commitButton;
private ThumbnailToolBarButton _pushButton;
private ThumbnailToolBarButton _pullButton;
private string _deferredAddToRecent;
private bool ToolbarButtonsCreated => _commitButton != null;
private readonly IRepositoryDescriptionProvider _repositoryDescriptionProvider;

Expand Down Expand Up @@ -65,11 +66,17 @@ private void Dispose(bool disposing)
[ContractAnnotation("workingDir:null=>halt")]
public void AddToRecent([NotNull] string workingDir)
{
if (!ToolbarButtonsCreated || !IsSupported)
if (!IsSupported)
{
return;
}

if (!ToolbarButtonsCreated)
{
_deferredAddToRecent = workingDir;
return;
}

if (string.IsNullOrWhiteSpace(workingDir))
{
throw new ArgumentException(nameof(workingDir));
Expand Down Expand Up @@ -122,6 +129,11 @@ public void UpdateCommitIcon(Image image)
}, nameof(UpdateCommitIcon));
}

/// <summary>
/// Indicates if the JumpList creation is still needed
/// </summary>
public bool NeedsJumpListCreation => IsSupported && !ToolbarButtonsCreated;

/// <summary>
/// Creates a JumpList for the given application instance.
/// It also adds thumbnail toolbars, which are a set of up to seven buttons at the bottom of the taskbar’s icon thumbnail preview.
Expand All @@ -146,6 +158,13 @@ public void CreateJumpList(IntPtr windowHandle, WindowsThumbnailToolbarButtons b
CreateTaskbarButtons(windowHandle, buttons);
}, nameof(CreateJumpList));

if (ToolbarButtonsCreated && _deferredAddToRecent != null)
{
var recentRepoAddToRecent = _deferredAddToRecent;
_deferredAddToRecent = null;
AddToRecent(recentRepoAddToRecent);
}

return;

void CreateTaskbarButtons(IntPtr handle, WindowsThumbnailToolbarButtons thumbButtons)
Expand Down

0 comments on commit c713a39

Please sign in to comment.