Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
Had to make the package async to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
marklam committed Jun 5, 2018
1 parent 491e9a5 commit 1ca8796
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ pip-log.txt
# Nuget packages
/packages
/paket-files
/ImageCommentsPackage/Output/ImageComments.vsix
32 changes: 32 additions & 0 deletions ImageCommentsPackage/ImageCommentsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace LM.ImageComments.Package
{
using System.ComponentModel.Design;
using LM.ImageComments.EditorComponent;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;

internal sealed class ImageCommentsCommand
{
public static async Task InitializeAsync(AsyncPackage package)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

var mcs = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;

if (null != mcs)
{
var menuCommandID = new CommandID(GuidList.guidImageCommentsPackageCmdSet, (int)PkgCmdIDList.cmdidToggleImageComments);

var menuItem = new MenuCommand((s, e) => Execute(package), menuCommandID);

mcs.AddCommand(menuItem);
}
}

private static void Execute(AsyncPackage package)
{
ThreadHelper.ThrowIfNotOnUIThread();
ImageAdornmentManager.ToggleEnabled();
}
}
}
34 changes: 10 additions & 24 deletions ImageCommentsPackage/ImageCommentsPackage.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
namespace LM.ImageComments.Package
{
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using LM.ImageComments.EditorComponent;
using System.Threading;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;

/// <summary>
/// Package containing image comment command
/// </summary>
[PackageRegistration(UseManagedResourcesOnly = true)]
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(GuidList.guidImageCommentsPackagePkgString)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
public sealed class ImageCommentsPackage : Microsoft.VisualStudio.Shell.Package
public sealed class ImageCommentsPackage : AsyncPackage
{
#region Package Members

/// <summary>
/// Creates and registers image comment enable/disable toggle command
/// </summary>
protected override void Initialize()
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
ThreadHelper.ThrowIfNotOnUIThread();

Trace.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();

OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if ( null != mcs )
{
CommandID menuCommandID = new CommandID(GuidList.guidImageCommentsPackageCmdSet, (int)PkgCmdIDList.cmdidToggleImageComments);
MenuCommand menuItem = new MenuCommand(
(sender, args) => { ImageAdornmentManager.ToggleEnabled(); },
menuCommandID);
mcs.AddCommand( menuItem );
}
Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
await ImageCommentsCommand.InitializeAsync(this);
}
#endregion
}
}
1 change: 1 addition & 0 deletions ImageCommentsPackage/ImageCommentsPackage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<ItemGroup>
<Compile Include="Guids.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ImageCommentsCommand.cs" />
<Compile Include="ImageCommentsPackage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PkgCmdID.cs" />
Expand Down

0 comments on commit 1ca8796

Please sign in to comment.