added some development tools
[windows-sources.git] / developer / VSSDK / Samples / Menu_And_Commands / C# / DynamicTextCommand.cs
blobd29e0a60355206e237149208c5bddbbbb4542501
1 /***************************************************************************
3 Copyright (c) Microsoft Corporation. All rights reserved.
4 THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
5 ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
6 IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
7 PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
9 ***************************************************************************/
11 using Microsoft.VisualStudio.Shell;
12 using System;
13 using System.ComponentModel.Design;
14 using System.Globalization;
16 namespace Microsoft.Samples.VisualStudio.MenuCommands
18 /// <summary>
19 /// This class implements a very specific type of command: this command will count the
20 /// number of times the user has clicked on it and will change its text to show this count.
21 /// </summary>
22 internal class DynamicTextCommand : OleMenuCommand
24 // Counter of the clicks.
25 private int clickCount;
27 /// <summary>
28 /// This is the function that is called when the user clicks on the menu command.
29 /// It will check that the selected object is actually an instance of this class and
30 /// increment its click counter.
31 /// </summary>
32 private static void ClickCallback(object sender, EventArgs args)
34 DynamicTextCommand cmd = sender as DynamicTextCommand;
35 if (null != cmd)
37 cmd.clickCount++;
41 /// <summary>
42 /// Creates a new DynamicTextCommand object with a specific CommandID and base text.
43 /// </summary>
44 public DynamicTextCommand(CommandID id, string text) :
45 base(new EventHandler(ClickCallback), id, text)
49 /// <summary>
50 /// If a command is defined with the TEXTCHANGES flag in the VSCT file and this package is
51 /// loaded, then Visual Studio will call this property to get the text to display.
52 /// </summary>
53 public override string Text
55 get
57 return string.Format(CultureInfo.CurrentCulture, VSPackage.ResourceManager.GetString("DynamicTextFormat"), base.Text, clickCount);
59 set { base.Text = value; }