Skip to content

Commit

Permalink
Merge pull request #229 from Checkmarx/feature/elchanan/auto_load_plu…
Browse files Browse the repository at this point in the history
…gin_on_ide_startup

Enable plugin to auto-load on IDE startup (AST-77606)
  • Loading branch information
elchananarb authored Dec 24, 2024
2 parents e3451c4 + 9039eb8 commit b712814
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.VisualStudio.Shell;
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using Task = System.Threading.Tasks.Task;

namespace ast_visual_studio_extension.CxExtension.Commands
Expand All @@ -26,6 +27,7 @@ private CxWindowCommand(AsyncPackage package, OleMenuCommandService commandServi
var menuCommandID = new CommandID(CommandSet, CxWindowCommandId);
var menuItem = new MenuCommand(this.Execute, menuCommandID);
commandService.AddCommand(menuItem);
InitializeInBackground();
}

public static CxWindowCommand Instance
Expand All @@ -41,17 +43,38 @@ public static async Task InitializeAsync(AsyncPackage package)
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new CxWindowCommand(package, commandService);
}

private void Execute(object sender, EventArgs e)
{
_ = this.package.JoinableTaskFactory.RunAsync(async delegate
{
ToolWindowPane window = await this.package.ShowToolWindowAsync(typeof(CxWindow), 0, true, this.package.DisposalToken);
if ((null == window) || (null == window.Frame))
{
throw new NotSupportedException("Cannot create tool window");
}
});
{
ToolWindowPane window = await this.package.ShowToolWindowAsync(typeof(CxWindow), 0, true, this.package.DisposalToken);
if ((null == window) || (null == window.Frame))
{
throw new NotSupportedException("Cannot create tool window");
}
});
}

private void InitializeInBackground()
{
_ = this.package.JoinableTaskFactory.RunAsync(async delegate
{
try
{
// Adds a 5-second delay to allow background processes initialization to complete before proceeding.
await Task.Delay(5000);
// Load the tool window in the background without affecting the UI
ToolWindowPane window = await this.package.FindToolWindowAsync(typeof(CxWindow), 0, create: true, this.package.DisposalToken);
if ((null == window) || (null == window.Frame))
{
throw new NotSupportedException("Cannot create tool window");
}
}
catch (Exception ex)
{
Debug.WriteLine($"Failed to load window in the background: {ex}");
}
});
}
}
}
5 changes: 3 additions & 2 deletions ast-visual-studio-extension/CxExtension/CxWindowPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ namespace ast_visual_studio_extension.CxExtension
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration("#14110", "#14112", "1.0", IconResourceID = 14400)] // Info on this package for Help/About
[ProvideMenuResource("Menus1.ctmenu", 1)]
[ProvideAutoLoad(PackageGuidString, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideToolWindow(typeof(CxWindow), Style = VsDockStyle.Tabbed, Orientation = ToolWindowOrientation.Right, Window = EnvDTE.Constants.vsWindowKindOutput)]
[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideToolWindow(typeof(CxWindow),Style = VsDockStyle.Tabbed,Orientation = ToolWindowOrientation.Right,Window = EnvDTE.Constants.vsWindowKindOutput,Transient = false)]
[Guid(PackageGuidString)]
public sealed class CxWindowPackage : AsyncPackage
{
Expand Down

0 comments on commit b712814

Please sign in to comment.