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


Reply to: Creating a custom toolbar?

That’s what I have been doing but I ran into a slight glitch.  If Xmetal has ever been open before, the first time that my macro creates the toolbar it does not work quite right. The first time I open Xmetal after adding my macro code to a startup file, there are 2 instances of the toolbar when you right click on the menu area as shown in the screenshot. I delete all *.tbr files from my computer after every test, so the duplicates are not leftover from the previous macro run.  Additionally if you are in any DTD specific file the menu is not visible by default. After restarting Xmetal once, the menu is visible in DTD specific documents but there are still 2 items listed when right-clicking. After restarting Xmetal again, it finally only has one new toolbar and it is visible in DTD specific documents.

Here is the code I have in the On_Default_CommandBars_Complete macro:
[code] var cmdBars = Application.CommandBars;
var oldBar = cmdBars.item(“New bar”);
if(oldBar != null) {
var customBar = cmdBars.Add(“New bar”,sqcbPosTop);
customBar.Visible = true;[/code]

I commented out the delete line and just have it return now after reading some of the help files, seeing if that was the issue but it doesn’t seem to be. I need to be able to periodically update toolbar icons and possible add and remove items when I update our customizations.

“Note: Do not use CommandBarControl.Delete or CommandBar.Delete in this event macro. Also, do not create a new toolbar in this event macro.”
(I can’t tell if this is referring to the On_Application_Open macro or the On_Default_CommandBars_Complete macro)
“If you want to make modifications to the menus and toolbars, you can do it here; however, you cannot affect the visibility of toolbars from this event.”

“Do not use this method inside the On_Default_CommandBars_Complete event macro.”

OK…, so when you and the documentation say you can “modify” the menus in On_Default_CommandBars_Complete what exactly can you modify if you are not supposed to call .Delete(), create new toolbars, change visibility, or call .reset() ?????
The programing guide specifically says “Do not create a new toolbar in this event macro” does that mean I can create new buttons under a toolbar (oh wait I can’t remove ones though so anything I add I will never be able to delete…)?
Am I supposed to create the new menu or delete all the items on that toolbar if it exists in in On_Application_Open? Then in On_Default_CommandBars_Complete populate the toolbar or something?

Up until now it has been fine except I recently added a new toolbar for our writers and noticed the weird double behavior on someone’s computer after the customization update.

The macro has to be robust and updatable. Everything up until this point I can push out any customizations and macro file updates relatively easily.  How am I supposed to update custom toolbar customizations if the macros are only supposed to create the toolbar only once? Have my customization script delete every *.tbr file from the system every time there’s an update?