Skip to content

Commit 3ea72e7

Browse files
committed
fix(toolwindow): simplify tool window registration and UI
- Remove auto-show logic that was causing window to close - Remove conflicting visibility attributes - Simplify XAML to basic placeholder for debugging - Window now opens only via View menu
1 parent 707cbcb commit 3ea72e7

4 files changed

Lines changed: 23 additions & 109 deletions

File tree

src/CodingWithCalvin.LaunchyBar/LaunchyBarPackage.cs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,10 @@ namespace CodingWithCalvin.LaunchyBar;
1616
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
1717
[Guid(VSCommandTableVsct.guidLaunchyBarPackageString)]
1818
[ProvideMenuResource("Menus.ctmenu", 1)]
19-
[ProvideToolWindow(
20-
typeof(LaunchyBarWindow),
21-
Style = VsDockStyle.MDI,
22-
Orientation = ToolWindowOrientation.Left,
23-
Width = 60,
24-
Height = 600,
25-
Window = "3ae79031-e1bc-11d0-8f78-00a0c9110057")]
26-
[ProvideToolWindowVisibility(typeof(LaunchyBarWindow), VSConstants.UICONTEXT.NoSolution_string)]
27-
[ProvideToolWindowVisibility(typeof(LaunchyBarWindow), VSConstants.UICONTEXT.SolutionExists_string)]
28-
[ProvideToolWindowVisibility(typeof(LaunchyBarWindow), VSConstants.UICONTEXT.EmptySolution_string)]
19+
[ProvideToolWindow(typeof(LaunchyBarWindow))]
2920
[ProvideAutoLoad(VSConstants.UICONTEXT.ShellInitialized_string, PackageAutoLoadFlags.BackgroundLoad)]
30-
[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)]
31-
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
3221
[ProvideOptionPage(typeof(OptionsProvider.GeneralOptionsPage), "LaunchyBar", "General", 0, 0, true)]
33-
public sealed class LaunchyBarPackage : AsyncPackage
22+
public sealed class LaunchyBarPackage : ToolkitPackage
3423
{
3524
public static LaunchyBarPackage? Instance { get; private set; }
3625

@@ -63,24 +52,6 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
6352
LaunchService = new LaunchService(this);
6453

6554
await this.RegisterCommandsAsync();
66-
67-
await ShowToolWindowAsync(cancellationToken);
68-
}
69-
70-
private async Task ShowToolWindowAsync(CancellationToken cancellationToken)
71-
{
72-
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
73-
74-
var window = await FindToolWindowAsync(
75-
typeof(LaunchyBarWindow),
76-
0,
77-
create: true,
78-
cancellationToken);
79-
80-
if (window?.Frame is IVsWindowFrame windowFrame)
81-
{
82-
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
83-
}
8455
}
8556

8657
protected override void Dispose(bool disposing)

src/CodingWithCalvin.LaunchyBar/ToolWindow/LaunchyBarControl.xaml

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,15 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:vs="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
7-
xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
8-
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
9-
xmlns:theming="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
107
mc:Ignorable="d"
118
d:DesignHeight="600" d:DesignWidth="48"
12-
Background="{DynamicResource {x:Static vs:VsBrushes.ToolWindowBackgroundKey}}"
13-
theming:ImageThemingUtilities.ImageBackgroundColor="{DynamicResource {x:Static vs:VsColors.ToolWindowBackgroundKey}}">
14-
15-
<UserControl.Resources>
16-
<ResourceDictionary>
17-
<ResourceDictionary.MergedDictionaries>
18-
<ResourceDictionary Source="../Themes/LaunchyBarStyles.xaml"/>
19-
</ResourceDictionary.MergedDictionaries>
20-
</ResourceDictionary>
21-
</UserControl.Resources>
9+
Background="{DynamicResource {x:Static vs:VsBrushes.ToolWindowBackgroundKey}}">
2210

