Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing buttons #62

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions GitTreeFilter/Commands/CommandRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ public static async Task InitializeAsync(IGitFiltersPackage package)
try
{
await RegisterAsync(package, commandService);
GitTreeFilterOutput.WriteLine($"Initialized all commands");
}
catch (Exception ex)
{
GitTreeFilterOutput.WriteLine($"Failed to register commands: {ex}");
ActivityLog.LogError(nameof(CommandRegistrar), $"Failed to register commands - {ex}");
throw ex;
}
Expand All @@ -50,19 +52,38 @@ private static async Task RegisterAsync(IGitFiltersPackage package, IMenuCommand

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

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

command.VisibilityChanged += delegate
{
menuCommand.Visible = command.IsVisible;
};
menuCommand.BeforeQueryStatus += delegate (object sender, EventArgs e)
{
ThreadHelper.JoinableTaskFactory.Run(() =>
{
menuCommand.Visible = command.IsVisible;
return Task.CompletedTask;
});
};

command.VisibilityChanged += delegate
{
ThreadHelper.JoinableTaskFactory.Run(() =>
{
menuCommand.Visible = command.IsVisible;
return Task.CompletedTask;
});
};

commandService.AddCommand(menuCommand);
commandService.AddCommand(menuCommand);

GitTreeFilterOutput.WriteLine($"Command {command.GetType()} with id {rawCommandId} registered");
}
else
{
GitTreeFilterOutput.WriteLine($"Command {command.GetType()} with id {rawCommandId} already registered");
}
}
}
1 change: 1 addition & 0 deletions GitTreeFilter/GitTreeFilter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="Commands\Diffrence\OpenDiffCommandManager.cs" />
<Compile Include="Commands\Diffrence\OpenPhysicalFileDiffCommand.cs" />
<Compile Include="Commands\Diffrence\OpenProjectFileDiffCommand.cs" />
<Compile Include="GitTreeFilterOutput.cs" />
<Compile Include="GitTreeFilterProvider.GitFileFilter.cs" />
<Compile Include="Models\ComparisonConfig.cs" />
<Compile Include="GitTreeFilterErrorPresenter.cs" />
Expand Down
33 changes: 33 additions & 0 deletions GitTreeFilter/GitTreeFilterOutput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;

public static class GitTreeFilterOutput
{
private static IVsOutputWindowPane _outputPane;

public static void Initialize(IServiceProvider serviceProvider)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (_outputPane == null)
{
var outputWindow = serviceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
if (outputWindow != null)
{
Guid customPaneGuid = Guid.NewGuid();
outputWindow.CreatePane(ref customPaneGuid, nameof(GitTreeFilter), 1, 1);
outputWindow.GetPane(ref customPaneGuid, out _outputPane);
}
}
}

public static void WriteLine(string message)
{
ThreadHelper.ThrowIfNotOnUIThread();

if (_outputPane != null)
{
_outputPane.OutputStringThreadSafe(message + Environment.NewLine);
}
}
}
11 changes: 6 additions & 5 deletions GitTreeFilter/GitTreeFilterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ISessionSettings SessionSettings

public bool IsFilterApplied
{
get => _isFilterApplied;
get => _isFilterApplied; // true
set
{
_isFilterApplied = value;
Expand Down Expand Up @@ -119,6 +119,7 @@ public async Task InitializeAsync(CancellationToken cancellationToken)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

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

Expand Down Expand Up @@ -151,6 +152,7 @@ private async Task SetUpAsync()

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

if (PluginState == PluginLifecycleState.LOADING)
{
await CommandRegistrar.InitializeAsync(_package);
}
GitTreeFilterOutput.WriteLine($"Initializing commands");
await CommandRegistrar.InitializeAsync(_package);

GitTreeFilterOutput.WriteLine($"Initialization done");
PluginState = PluginLifecycleState.RUNNING;
}

Expand Down
Loading