7 Replies Latest reply on Jan 26, 2016 7:37 AM by Klaus Göbel

    Moving menu commands

    frameexpert Level 4

      Has anyone had success adding custom commands to FrameMaker menus and then moving them to different locations on the menu? I can do this with the FDK and FrameScript but I haven't had success with ExtendScript. I am defining a custom command and adding it to the File menu. I want to move it up under the Save As XML command. Here is what I am using:

       

      #target framemaker
      
      var menu, cmd, saveCmd;
      
      // Get the File menu.
      menu = app.GetNamedMenu ("FileMenu");
      
      // Create the command and add it to the File menu.
      cmd = menu.DefineAndAddCommand (10, "SaveAsPdfQuickCmd", "Save As PDF Quick","");
      cmd.EnabledWhen = Constants.FV_ENABLE_NEEDS_DOCP_ONLY;
      
      // Move the command up in the menu.
      saveCmd = app.GetNamedCommand ("SaveAsXml");
      cmd.PrevMenuItemInMenu = saveCmd;
      
      // must call if script has been run through ESTK, redundant otherwise.
      UpdateMenus ();
      

       

      The custom command gets added to the File menu, but it stays at the bottom of the menu. Any help would be appreciated. Thanks.

      -Rick

        • 1. Re: Moving menu commands
          Klaus Göbel Level 3

          Hi Rick,

           

          you can find the answer in FDK Programmer's Guide

           

          Section "Reordering menus and menu items" page 393

           

          To change a menu or menu item’s position on a menu, set its

          FP_NextMenuItemInMenu or FP_PrevMenuItemInMenu properties to specify

          the IDs of other menus or menu items on the menu. You need to set only one of these

          properties. FrameMaker automatically sets the other one for you.

           

          I hope that helps.

          • 2. Re: Moving menu commands
            frameexpert Level 4

            Hi Klaus, Thanks for your answer, but my ExtendScript code doesn't work. I am not sure if it is a bug in ExtendScript or if it has to be done differently than in the FDK. -Rick

            • 3. Re: Moving menu commands
              Klaus Göbel Level 3

              Hi Rick,

              I will test it next week.

               

              I'll come back with my results the next days.

               

              Have a nice weekend

              • 4. Re: Moving menu commands
                Russ Ward Level 4

                Hi Rick,

                 

                I observe the same behavior. I've also observed in the past that menu.Delete() doesn't work either. I can't remember whether they fixed that or not.

                 

                Russ

                • 5. Re: Moving menu commands
                  frameexpert Level 4

                  Hi Russ, Yes, there is some kind of disconnect between the command and the menus it resides on. When you do this in the FDK with F_ApiSetId, one of the parameters is the menu id (see lines 10 and 12). The menu id is critical because a particular command can appear on any number of menus.

                   

                      // Add the custom straddle columns command to the table menu.
                      straddleColsCmd = F_ApiDefineCommand(STRADDLE_COLS, "StraddleCols",
                          "Straddle Columns Only (Preserve Rows)", "");
                      F_ApiAddCommandToMenu(tableMenuId, straddleColsCmd);
                      F_ApiAddCommandToMenu(tableContextMenuId, straddleColsCmd);
                      F_ApiSetInt(FV_SessionId, straddleColsCmd,
                          FP_EnabledWhen, FV_ENABLE_IS_CELLS);
                  
                      // Move the command so that it comes after the straddle command.
                      F_ApiSetId(tableMenuId, straddleColsCmd, FP_PrevMenuItemInMenu,
                          straddleCmd);
                      F_ApiSetId(tableContextMenuId, straddleColsCmd, FP_PrevMenuItemInMenu,
                          straddleCmd);
                  

                   

                  FrameScript is similar. For example,

                   

                  // Get the table menu.
                  Get Object Name('TableMenu') Type(Menu) NewVar(oTblMenu);
                  // Make the new command.
                  New Command Name('StraddleCols') Label('Straddle Columns Only (Preserve Rows)')
                    NewVar(oStraddleColsCmd) EventProc(StraddleColsEvent);
                  // Add the command to the table menu.
                  Add CommandObject(oStraddleColsCmd) To(oTblMenu);
                  // Move the custom command so it appears after the built-in Straddle command.
                  Get Object Name('TableStraddle') Type(Command) NewVar(oStraddleCmd);
                  // *** First assign the parent menu object to the command.
                  Set oStraddleCmd.Menu = oTblMenu;
                  // Now it can be moved.
                  Set oStraddleColsCmd.PrevMenuItemInMenu = oStraddleCmd;
                  

                   

                  Line 11 is the key because it tells you which menu item you are referring to for the existing command. I can't figure out how to specify the parent menu of a command with ExtendScript. -Rick

                  • 6. Re: Moving menu commands
                    Russ Ward Level 4

                    Rick, I get it now. You are right... the parent menu is a fundamental parameter when defining or retrieving NextMenuItemInMenu, etc., but there seems to be no way to specify it. Using the debugger, I see that the NextMenuItemInMenu and PrevMenuItemInMenu properties always return an invalid object, no matter which way you come at them.

                     

                    Since the debugger suggests that the documentation is correct (or at least intends to be), I think this must be an incomplete implementation. With regrets, I don't have any other ideas. This seems very unfortunate indeed. Perhaps Adobe would regard this as an issue worthy of attention.

                     

                    Russ