31.5. Adding a New Group

In this next example, you'll see how to decide where to locate a new, custom element on the Ribbon, and also where to find the correct control identifier (idMso attribute) for built-in dialog boxes, commands, and controls.

31.5.1. Limitations to Group Customizing

You'll find a few limitations when customizing groups on the Ribbon.

Although you can hide a built-in group, you can't modify a group's options. In other words, in the following example you will add Word's Next Window command to the Ribbon. Obviously, this should go in the Window group of the View tab. However, you can't add options to built-in groups. So we'll have to devote a whole new group of our own to the Next Window command.

Also keep in mind that you cannot remove one of the existing buttons in a built-in group. You could, of course, hide the entire group, and then replace it by adding a new group of your own — reproducing some or all of Microsoft's original buttons on the group and adding some new ones of your own. But you should avoid this approach because lots of study has gone into these groupings and most people will find them well organized if not totally intuitive.

Of course if you're just customizing the Ribbon for yourself and your coworkers won't use it, you can more freely rearrange things.

Another limitation is that you can't rearrange the order of groups (or of the tabs, for that matter). But if you create a new group of your own, you can specify its position on the Ribbon, as you'll see in the next example.

I frequently like to cycle through open Word documents, and that requires the Next Window feature. The Word Ribbon displays a Switch Windows dropdown list, but I don't want to choose from a list; I want to just see each open document in turn (like the way you see each open application by pressing Alt+Tab).

The Next Window command is listed in the Commands Not in the Ribbon list in the Word Options dialog box. Normally, you want to avoid filling up the Ribbon with new groups because the Ribbon's built-in buttons will not all be visible in order to make room for your custom groups. This can force the user to have to click the Ribbon to reveal what is perhaps a favorite, frequently used, button. But in Word's View tab there's plenty of room to add a new group.

A good place for our new tab, which we will call Shuffle, is just to the right of the built-in Window group. This will leave the Macros group on the far right, as it is in the default Ribbon arrangement.

To create a new group (called Shuffle) and a new button (called Next Window) in that group, follow the steps in the first example in this chapter. But replace the XML code in step 9 with this XML code:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
        <ribbon>
                <tabs>
                        <tab idMso="TabView">
                                <group id="CustomViewsGroup"  label="Next Window"
      insertAfterMso="GroupWindow">
                                        <labelControl id="null"/>
                                        <button  idMso="WindowNext"/>
                                </group>
                        </tab>
                </tabs>
        </ribbon>
</customUI>

There are several things to notice in this code. Each element in the Ribbon (the group, label, and button) is given an identifier, an id — a unique string. And there are two types of IDs: the idMso and the plain id. An idMso refers to a built-in Microsoft command, control, or dialog box (such as the Next Window command or a font dialog box). A plain id refers to a customized element you are adding to the Ribbon: a customized group, a new tab, a button that triggers one of your macros, and so on.

Note that I added a button control to the Ribbon (there are other controls you can place on the Ribbon, such as a combo box, as you'll see in another example shortly).

The code in this example illustrates how to use the XML element id:

group id="CustomViewsGroup"

and

labelControl id="null"

The id name that you give to these objects (such as CustomViewsGroup) is not displayed; it's for internal code purposes only. So name them as you wish.

Note that I added a Label control but didn't provide any text caption (I included no Label attribute). Used this way, a Label control acts as a spacer, pushing the Next Window button to the middle of the group area. Without it, the button would be displayed at the top of the Ribbon. Add two of these captionless Label spacer controls if you want to push the button to the bottom of the Ribbon.

In this code, the View tab is specified as the tab we're going to use (<tab idMso="TabView">). The caption that will be displayed on the Ribbon to describe our new group is Next Window, thanks to this code: label="Next Window". The position on the Ribbon is specified as being to the right of the built-in Window group: insertAfterMso="GroupWindow">.

31.5.2. Two Ways to Find the Correct IDMSO

But, most important, how did I know that the proper Microsoft name for this Next Window command is WindowNext? If you look up the command in the Choose Commands From dropdown list (Commands Not in the Ribbon) in the Word Options dialog box, it is displayed as Next Window. But if you use Next Window in the code for the idMso (Microsoft built-in command ID), nothing will be displayed on the ribbon because Next Window is not the correct internal ID. This won't work:

<button idMso="Next Window"/>

You must use:

<button idMso=" WindowNext"/>

A quick way to identify the correct internal Microsoft ID (idMso) for any control or command is to pause your mouse pointer on top of the command in the Choose Commands From dropdown list, as shown in Figure 31-2. The control name appears in parentheses at the far right of the tooltip that is displayed when you hover your mouse pointer over any command in the list (see Figure 31.2).

If you prefer, you can download a more detailed list of the commands and controls to use with the idMso attribute. You can download lists of all the built-in Office 2007 controls — such as the font dialog box or the clipboard task pane (ShowClipboard) — from this web page:

http://www.microsoft.com/downloads/details.aspx?familyid=4329d9e9-4d11-46a5-898d-23e4f331e9ae&displaylang=en#filelist

Figure 31.2. Hover your mouse pointer over any command to see the correct ID to use in your XML code. In this example, you can see that the Next Window command has an ID of WindowNext.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.108.150