Skip to content

Commit c7b9db4

Browse files
committed
Added an "Excel-DNA" submenu under the Extensions menu with Documentation and About items.
1 parent b49b0a6 commit c7b9db4

5 files changed

Lines changed: 123 additions & 38 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace ExcelDNAVSExtension
2+
{
3+
class Commands
4+
{
5+
public Commands(Microsoft.VisualStudio.Shell.Package package)
6+
{
7+
System.IServiceProvider serviceProvider = package as System.IServiceProvider;
8+
mcs = (Microsoft.VisualStudio.Shell.OleMenuCommandService)serviceProvider.GetService(
9+
typeof(System.ComponentModel.Design.IMenuCommandService));
10+
11+
AddCommand(() => System.Diagnostics.Process.Start("https://docs.excel-dna.net"), cmdidDocs);
12+
AddCommand(() => System.Windows.MessageBox.Show("Excel-DNA Developer Tools v1.0.2.", "About", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information), cmdidAbout);
13+
}
14+
15+
private void AddCommand(System.Action command, uint cmdid)
16+
{
17+
mcs.AddCommand(CreateMenuCommand((object sender, System.EventArgs args) =>
18+
{
19+
try
20+
{
21+
command();
22+
}
23+
catch (System.Exception e)
24+
{
25+
ExceptionHandler.ShowException(e);
26+
}
27+
}, cmdid));
28+
}
29+
30+
private System.ComponentModel.Design.MenuCommand CreateMenuCommand(System.EventHandler onClick, uint id)
31+
{
32+
System.ComponentModel.Design.CommandID menuCommandID = new System.ComponentModel.Design.CommandID(CommandSet, (int)id);
33+
return new System.ComponentModel.Design.MenuCommand(onClick, menuCommandID);
34+
}
35+
36+
private Microsoft.VisualStudio.Shell.OleMenuCommandService mcs;
37+
38+
private static readonly System.Guid CommandSet = new System.Guid("a6a2b6bd-05ce-4df3-a1c2-a9fa1685c969");
39+
private const uint cmdidAbout = 0x100;
40+
private const uint cmdidDocs = 0x101;
41+
}
42+
}

ExcelDNAVSExtension/ExcelDNAVSExtension/ExcelDNAVSExtension.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<DefineConstants>DEBUG;TRACE</DefineConstants>
4242
<ErrorReport>prompt</ErrorReport>
4343
<WarningLevel>4</WarningLevel>
44-
<NoWarn>VSTHRD010</NoWarn>
44+
<NoWarn>VSTHRD010,VSSDK006</NoWarn>
4545
</PropertyGroup>
4646
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4747
<DebugType>none</DebugType>
@@ -50,9 +50,10 @@
5050
<DefineConstants>TRACE</DefineConstants>
5151
<ErrorReport>prompt</ErrorReport>
5252
<WarningLevel>4</WarningLevel>
53-
<NoWarn>VSTHRD010</NoWarn>
53+
<NoWarn>VSTHRD010,VSSDK006</NoWarn>
5454
</PropertyGroup>
5555
<ItemGroup>
56+
<Compile Include="Commands.cs" />
5657
<Compile Include="ExceptionHandler.cs" />
5758
<Compile Include="ProjectCreationOptions.cs" />
5859
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -77,6 +78,10 @@
7778
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7879
<IncludeInVSIX>true</IncludeInVSIX>
7980
</Content>
81+
<VSCTCompile Include="VSPackage.vsct">
82+
<ResourceName>Menus.ctmenu</ResourceName>
83+
</VSCTCompile>
84+
<Content Include="Resources\Images.png" />
8085
<Content Include="XmlSchemas\*.*">
8186
<IncludeInVSIX>true</IncludeInVSIX>
8287
</Content>
1.14 KB
Loading

ExcelDNAVSExtension/ExcelDNAVSExtension/VSPackage.cs

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,60 +15,35 @@
1515

