Skip to content

Commit 5d33c06

Browse files
kboomGrzegorz Gurgul
and
Grzegorz Gurgul
authored
Fix missing buttons (#62)
Co-authored-by: Grzegorz Gurgul <[email protected]>
1 parent 355d7f1 commit 5d33c06

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

GitTreeFilter/Commands/CommandRegistrar.cs

+31-10
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ public static async Task InitializeAsync(IGitFiltersPackage package)
2222
try
2323
{
2424
await RegisterAsync(package, commandService);
25+
GitTreeFilterOutput.WriteLine($"Initialized all commands");
2526
}
2627
catch (Exception ex)
2728
{
29+
GitTreeFilterOutput.WriteLine($"Failed to register commands: {ex}");
2830
ActivityLog.LogError(nameof(CommandRegistrar), $"Failed to register commands - {ex}");
2931
throw ex;
3032
}
@@ -50,19 +52,38 @@ private static async Task RegisterAsync(IGitFiltersPackage package, IMenuCommand
5052

5153
private static void RegisterCommand(IMenuCommandService commandService, int rawCommandId, GitFiltersCommand command)
5254
{
53-
var commandId = new CommandID(GitFiltersControls.GitFiltersControlsCmdSet, rawCommandId);
54-
var menuCommand = new OleMenuCommand(command.OnExecute, commandId);
55+
GitTreeFilterOutput.WriteLine($"Registering command {command.GetType()} with id {rawCommandId}");
5556

56-
menuCommand.BeforeQueryStatus += delegate (object sender, EventArgs e)
57+
var commandId = new CommandID(GitFiltersControls.GitFiltersControlsCmdSet, rawCommandId);
58+
if (commandService.FindCommand(commandId) == null)
5759
{
58-
menuCommand.Visible = command.IsVisible;
59-
};
60+
var menuCommand = new OleMenuCommand(command.OnExecute, commandId);
6061

61-
command.VisibilityChanged += delegate
62-
{
63-
menuCommand.Visible = command.IsVisible;
64-
};
62+
menuCommand.BeforeQueryStatus += delegate (object sender, EventArgs e)
63+
{
64+
ThreadHelper.JoinableTaskFactory.Run(() =>
65+
{
66+
menuCommand.Visible = command.IsVisible;
67+
return Task.CompletedTask;
68+
});
69+
};
70+
71+
command.VisibilityChanged += delegate
72+
{
73+
ThreadHelper.JoinableTaskFactory.Run(() =>
74+
{
75+
menuCommand.Visible = command.IsVisible;
76+
return Task.CompletedTask;
77+
});
78+
};
6579

66-
commandService.AddCommand(menuCommand);
80+
commandService.AddCommand(menuCommand);
81+
82+
GitTreeFilterOutput.WriteLine($"Command {command.GetType()} with id {rawCommandId} registered");
83+
}
84+
else
85+
{
86+
GitTreeFilterOutput.WriteLine($"Command {command.GetType()} with id {rawCommandId} already registered");
87+
}
6788
}
6889
}

GitTreeFilter/GitTreeFilter.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="Commands\Diffrence\OpenDiffCommandManager.cs" />
6363
<Compile Include="Commands\Diffrence\OpenPhysicalFileDiffCommand.cs" />
6464
<Compile Include="Commands\Diffrence\OpenProjectFileDiffCommand.cs" />
65+
<Compile Include="GitTreeFilterOutput.cs" />
6566
<Compile Include="GitTreeFilterProvider.GitFileFilter.cs" />
6667
<Compile Include="Models\ComparisonConfig.cs" />
6768
<Compile Include="GitTreeFilterErrorPresenter.cs" />

GitTreeFilter/GitTreeFilterOutput.cs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.VisualStudio.Shell;
2+
using Microsoft.VisualStudio.Shell.Interop;
3+
using System;
4+
5+
public static class GitTreeFilterOutput
6+
{
7+
private static IVsOutputWindowPane _outputPane;
8+
9+
public static void Initialize(IServiceProvider serviceProvider)
10+
{
11+
ThreadHelper.ThrowIfNotOnUIThread();
12+
if (_outputPane == null)
13+
{
14+
var outputWindow = serviceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
15+
if (outputWindow != null)
16+
{
17+
Guid customPaneGuid = Guid.NewGuid();
18+
outputWindow.CreatePane(ref customPaneGuid, nameof(GitTreeFilter), 1, 1);
19+
outputWindow.GetPane(ref customPaneGuid, out _outputPane);
20+
}
21+
}
22+
}
23+
24+
public static void WriteLine(string message)
25+
{
26+
ThreadHelper.ThrowIfNotOnUIThread();
27+
28+
if (_outputPane != null)
29+
{
30+
_outputPane.OutputStringThreadSafe(message + Environment.NewLine);
31+
}
32+
}
33+
}

GitTreeFilter/GitTreeFilterService.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public ISessionSettings SessionSettings
7777

7878
public bool IsFilterApplied
7979
{
80-
get => _isFilterApplied;
80+
get => _isFilterApplied; // true
8181
set
8282
{
8383
_isFilterApplied = value;
@@ -119,6 +119,7 @@ public async Task InitializeAsync(CancellationToken cancellationToken)
119119
{
120120
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
121121

122+
GitTreeFilterOutput.Initialize(ServiceProvider.GlobalProvider);
122123
_gitExt = ServiceProvider.GlobalProvider.GetService(typeof(IGitExt)) as IGitExt;
123124
_dte = await _package.GetServiceAsync<DTE>();
124125

@@ -151,6 +152,7 @@ private async Task SetUpAsync()
151152

152153
if (!TryGetRootRepositoryPath(out string repositoryRootPath))
153154
{
155+
GitTreeFilterOutput.WriteLine("Could not identify GIT repository to use, deactivating the plugin for now");
154156
PluginState = PluginLifecycleState.INACTIVE;
155157
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not identify GIT repository to use, deactivating the plugin for now"));
156158
return;
@@ -174,11 +176,10 @@ private async Task SetUpAsync()
174176
LoadSessionSettings();
175177
ItemTagManager.CreateTagTables();
176178

177-
if (PluginState == PluginLifecycleState.LOADING)
178-
{
179-
await CommandRegistrar.InitializeAsync(_package);
180-
}
179+
GitTreeFilterOutput.WriteLine($"Initializing commands");
180+
await CommandRegistrar.InitializeAsync(_package);
181181

182+
GitTreeFilterOutput.WriteLine($"Initialization done");
182183
PluginState = PluginLifecycleState.RUNNING;
183184
}
184185

0 commit comments

Comments
 (0)