2311
<Grid>
24-
<Grid.RowDefinitions>
25-
<RowDefinition Height="*"/>
26-
<RowDefinition Height="Auto"/>
27-
</Grid.RowDefinitions>
28-
29-
<!-- Top Items (flow down) -->
30-
<ItemsControl Grid.Row="0"
31-
ItemsSource="{Binding TopItems}"
32-
VerticalAlignment="Top">
33-
<ItemsControl.ItemTemplate>
34-
<DataTemplate>
35-
<Button Style="{StaticResource LaunchyBarButtonStyle}"
36-
Command="{Binding DataContext.LaunchCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
37-
CommandParameter="{Binding}"
38-
ToolTip="{Binding Name}"
39-
IsEnabled="{Binding IsEnabled}">
40-
<imaging:CrispImage x:Name="ButtonImage"
41-
Width="24" Height="24"
42-
Moniker="{Binding IconMoniker}" />
43-
</Button>
44-
</DataTemplate>
45-
</ItemsControl.ItemTemplate>
46-
</ItemsControl>
47-
48-
<!-- Bottom Items (flow up) -->
49-
<ItemsControl Grid.Row="1"
50-
ItemsSource="{Binding BottomItems}"
51-
VerticalAlignment="Bottom">
52-
<ItemsControl.ItemTemplate>
53-
<DataTemplate>
54-
<Button Style="{StaticResource LaunchyBarButtonStyle}"
55-
Command="{Binding DataContext.LaunchCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
56-
CommandParameter="{Binding}"
57-
ToolTip="{Binding Name}"
58-
IsEnabled="{Binding IsEnabled}">
59-
<imaging:CrispImage x:Name="ButtonImage"
60-
Width="24" Height="24"
61-
Moniker="{Binding IconMoniker}" />
62-
</Button>
63-
</DataTemplate>
64-
</ItemsControl.ItemTemplate>
65-
</ItemsControl>
12+
<TextBlock Text="LaunchyBar"
13+
Foreground="{DynamicResource {x:Static vs:VsBrushes.ToolWindowTextKey}}"
14+
VerticalAlignment="Center"
15+
HorizontalAlignment="Center"
16+
TextWrapping="Wrap"/>
6617
</Grid>
6718
</UserControl>
Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System.Windows.Controls;
2-
using CodingWithCalvin.LaunchyBar.ViewModels;
3-
using Microsoft.VisualStudio.Shell;
42

53
namespace CodingWithCalvin.LaunchyBar.ToolWindow;
64

@@ -12,25 +10,5 @@ public partial class LaunchyBarControl : UserControl
1210
public LaunchyBarControl()
1311
{
1412
InitializeComponent();
15-
16-
Loaded += OnLoaded;
17-
}
18-
19-
private async void OnLoaded(object sender, System.Windows.RoutedEventArgs e)
20-
{
21-
var package = LaunchyBarPackage.Instance;
22-
if (package?.ConfigurationService != null && package?.LaunchService != null)
23-
{
24-
var viewModel = new LaunchyBarViewModel(
25-
package.ConfigurationService,
26-
package.LaunchService);
27-
28-
DataContext = viewModel;
29-
30-
await ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
31-
{
32-
await viewModel.InitializeAsync();
33-
});
34-
}
3513
}
3614
}

src/CodingWithCalvin.LaunchyBar/ToolWindow/LaunchyBarWindow.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ public LaunchyBarWindow() : base(null)
2828
/// </summary>
2929
public static async Task ShowAsync()
3030
{
31-
await VS.Windows.ShowToolWindowAsync(new Guid(VSCommandTableVsct.guidLaunchyBarToolWindowString));
31+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
32+
33+
var package = LaunchyBarPackage.Instance;
34+
if (package == null) return;
35+
36+
var window = await package.FindToolWindowAsync(
37+
typeof(LaunchyBarWindow),
38+
0,
39+
create: true,
40+
package.DisposalToken);
41+
42+
if (window?.Frame is Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame frame)
43+
{
44+
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(frame.Show());
45+
}
3246
}
3347
}

0 commit comments

Comments
 (0)