Views
3 years ago

DNDJ 3-6 June.indd - sys-con.com's archive of magazines - SYS ...

DNDJ 3-6 June.indd - sys-con.com's archive of magazines - SYS ...

Visual Studio

Visual Studio ExtensibilityPro pertyValue(Name)lvwTasksAnchorTop, Bottom, Left, RightCheckboxesTrueColumns(Name): chDescription;Text: “Description”(Name): chPriority;Text: “Priority”FullRowSelectGroupsTrueHeader Name: “User Tasks”f 8 Figure 8: Typing in the TextBox f 9Figure 9: The text is added to theListViewShowGroupsViewt3TrueDetailsTable 3: Properties to set on the ListViewaccomplish the same behavior. Add anEvent Handler to txtNewTask for theKeyDown Event, as shown in Listing 1.Let’s see how this works at runtime.Run the project and open yourtool window. Add some text to theTextbox and press Enter. Your task willbe added to your new task list, as isshown in Figures 8 and 9.4Adding a ToolbarNext, we’ll integrate a standardVisual Studio Toolbar into our toolwindow. If you look around at our toolwindows you’ll see that quite a few ofthem use Toolbars (Solution Explorer,Document Outline, Class View, Properties,and so forth). There are a few commandsthat would be handy to have ona toolbar, such as an Add Task button.There are several steps involvedin creating a Visual Studio toolbar,but it’s not difficult. The basic processworks like this: your tool window hasan exposed Toolbar property thataccepts a CommandID object. TheCommandID object uniquely representsyour Toolbar through a Guid/intpair. The Guid identifies your Package’sset of commands, and the int identifiesa specific command that can bind to amenu item or a toolbar button.The Visual Studio Command modelis rich and powerful enough that youcan create a set of commands and thenadd then to virtually any exposed Menustructure, whether that happens to bein the main Menu Bar, a toolbar in theIDE, or a toolbar located on a specifictool window. We use Command TableCompiler (CTC) files to control thisinteraction.To get started, open PkgCmd.ctc.Look for the section marked “CMDS_SECTION.” This is where we’ll add newCommands to Visual Studio for use inour Package. For our purposes, thereare three pieces of data that we’ll haveto specify right now: a new Menu, anew Menu Group, and a new Button.The relevant portions of PkgCmd.ctcare reproduced in Listing 2.4CTC Menu Section• Menu uniquely identifies our newmenu. This is the same data we’llfeed to our Tool Window’s Toolbarproperty later on.• Relative to Group specifies whatgroup this menu will be placed on.For example, if you wanted to createa submenu on an existing menu,you’d place the existing menu’sidentifier here. To see this in concreteterms look at how the TasklistSample command is added to theView menu.• Priority is quite important. Youshould only use the top two numberswhen defining the priority for acommand, group, or menu. This isrequired by the shell to deal with themerging of items. This parameterdetermines where the item is tobe placed in the group specified inparameter 2, 0x0000 being the highest,and 0xFF00 being the lowest.• Menu Type specifies what type ofmenu you’re creating. This is howyou specify whether you’re creatingcontext menus, tool bars, and soforth.• Text is the textual name of the menuif it were to appear as an item somewhere,either in the Tools.Customizedialog or on the menu itself.4CTC Menu Group Section• New Group defines the group youwant to create. This allows you toplace logically related commandstogether. For example: Cut, Copy,and Paste commands would all beplaced in a group together.• Parent Group defines the parentmenu the group will be placed on.• Priority defines the priority of thegroup in the specified parent menu.4CTC Button Section• Command uniquely identifies thenew command you’re creating.• Parent Group species the Primarygroup that this command belongsto. Every command MUST belongto a primary group. This is necessaryfor both Keyboard and ToolbarCustomization modes. The commandwill show up in its primarylocation when the end user looks ineither one of these dialogs.• Priority defines the priority of thecommand in the specified group.• Image defines the picture associatedwith this command. If you don’twant an image associated with thisbutton, pass in the value guidOfficeIcon:msotcidNoIcon.• Button Type determines thetype of button we’re defininghere. This could be BUTTON orSPLITDROPDOWN, for example.• Visibility specifies how the commandis shown or hidden. Leavingthis blank means the command willalways be visible and enabled.• Text is the text that will show upas the button text itself, or as thebutton’s tool tip.22June 2005 • dotnetdevelopersjournal.com

