Skip to content

Commit c29b807

Browse files
committed
property, resource, and config files
1 parent 1ae20c2 commit c29b807

File tree

6 files changed

+273
-0
lines changed

6 files changed

+273
-0
lines changed

Command1.cs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System;
2+
using System.ComponentModel.Design;
3+
using System.Globalization;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Microsoft.VisualStudio.Shell;
7+
using Microsoft.VisualStudio.Shell.Interop;
8+
using Task = System.Threading.Tasks.Task;
9+
10+
using System.Collections.Generic;
11+
using Microsoft.VisualStudio.Settings;
12+
using Microsoft.VisualStudio.Shell.Settings;
13+
using System.Windows.Forms;
14+
15+
// see https://docs.microsoft.com/en-us/visualstudio/extensibility/using-the-settings-store?view=vs-2019
16+
17+
namespace GcodeLanguage
18+
{
19+
/// <summary>
20+
/// Command handler
21+
/// </summary>
22+
internal sealed class Command1
23+
{
24+
/// <summary>
25+
/// Command ID.
26+
/// </summary>
27+
public const int CommandId = 0x0100;
28+
29+
/// <summary>
30+
/// Command menu group (command set GUID).
31+
/// </summary>
32+
public static readonly Guid CommandSet = new Guid("c901338f-9e37-4818-9082-d02c3326c279");
33+
34+
/// <summary>
35+
/// VS Package that provides this command, not null.
36+
/// </summary>
37+
private readonly AsyncPackage package;
38+
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="Command1"/> class.
41+
/// Adds our command handlers for menu (commands must exist in the command table file)
42+
/// </summary>
43+
/// <param name="package">Owner package, not null.</param>
44+
/// <param name="commandService">Command service to add command to, not null.</param>
45+
private Command1(AsyncPackage package, OleMenuCommandService commandService)
46+
{
47+
this.package = package ?? throw new ArgumentNullException(nameof(package));
48+
commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
49+
50+
var menuCommandID = new CommandID(CommandSet, CommandId);
51+
var menuItem = new MenuCommand(this.Execute, menuCommandID);
52+
commandService.AddCommand(menuItem);
53+
}
54+
55+
/// <summary>
56+
/// Gets the instance of the command.
57+
/// </summary>
58+
public static Command1 Instance
59+
{
60+
get;
61+
private set;
62+
}
63+
64+
/// <summary>
65+
/// Gets the service provider from the owner package.
66+
/// </summary>
67+
private Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider
68+
{
69+
get
70+
{
71+
return this.package;
72+
}
73+
}
74+
75+
/// <summary>
76+
/// Initializes the singleton instance of the command.
77+
/// </summary>
78+
/// <param name="package">Owner package, not null.</param>
79+
public static async Task InitializeAsync(AsyncPackage package)
80+
{
81+
// Switch to the main thread - the call to AddCommand in Command1's constructor requires
82+
// the UI thread.
83+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
84+
85+
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
86+
Instance = new Command1(package, commandService);
87+
}
88+
89+
/// <summary>
90+
/// This function is the callback used to execute the command when the menu item is clicked.
91+
/// See the constructor to see how the menu item is associated with this function using
92+
/// OleMenuCommandService service and MenuCommand class.
93+
/// </summary>
94+
/// <param name="sender">Event sender.</param>
95+
/// <param name="e">Event args.</param>
96+
private void Execute(object sender, EventArgs e)
97+
{
98+
ThreadHelper.ThrowIfNotOnUIThread();
99+
string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);
100+
string title = "Command1";
101+
102+
// Show a message box to prove we were here
103+
VsShellUtilities.ShowMessageBox(
104+
this.package,
105+
message,
106+
title,
107+
OLEMSGICON.OLEMSGICON_INFO,
108+
OLEMSGBUTTON.OLEMSGBUTTON_OK,
109+
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
110+
}
111+
}
112+
}