1616
namespace ExcelDNAVSExtension
1717
{
18-
/// <summary>
19-
/// This is the class that implements the package exposed by this assembly.
20-
/// </summary>
21-
/// <remarks>
22-
/// <para>
23-
/// The minimum requirement for a class to be considered a valid package for Visual Studio
24-
/// is to implement the IVsPackage interface and register itself with the shell.
25-
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
26-
/// to do it: it derives from the Package class that provides the implementation of the
27-
/// IVsPackage interface and uses the registration attributes defined in the framework to
28-
/// register itself and its components with the shell. These attributes tell the pkgdef creation
29-
/// utility what data to put into .pkgdef file.
30-
/// </para>
31-
/// <para>
32-
/// To get loaded into VS, the package must be referred by &lt;Asset Type="Microsoft.VisualStudio.VsPackage" ...&gt; in .vsixmanifest file.
33-
/// </para>
34-
/// </remarks>
3518
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
3619
[Guid(VSPackage.PackageGuidString)]
3720
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
21+
[ProvideMenuResource("Menus.ctmenu", 1)]
3822
public sealed class VSPackage : AsyncPackage
3923
{
40-
/// <summary>
41-
/// VSPackage GUID string.
42-
/// </summary>
4324
public const string PackageGuidString = "8123a50c-24f3-4eb6-8e12-6e852e023779";
4425

45-
/// <summary>
46-
/// Initializes a new instance of the <see cref="VSPackage"/> class.
47-
/// </summary>
4826
public VSPackage()
4927
{
50-
// Inside this method you can place any initialization code that does not require
51-
// any Visual Studio service because at this point the package object is created but
52-
// not sited yet inside Visual Studio environment. The place to do all the other
53-
// initialization is the Initialize method.
5428
}
5529

5630
#region Package Members
5731

58-
/// <summary>
59-
/// Initialization of the package; this method is called right after the package is sited, so this is the place
60-
/// where you can put all the initialization code that rely on services provided by VisualStudio.
61-
/// </summary>
62-
/// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
63-
/// <param name="progress">A provider for progress updates.</param>
64-
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
6532
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
6633
{
67-
// When initialized asynchronously, the current thread may be a background thread at this point.
68-
// Do any initialization that requires the UI thread after switching to the UI thread.
6934
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
35+
try
36+
{
37+
commands = new Commands(this);
38+
}
39+
catch (System.Exception e)
40+
{
41+
ExceptionHandler.ShowException(e);
42+
}
7043
}
7144

7245
#endregion
46+
47+
private Commands commands;
7348
}
7449
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
4+
<Extern href="stdidcmd.h"/>
5+
<Extern href="vsshlids.h"/>
6+
7+
<Commands package="guidVSPackage">
8+
9+
<Menus>
10+
<Menu guid="guidVSPackageCmdSet" id="TopMenu" priority="0x700" type="Menu">
11+
<Parent guid="guidSHLMainMenu" id="IDG_VS_MM_TOOLSADDINS" />
12+
<Strings>
13+
<CommandName>Excel-DNA</CommandName>
14+
<ButtonText>Excel-DNA</ButtonText>
15+
</Strings>
16+
</Menu>
17+
</Menus>
18+
19+
<Groups>
20+
<Group guid="guidVSPackageCmdSet" id="TopMenuGroup" priority="0x0000">
21+
<Parent guid="guidVSPackageCmdSet" id="TopMenu"/>
22+
</Group>
23+
</Groups>
24+
25+
<Buttons>
26+
27+
<Button guid="guidVSPackageCmdSet" id="cmdidDocs" priority="0x0100" type="Button">
28+
<Parent guid="guidVSPackageCmdSet" id="TopMenuGroup" />
29+
<Strings>
30+
<ButtonText>Documentation</ButtonText>
31+
</Strings>
32+
</Button>
33+
34+
<Button guid="guidVSPackageCmdSet" id="cmdidAbout" priority="0x0110" type="Button">
35+
<Parent guid="guidVSPackageCmdSet" id="TopMenuGroup" />
36+
<Strings>
37+
<ButtonText>About</ButtonText>
38+
</Strings>
39+
</Button>
40+
41+
</Buttons>
42+
43+
<Bitmaps>
44+
<Bitmap guid="guidImages" href="Resources\Images.png" usedList="bmpPic1"/>
45+
</Bitmaps>
46+
47+
</Commands>
48+
49+
<Symbols>
50+
<GuidSymbol name="guidVSPackage" value="{8123a50c-24f3-4eb6-8e12-6e852e023779}" />
51+
52+
<GuidSymbol name="guidVSPackageCmdSet" value="{a6a2b6bd-05ce-4df3-a1c2-a9fa1685c969}">
53+
<IDSymbol name="TopMenu" value="0000" />
54+
<IDSymbol name="TopMenuGroup" value="0010" />
55+
<IDSymbol name="cmdidAbout" value="0x0100" />
56+
<IDSymbol name="cmdidDocs" value="0x0101" />
57+
</GuidSymbol>
58+
59+
<GuidSymbol name="guidImages" value="{b1e53aad-6a3a-4c1e-9b1a-7949f516844d}" >
60+
<IDSymbol name="bmpPic1" value="1" />
61+
</GuidSymbol>
62+
</Symbols>
63+
</CommandTable>

0 commit comments

Comments
 (0)