f 10f 11Figure 10: Adding aWindows FormFigure 11: Add Task Dialog UI4Defining Menus, Groups,and CommandsIf you try compiling right now,you’ll receive a number of pithyerror messages from the CTC compiler.We need to define the newMenu, Group, and Button that wehave created.We’ll start by adding these tothe Native project. Open PkgCmd-ID.h and add the following#defines:#define ToolbarMenu 0x1000#define ToolbarMenuGroup 0x1100#define cmdidAddTask 0x110Next, we need to add these valuesto the Managed project. OpenPkgCmdID.cs and add the followingvalues:public const int cmdidAddTask =0x110;public const int ToolbarMenu =0x1000;public const int ToolbarMenuGroup= 0x1100;4Detailed Task Entry UINow that we have a functionalToolbar with a button in our toolwindow, let’s make it do somethinguseful. What we’re going to do is adda Windows Form to our Package thatwill be displayed upon clicking theAdd Task button in our tool bar.First, add a new Windows Formnamed AddTaskDialog.cs to your C#project (see Figure 10).Add a label with the Text property“&Description:” and make sure you getthe ampersand added. The ampersandwill give the label a mnemonic, whichallows your users to select the nextcontrol in the tab order by pressingAlt+D, in this case. Now, add a multilineTextBox named txtDescription.Drag another label onto the Formand name it “&Priority:” which resultsin a mnemonic invokable through thekey combination Alt+P. Next, add acombo box named cmbPriority withthe following Items:• High• Medium• Lowf 12f 13Figure 12: Setting the tab orderFigure 13: Tasklist sampleLast, but certainly not least, weneed to tell our tool window aboutthe new Toolbar we have created.Open TasklistToolwindow.cs andadd the following code to theconstructor:this.ToolBar = new System.ComponentModel.Design.CommandID(GuidList.guidTasklist_SampleCmdSet,PkgCmdIDList.ToolbarMenu);Drag two buttons onto the Formand rename them OK and Cancel.Use the Windows Forms DesignerSnaplines feature to position them atthe bottom-right corner of the dialog.Cancel goes on the far right and OK sitsat its left. Set their name properties tobe btnOK and btnCancel, respectively.Now we’re going to make the dialogconsistent with the Visual StudioUI Guidelines. If you’re interested inlearning more about creating a VisualStudio consistent user experiencerefer, to the document located in C:\Program Files\VSIP 8.0\UI Guidelines.Your Form should now resembleFigure 11. See Table 4 for the list ofproperties and associated values to seton your Form.We have one step left in our UIlayout. Go to the View menu and selectthe Tab Order menu item. Your cursorwill change into a crosshair and everycontrol will have a number superimposedon top of it. Click the controls inthe following order:1. “Description” Label2. Textbox3. “Priority” Label4. Combo Box5. OK Button6. Cancel Buttondotnetdevelopersjournal.com • June 200523

DNDJ 6-3 web.indd - sys-con.com's archive of magazines - SYS ...
DNDJ 6-3WEB.indd - sys-con.com's archive of magazines - SYS ...
DNDJ 3-11 Nov.indd - sys-con.com's archive of magazines - SYS ...
DNDJ 6-4 web.indd - sys-con.com's archive of magazines - SYS ...
DNDJ February 3-2.indd - sys-con.com's archive of magazines ...
DNDJ 4-9.indd - sys-con.com's archive of magazines - SYS-CON ...
DNDJ 3-7 July.indd - sys-con.com's archive of magazines - SYS ...
JAVA Vol 3 Issue4 - sys-con.com's archive of magazines
DNDJ 4-8.indd - sys-con.com's archive of magazines - SYS-CON ...
JDJ 10-10.indd - sys-con.com's archive of magazines - SYS-CON ...
LWM 3-12.indd - sys-con.com's archive of magazines - SYS-CON ...
issue 6 - sys-con.com's archive of magazines - SYS-CON Media
in PowerBuilder - sys-con.com's archive of magazines - SYS-CON ...
JDJ 10-12 Dec.indd - sys-con.com's archive of magazines
LinuxWorld.com - sys-con.com's archive of magazines - SYS-CON ...
JDJ 12-1 Jan.indd - sys-con.com's archive of magazines - SYS-CON ...
Conclusion - sys-con.com's archive of magazines
WebSphere vs WebLogic: - sys-con.com's archive of magazines ...
jdjedge conference & expo - sys-con.com's archive of magazines ...
DNDJ 2-8.qxd - sys-con.com's archive of magazines - SYS-CON ...
JDJ 10-6.indd - sys-con.com's archive of magazines - SYS-CON Media
issue 10 - sys-con.com's archive of magazines - SYS-CON Media
MX - sys-con.com's archive of magazines - SYS-CON Media
!"0&$+ ,!" - sys-con.com's archive of magazines - SYS-CON Media
issue 9 - sys-con.com's archive of magazines - SYS-CON Media
SCOTT McNEALY - sys-con.com's archive of magazines - SYS-CON ...
Web Services Edge 2003 - sys-con.com's archive of magazines ...
Figure 1 - sys-con.com's archive of magazines - SYS-CON Media
Binary Data, ColdFusion & Flex - sys-con.com's archive of ...
CFDJ 7-10.indd - sys-con.com's archive of magazines - SYS-CON ...