General XMetaL Discussion

  • Max

    Help with Menu

    Participants 4
    Replies 5
    Last Activity 13 years, 2 months ago

    Hi,

    I'm trying to create a custom menu and toolbar in XMetal Author 5.5

    I created the marcos “On_Default_CommandBars_Complete” and put it in MyMacro.mcr in the StartUp folder.

    I can see my “NewMenu” and toolbar when XMetal is loaded.

    Menu has 2 views:

    View 1

    MyMenu
      Load

    View 2

    MyMenu
      Item 1
      Item 2
      Unload

    When I opened “Sample_Map.ditamap” and choose User accounts -> Editing a user accounts, Xmetal opened a document.
    I choose MyMenu -> Load  and then saw my toolbar and refreshed menu (in View 2), then I choose Unload.  My menu view became like this:

    MyMenu

    But if I close “Editing a user accounts” menu takes the view 1.
    I opened this document  again and menu got a wrong view.

    Does Xmetal save a state for menu bar when a document is open and when no documents are open?

    How to fix it?  I need the same behavior in case when documents are open and when no documents are open.

    Code for menu

    [code]var cmdBars = Application.CommandBars;
    var menuBar = cmdBars.item(“Menu bar”);
    var menuBarCtrls = menuBar.Controls;
    var fileMenu = menuBarCtrls.item(“MyMenu”);

      if (fileMenu == null)
      {
          var newHeaderItem = menuBarCtrls.Add(sqcbcTypePopup);
          newHeaderItem.Caption = “MyMenu”;
          if (newHeaderItem != null)            // Label 1
          {
              var newHeaderItemControls = newHeaderItem.Controls;
             
              var Item = newHeaderItemControls.Add(sqcbcTypePopup);                   
              Item.Caption = “Load”;
              Item.FaceId=0;
              Item.OnAction = “LoadEngine”;
              Item.Enabled = true;
              Item = null;   

          }
      }
    else
      {
          var MenuItems = null;
          var tImem = null;
          var trycreatemenu = null;
         
          try{
              MenuItems = fileMenu.Controls;   
              try
              {
                  while (MenuItems.Count >0)
                  {
                    tImem = MenuItems.item(1);
                    if (tImem != null) tImem.Delete();
                  }
              }
              catch (err)
              { 
                fileMenu.Delete();
                trycreatemenu = menuBarCtrls.Add(sqcbcTypePopup);
                trycreatemenu.caption = “MyMenu”;
              }
          }
          catch(HighError)
          {
              Application.alert(HighError); 
          }   

        // Create menu as described above (  see Label 1 )

      }

    // Clear memory

    all vars = null;[/code]

    Reply

    BoneKrusher

    Reply to: Help with Menu

    I thinks its in

    C:Program FilesXMetaL 5.1AuthorMacros

    Reply

    Derek Read

    Reply to: Help with Menu

    Yes, there are two states. One is the “default” state. This is what you see when no documents are open. When you open a document the menus and toolbars associated with the customization for that DTD or XSD are loaded on top of the default state (they are cumulative).

    TBR files might get in the way here during development because they are also loaded when a document is loaded. I would try keeping your script as it is and then resetting your last opened workspace by holding the Ctrl key down at launch. This should restore the workspace to the default (out of box) state. Note that if you provide a modified TBR file with your customization (DTD or XSD) then this will still be loaded on top of any changes you make. However, by default such a file will contain all the same settings and so nothing extra should be added.

    Reply

    Max

    Reply to: Help with Menu

    Thanks, Derek Read.

    Another question.

    I defined two macros

    On_Before_Document_Save
    On_Before_Document_SaveAs

    like this:

    [code]

    Application.alert(“Save As Event!”) 'Do something with this document and “MyMenu” ]]>
    [/code]

    I put this macros in MyMacro.mcr in the StartUp folder.
    But I don't see any messages when I changed document and clicked “save”. What's wrong?

    Reply

    mag3737

    Reply to: Help with Menu

    Those two events are document-type-specific event macros.  They won't fire when they are located in an “application-level” macro file, such as the ones in the Startup folder.  Instead use the corresponding application-level event macros:

    On_Application_Before_Document_SaveAs
    On_Application_Before_Document_Save

    Reply

    Max

    Reply to: Help with Menu

    Thanks, mag3737.

    Derek Read and mag3737,

    My goal is to create simple customisation with menu and toolbar.

    here my logic (how i  imagine it) step by step:

    1) Create MyMacro.mcr in the StartUp folder

    2) On Macro “On_Default_CommandBars_Complete” I call function “CreateLoadMenu” and this function recreates
    menu in view 1

    MyMenu
      Load

    2.1) I put macro “CreateFullMenu” on property OnAction for “Load” item.

    3) User presses “Load” and calles macro “CreateFullMenu”.

    4) This macro tries to delete previous menu item “Load”, if fails macro tries to delete “MyMenu” and recreates it.

    4.1) Add menu items “Item 1″,”Item 2″,”Unload” and create toolbar
    4.3) On “Unload” action macros “CreateLoadMenu” is called

    5) User preses “Unload” and sees menu in View 1.

    Steps 2 – 4.3 are application-level marco.
    I use only one file “MyMacro.mcr” and I don't use any DTD or XSD customization.

    This is What I get when no documents are opened: pict 1

    This is What I get when a document is opened: pict 2

    How can I get the needed items when the documents are opened?

    Full code of “MyMacro.mcr”:
    [code]


    Application.alert(“Test!!!”)
    ]]>


    Application.Run(“CreateLoadMenuMac”)
    ]]>


    var cmdBars = Application.CommandBars;
    var menuBar = cmdBars.item(“Menu bar”);
    var menuBarCtrls = menuBar.Controls;
    var fileMenu = menuBarCtrls.item(“MyMenu”); if (fileMenu != null) fileMenu.Delete(); //clear memory
    cmdBars = null;
    menuBar = null;
    menuBarCtrls = null;
    fileMenu = null;
    }//_DeleteMenu() ]]>


    //Application.Run(“DeleteToolBar”); function _CreateLoadMenu(){ var cmdBars = Application.CommandBars;
    var menuBar = cmdBars.item(“Menu bar”);
    var menuBarCtrls = menuBar.Controls;
    var fileMenu = menuBarCtrls.item(“MyMenu”);   if (fileMenu == null)
      {
          var newHeaderItem = menuBarCtrls.Add(sqcbcTypePopup);
          newHeaderItem.Caption = “MyMenu”;
          if (newHeaderItem != null)                //  create ok!
          {
              var newHeaderItemControls = newHeaderItem.Controls;
             
              var Item = newHeaderItemControls.Add(sqcbcTypePopup);                   
              Item.Caption = “Load”;
              Item.FaceId=0;
              Item.OnAction = “CreateFullMenuMac”;
              Item.Enabled = true;
              Item = null; 
             
              //clear memory
              newHeaderItemControls = null;
              Item = null;       
          }
          else
          {
            Application.Alert(“Can't create MyMenu menu”)   
          }
         
        //clear memory
        newHeaderItem = null; 
      }
      else                                        // if already exits
      {
          var MenuItems = null;
          var tImem = null;
          var trycreatemenu = null;
         
          try{
              MenuItems = fileMenu.Controls;      // try kill menu item
              try
              {
                  while (MenuItems.Count >0)
                  {
                    tImem = MenuItems.item(1);
                    if (tImem != null) tImem.Delete();
                  }
              }
              catch (err)
              { 
                fileMenu.Delete();                // fail! Kill MyMenu and ReCreate
                trycreatemenu = menuBarCtrls.Add(sqcbcTypePopup);
                trycreatemenu.caption = “MyMenu”;
              }
          }
          catch(HighError)
          {
              Application.alert(HighError); 
          }
          //clear memory
          MenuItems = null;
          tImem = null;
          trycreatemenu = null;     
             
          var newHeaderItem = menuBarCtrls.item(“MyMenu”);     
          if (newHeaderItem != null)            //  ReCreate ok!
          {
              var newHeaderItemControls = newHeaderItem.Controls;
             
              var Item = newHeaderItemControls.Add(sqcbcTypePopup);                   
              Item.Caption = “Load”;
              Item.FaceId=0;
              Item.OnAction = “CreateFullMenuMac”;
              Item.Enabled = true;
              Item = null; 
             
              //clear memory
              newHeaderItemControls = null;
              Item = null;         
          }
          else
          {
            Application.Alert(“Can't create MyMenu menu”)   
          } 
          //clear memory
          newHeaderItem = null;
      } // Menu If
       
    //clear memory
    cmdBars = null;
    menuBar = null;
    menuBarCtrls = null;
    fileMenu = null; } //_CreateLoadMenu() ]]>


             
    var cmdBars = Application.CommandBars;
    var menuBar = cmdBars.item(“Menu bar”);
    var menuBarCtrls = menuBar.Controls;
    var fileMenu = menuBarCtrls.item(“MyMenu”);   if (fileMenu == null)
      {
          var newHeaderItem = menuBarCtrls.Add(sqcbcTypePopup);
          newHeaderItem.Caption = “MyMenu”;
          if (newHeaderItem != null)                    //  create ok!
          {
              var newHeaderItemControls = newHeaderItem.Controls;
             
              var Item = newHeaderItemControls.Add(sqcbcTypePopup);                   
              Item.Caption = “Item 1”;
              Item.FaceId=0;
              Item.OnAction = “TestMac”;
              Item.Enabled = true;
              Item = null;     
             
             
              Item = newHeaderItemControls.Add(sqcbcTypePopup);
              Item.Caption = “Item 2”;
              Item.FaceId=0;
              Item.OnAction = “TestMac”;       
              Item.Enabled = true;
              Item = null;
             
              Item = newHeaderItemControls.Add(sqcbcTypePopup);
              Item.Caption = “Unload”;
              Item.FaceId=0;
              Item.OnAction = “CreateLoadMenuMac”;
              Item = null;
             
              //clear memory
              newHeaderItemControls = null;
              Item = null;       
          }
          else
          {
            Application.Alert(“Can't create MyMenu menu”)   
          }
         
        //clear memory
        newHeaderItem = null; 
      }
      else                                                //if already exist
      {
          var MenuItems = null;
          var tImem = null;
          var trycreatemenu = null;
         
          try{
              MenuItems = fileMenu.Controls;              // try Kill menu item
              try
              {
                  while (MenuItems.Count >0)
                  {
                    tImem = MenuItems.item(1);
                    if (tImem != null) tImem.Delete();
                  }
              }
              catch (err)
              { 
                fileMenu.Delete();                        // Fail, Kill MyMenu and ReCreate.
                trycreatemenu = menuBarCtrls.Add(sqcbcTypePopup);
                trycreatemenu.caption = “MyMenu”;
              }
          }
          catch(HighError)
          {
              Application.alert(HighError); 
          }
          //clear memory
          MenuItems = null;
          tImem = null;
          trycreatemenu = null;     
             
          var newHeaderItem = menuBarCtrls.item(“MyMenu”);     
          if (newHeaderItem != null)                          // ReCreate ok!
          {
              var newHeaderItemControls = newHeaderItem.Controls;
             
              var Item = newHeaderItemControls.Add(sqcbcTypePopup);                   
              Item.Caption = “Item 1”;
              Item.FaceId=0;
              Item.OnAction = “TestMac”;
              Item.Enabled = true;
              Item = null;     
             
             
              Item = newHeaderItemControls.Add(sqcbcTypePopup);
              Item.Caption = “Item 2”;
              Item.FaceId=0;
              Item.OnAction = “TestMac”;       
              Item.Enabled = true;
              Item = null;
             
              Item = newHeaderItemControls.Add(sqcbcTypePopup);
              Item.Caption = “Unload”;
              Item.FaceId=0;
              Item.OnAction = “CreateLoadMenuMac”;
              Item = null; 
             
              //clear memory
              newHeaderItemControls = null;
              Item = null;         
          }
          else
          {
            Application.Alert(“Can't create MyMenu menu”)   
          } 
          //clear memory
          newHeaderItem = null;
      } // Menu If
       
    //clear memory
    cmdBars = null;
    menuBar = null;
    menuBarCtrls = null;
    fileMenu = null; }//_CreateFullMenu() ]]>
     


    [/code]

    Reply

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

Lost Your Password?

Products
Downloads
Support