GcodeLanguagePackage.vsct

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
<!-- This is the file that defines the actual layout and type of the commands.
5+
It is divided in different sections (e.g. command definition, command
6+
placement, ...), with each defining a specific set of properties.
7+
See the comment before each section for more details about how to
8+
use it. -->
9+
10+
<!-- The VSCT compiler (the tool that translates this file into the binary
11+
format that VisualStudio will consume) has the ability to run a preprocessor
12+
on the vsct file; this preprocessor is (usually) the C++ preprocessor, so
13+
it is possible to define includes and macros with the same syntax used
14+
in C++ files. Using this ability of the compiler here, we include some files
15+
defining some of the constants that we will use inside the file. -->
16+
17+
<!--This is the file that defines the IDs for all the commands exposed by VisualStudio. -->
18+
<Extern href="stdidcmd.h"/>
19+
20+
<!--This header contains the command ids for the menus provided by the shell. -->
21+
<Extern href="vsshlids.h"/>
22+
23+
<!--The Commands section is where commands, menus, and menu groups are defined.
24+
This section uses a Guid to identify the package that provides the command defined inside it. -->
25+
<Commands package="guidGcodeLanguagePackage">
26+
<!-- Inside this section we have different sub-sections: one for the menus, another
27+
for the menu groups, one for the buttons (the actual commands), one for the combos
28+
and the last one for the bitmaps used. Each element is identified by a command id that
29+
is a unique pair of guid and numeric identifier; the guid part of the identifier is usually
30+
called "command set" and is used to group different command inside a logically related
31+
group; your package should define its own command set in order to avoid collisions
32+
with command ids defined by other packages. -->
33+
34+
<!-- In this section you can define new menu groups. A menu group is a container for
35+
other menus or buttons (commands); from a visual point of view you can see the
36+
group as the part of a menu contained between two lines. The parent of a group
37+
must be a menu. -->
38+
<Groups>
39+
<Group guid="guidGcodeLanguagePackageCmdSet" id="MyMenuGroup" priority="0x0600">
40+
<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
41+
</Group>
42+
</Groups>
43+
44+
<!--Buttons section. -->
45+
<!--This section defines the elements the user can interact with, like a menu command or a button
46+
or combo box in a toolbar. -->
47+
<Buttons>
48+
<!--To define a menu group you have to specify its ID, the parent menu and its display priority.
49+
The command is visible and enabled by default. If you need to change the visibility, status, etc, you can use
50+
the CommandFlag node.
51+
You can add more than one CommandFlag node e.g.:
52+
<CommandFlag>DefaultInvisible</CommandFlag>
53+
<CommandFlag>DynamicVisibility</CommandFlag>
54+
If you do not want an image next to your command, remove the Icon node /> -->
55+
<Button guid="guidGcodeLanguagePackageCmdSet" id="Command1Id" priority="0x0100" type="Button">
56+
<Parent guid="guidGcodeLanguagePackageCmdSet" id="MyMenuGroup" />
57+
<Icon guid="guidImages" id="bmpPic1" />
58+
<Strings>
59+
<ButtonText>Invoke Command1</ButtonText>
60+
</Strings>
61+
</Button>
62+
</Buttons>
63+
64+
<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
65+
<Bitmaps>
66+
<!-- The bitmap id is defined in a way that is a little bit different from the others:
67+
the declaration starts with a guid for the bitmap strip, then there is the resource id of the
68+
bitmap strip containing the bitmaps and then there are the numeric ids of the elements used
69+
inside a button definition. An important aspect of this declaration is that the element id
70+
must be the actual index (1-based) of the bitmap inside the bitmap strip. -->
71+
<Bitmap guid="guidImages" href="Resources\Command1.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
72+
</Bitmaps>
73+
</Commands>
74+
75+
<Symbols>
76+
<!-- This is the package guid. -->
77+
<GuidSymbol name="guidGcodeLanguagePackage" value="{c1f3890c-b80a-4b60-bc5e-ece8a74ac1fa}" />
78+
79+
<!-- This is the guid used to group the menu commands together -->
80+
<GuidSymbol name="guidGcodeLanguagePackageCmdSet" value="{c901338f-9e37-4818-9082-d02c3326c279}">
81+
<IDSymbol name="MyMenuGroup" value="0x1020" />
82+
<IDSymbol name="Command1Id" value="0x0100" />
83+
</GuidSymbol>
84+
85+
<GuidSymbol name="guidImages" value="{c07cb23f-8250-4eaf-b45a-a6b8aad67d2a}" >
86+
<IDSymbol name="bmpPic1" value="1" />
87+
<IDSymbol name="bmpPic2" value="2" />
88+
<IDSymbol name="bmpPicSearch" value="3" />
89+
<IDSymbol name="bmpPicX" value="4" />
90+
<IDSymbol name="bmpPicArrows" value="5" />
91+
<IDSymbol name="bmpPicStrikethrough" value="6" />
92+
</GuidSymbol>
93+
</Symbols>
94+
</CommandTable>

Properties/Settings.Designer.cs

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Properties/Settings.settings

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="GcodeLanguage.Properties" GeneratedClassName="Settings">
3+
<Profiles />
4+
<Settings>
5+
<Setting Name="MyColor" Type="System.String" Scope="Application">
6+
<Value Profile="(Default)">test</Value>
7+
</Setting>
8+
</Settings>
9+
</SettingsFile>

Resources/Command1.png

1.14 KB
Loading

app.config

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<configSections>
4+
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5+
<section name="GcodeLanguage.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6+
</sectionGroup>
7+
</configSections>
8+
<runtime>
9+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
10+
<dependentAssembly>
11+
<assemblyIdentity name="Microsoft.VisualStudio.Threading" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
12+
<bindingRedirect oldVersion="0.0.0.0-15.0.0.0" newVersion="15.0.0.0" />
13+
</dependentAssembly>
14+
</assemblyBinding>
15+
</runtime>
16+
<applicationSettings>
17+
<GcodeLanguage.Properties.Settings>
18+
<setting name="MyColor" serializeAs="String">
19+
<value>test</value>
20+
</setting>
21+
</GcodeLanguage.Properties.Settings>
22+
</applicationSettings>
23+
</configuration>

0 commit comments

Comments
 (0)