Skip to content

Commit

Permalink
Add support for newer version of vs to VisualStudioStatusBarHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Nov 2, 2023
1 parent 0515f0f commit 9f9f39e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Integration/Notifications/VisualStudioStatusBarHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace SonarLint.VisualStudio.Integration.Notifications
public static class VisualStudioStatusBarHelper
{
private const string SccStatusBarHostName = "PART_SccStatusBarHost";
private const string StatusBarRightFrameControlContainerName = "PART_StatusBarRightFrameControlContainer";

public static void RemoveStatusBarIcon(FrameworkElement statusBarIcon)
{
Expand Down Expand Up @@ -60,10 +61,8 @@ public static void AddStatusBarIcon(FrameworkElement statusBarIcon)
/// </remarks>
private static void AddStatusBarIcon(Window window, UIElement statusBarIcon)
{
var statusBarPart = window?.Template?.FindName(SccStatusBarHostName, window) as FrameworkElement;
var parent = statusBarPart?.Parent as DockPanel;

if (parent == null)
if(!GetOldStatusBarPlacement(SccStatusBarHostName, window, out var statusBarPart, out var parent)
&& !GetOldStatusBarPlacement(StatusBarRightFrameControlContainerName, window, out statusBarPart, out parent))
{
Debug.Fail("Could not find status bar container");
return;
Expand All @@ -72,5 +71,12 @@ private static void AddStatusBarIcon(Window window, UIElement statusBarIcon)
var index = parent.Children.IndexOf(statusBarPart);
parent.Children.Insert(index + 1, statusBarIcon);
}

private static bool GetOldStatusBarPlacement(string statusBarElementToAttachAfter, Window window, out FrameworkElement statusBarElement, out DockPanel parent)
{
statusBarElement = window?.Template?.FindName(statusBarElementToAttachAfter, window) as FrameworkElement;
parent = statusBarElement?.Parent as DockPanel;
return parent != null;
}
}
}

0 comments on commit 9f9f39e

Please sign in to comment.