General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › XMetal Menu Problem
-
Fendor May 5, 2009 at 11:32 am
XMetal Menu Problem
May 5, 2009 at 11:32 amParticipants 5Replies 6Last Activity 13 years, 10 months agoI am creating a custom menu for XMetal.
Duiring the runtime I have to change the menu content, i.e. rename a few menu items.
The renaming works well when no document is loaded.
If I rename the menu items while any document is open, closing this document restores initial menu look which was before the document was opened.
Below is the code extract for renaming the menu items.
Please help to learn how do I change menu while a document is loaded so that it remains changed after the document has been closed.[code]
var Bars = Application.CommandBars;
var menuBar = Bars.item(“Menu bar”);
var menuBarCtrls = menuBar.Controls;
var fileMenu = menuBarCtrls.item(“MyMenu”); if (fileMenu != null)
{
var newHeaderItem = menuBarCtrls.item(“MyMenu”);
if (newHeaderItem != null)
{
var newHeaderItemControls = newHeaderItem.Controls;
var Item = newHeaderItemControls.item(1); // Get Access to 1st SubItem
if (Item != null)
{
if (Item.Caption == “Turn to German”) Item.Caption = “Turn to English”;
else
if (Item.Caption == “Turn to English”) Item.Caption = “Turn to German”;
}
//clear memory
newHeaderItemControls = null;
Item = null;
}
else
{
Application.Alert(“Can't Rename menu”)
}
//clear memory
newHeaderItem = null;
}
//clear memory
Bars = null;
menuBar = null;
menuBarCtrls = null;
fileMenu = null;
} // _Switch()
]]>
[/code]Derek Read May 5, 2009 at 4:31 pm
Reply to: XMetal Menu Problem
May 5, 2009 at 4:31 pmYou must run such a macro when there are no documents open for it to affect the default toolbars and menus. Typically such a script would be placed inside the startup event On_Default_CommandBars_Complete.
Fendor May 6, 2009 at 8:16 am
Reply to: XMetal Menu Problem
May 6, 2009 at 8:16 amunfortunately I need to be able to run this script at any point in time (localization)
so I need to know WHY the menu is affected by the opened document and WHAT to do to avoid it
please help DerekDerek Read May 6, 2009 at 7:33 pm
Reply to: XMetal Menu Problem
May 6, 2009 at 7:33 pmThis is going to be trickier to do as scripting changes to toolbars and menus are meant to be done at application startup or at document (DTD/Schema) open as part of either an application level (customization) macro or document level (customization) macro. You might be able to make changes during other events, but we do not test those scenarios. If such a script is run manually by a user it will probably work, but it will affect the particular document level customization currently loaded, or if one is not loaded it will affect the application level customization.
Do you mean that you wish to allow your users to switch between different language versions of toolbars at any time during editing? I'm not sure why that would be a requirement (not arguing that it shouldn't be, just wondering)? The only solution I can think of is to check for the number of documents open (Documents.Count) and if the value is larger than 0 tell the user they must close all documents before running your script.
To answer your question… When XMetaL Author launches it first loads up a default set of toolbars and menus. These are governed by the content of the file named default.tbr. To this are added any changes that fire in scripts at application startup. When a document is opened the yourDocType.tbr file (that matches yourDocType.dtd or yourDocType.xsd in your customization) are added on top of the default settings along with any scripts that fire at document open.
This allows the product to have menu and toolbar items that should be available at all times (for example File > Open, etc) and then add specific items that only have special meaning in the context of a specific document type. When you switch between different document types the menus and toolbars are automatically updated.
Fendor May 7, 2009 at 10:56 am
Reply to: XMetal Menu Problem
May 7, 2009 at 10:56 amHi Derek.
Thank you very much for the extensive reply.
The localization is given here as a simplest example.
To make things more clear we need to be able to change the menu content at any time. And to make sure that these changes are not lost when a user closes a document.Currently if we apply any change to the menu when a document is loaded, closing this document will roll those changes back and restore the menu to the state which it had before the document was opened.
So far we need to make our menu a “global” one, so that any changes applied to this menu shall remain regardless of wether a document is open or not.
Please specify the most correct way to do so?
Fendor.
Derek Read May 7, 2009 at 6:09 pm
Reply to: XMetal Menu Problem
May 7, 2009 at 6:09 pmYou will need to close all documents (either by asking the user to do so or via script) before making the change.
-
AuthorPosts
- You must be logged in to reply to this topic.