.. highlightlang:: us .. index:: Overview Menus, Menus .. _overview-menus: Overview Menus ============== .. us.makeindex Menu, Overview Menus .. include:: ../ftab/Menu.ftab The Main Menus .............. UniPlot has menus for each window type. The menus have the following names: .. list-table:: :header-rows: 1 * - Value - Meaning * - "Editor" - This menu is displayed when the text editor is active. * - "Document" - This menu is displayed when a document page is active :file:`.ipw`. * - "DocumentServer" - This menu is displayed when a document page is active in a different application (OLE 1) :file:`.ipw`. * - "Command" - This menu is displayed when the command window is active. * - "Main" - This menu is displayed when UniPlot does not show an active window. New menu items can be inserted with the help of the functions :ref:`MnInsert`, :ref:`MnAppend` and :ref:`MnSetCommand`. These functions are normally invoked during startup. Most of the standard menu items are added in the file :file:`do_cmds.ic`. .. us.example **Example** A simple example: :: nID = MnGetNewCommandID(); MnInsert("Document", 1, 7, nID, "My Import"); MnDrawMenuBar(); MnSetCommand(nID, "DoMyImport()"); :ref:`MnInsert` inserts a new item into a menu. In the example the string ``"My Import"`` will be added to the "Document" menu. The three numbers have the following meaning: The first number is the index of the main menu element. The index 1 means the first menu, in this case it is the File menu. The 7 means the item is added after the 7th element. The number *nID* is the index in the UniPlot/UniScript command table. To create a unique index you should use the :ref:`MnGetNewCommandID` function. :ref:`MnDrawMenuBar` will replot the active menu. :ref:`MnSetCommand` assigns a UniScript command to a menu item. Popup Menus ........... If a menu item is selected that displays a small triangle on the right side popup menu will be displayed. This popup menu can be inserted into a menu using the :ref:`MnInsertPopup` function. See :ref:`MnInsertPopup` for an example. OnCommandUI ........... Menu items can be removed or disabled by specifying a function to update the menu item. See :ref:`OnCommandUI`. Context Menus (shortcut menu) ............................. Beginning with UniPlot 3.05 objects can have menus. To open a context menu, right click on an object. Context menus can contain popup menus. .. us.example **Example** Example: Add Menu item to the text object context menu: :: MenuInsertCommands("OBJ_TB", [""; "MyLegendFunc"], 32000); MnSetCommand("MyLegendFunc", "Legende..."); Example: Add pop-up menu to the text object context menu. :: MenuCreatePopup("OBJ_TB-Legend", [.. "_Test1"; "_Test2"]); MenuInsertCommands("OBJ_TB", [""; "OBJ_TB-Legend@Legende"], 32000); MnSetCommand("_Test1", "Legende1..."); MnSetCommand("_Test2", "Legende2..."); Example: Adds a pop-up menu "Translate" to the layer object context menu. Save the following script in an ic file in the UniPlot autoload folder: :: def _popup_InitTranslateMenu() { global g_bTranslateMenuInit; if (g_bTranslateMenuInit) { return; } g_bTranslateMenuInit = 1; MenuCreatePopup("OBJ_LAYER-Translate", [.. "OnTranslateEnglish"; "OnTranslateGerman"; "OnTranslateSpanish"]); MenuInsertCommands("OBJ_LAYER", [""; "OBJ_LAYER-Translate@Translate"], 32000); MnSetCommand("OnTranslateEnglish", "English..."); MnSetCommand("OnTranslateGerman", "German..."); MnSetCommand("OnTranslateSpanish", "Spanish..."); } _popup_InitTranslateMenu() def OnTranslateEnglish() { hPage = AppGetActivePage(); if (hPage == 0) { return 0; } hvLayer = PageGetAllLayers(hPage) if (hvLayer[1] == 0) { return 0; } // etc.. MessageBox("english"); } def OnTranslateGerman() { MessageBox("german"); } def OnTranslateSpanish() { MessageBox("spanish"); } .. seealso:: :ref:`functions-by-categories` :sub:`id-1362113`