General XMetaL Discussion

  • Fendor

    XMetal Menu Problem

    Participants 5
    Replies 6
    Last Activity 13 years, 10 months ago

    I 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]

    Reply

    Derek Read

    Reply to: XMetal Menu Problem

    You 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.

    Reply

    Fendor

    Reply to: XMetal Menu Problem

    unfortunately 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 Derek

    Reply

    Derek Read

    Reply to: XMetal Menu Problem

    This 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.

    Reply

    Fendor

    Reply to: XMetal Menu Problem

    Hi 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.

    Reply

    Derek Read

    Reply to: XMetal Menu Problem

    You will need to close all documents (either by asking the user to do so or via script) before making the change.

    Reply

    Fendor

    Reply to: XMetal Menu Problem

    Sad to hear that, but thank you anyway 🙂

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support