Home Forums DITA and XMetaL Discussion Creating a custom toolbar? Reply To: Creating a custom toolbar?

Derek Read

Reply to: Creating a custom toolbar?

Here's some code I have from my own samples. There is fancier code in the DocBook sample and various other places in the XMetaL MCR files (search for On_Default_CommandBars_Complete) but our developers tend to use eval() and JScript prototypes so they can be difficult to follow (one reason they use prototypes is that allows others to override the code more easily so it comes in handy for patching macros).

Let me know if the following doesn't work for you. You should end up with a single toolbar called “My Custom Toolbar” that has two buttons, neither of which will be enabled because the OnAction property needs to point to an existing macro.

[code]
//check if toolbar already exists
var exists = false;
for (i=1;i if(Application.CommandBars.item(i).name == “My Custom Toolbar”) exists = true;
} //if the toolbar doesn't exist then create it
if (!exists) {
var myToolbar = Application.CommandBars.Add(“My Custom Toolbar”);
//add a button to the toolbar
var newButton             = myToolbar.Controls.Add(sqcbcTypeButton);
newButton.TooltipText     = “This text will appear in a tooltip when someone hovers over the button.”;
newButton.OnAction        = “Name of Macro to Run”;
newButton.DescriptionText = “This is my long description. It will appear in the status bar.”;
//find an icon to reference
var icon = Application.MakeFaceId(“Structure (Custom)”,4,1);
//assign the icon to the button
newButton.FaceId          = icon; //add a second button to the toolbar
var newButton             = myToolbar.Controls.Add(sqcbcTypeButton);
newButton.TooltipText     = “This text will appear in a tooltip when someone hovers over the button.”;
newButton.OnAction        = “Name of Macro to Run”;
newButton.DescriptionText = “This is my long description. It will appear in the status bar.”;
//find an icon to reference
var icon = Application.MakeFaceId(“Structure (Custom)”,4,2);
//assign the icon to the button
newButton.FaceId          = icon;
//…etc…
}
]]>
[/code]

To answer your question about deployment, if you provide your users with a new version of the toolbar (anything in the second section) your users can reset XMetaL to the default workspace by holding the Ctrl key down. That will blow away any custom toolbars added like this and then the code will run again and add your new stuff.

Reply

Products
Downloads
Support