2 Replies Latest reply on Oct 20, 2008 11:08 PM by kiwi_ziesch

    Menu items

    kiwi_ziesch Level 1
      Hi,

      I have a native menu in my application. But I won´t show all menu items at the start. How can I hide items and activate them later?

      here comes my AIRMenus.js:

      ----------------------------------
      /* AIR Menus HTML application logic **/
      var popUp;
      var eventLog;

      var macStandardModifier = air.Keyboard.COMMAND;
      var winStandardModifier = air.Keyboard.CONTROL;
      var standardModifier;

      var macQuitLabel = "Beenden";
      var winQuitLabel = "Schließen";
      var quitLabel;


      //Sets the system tray or dock icon with the loaded image
      var iconLoadComplete = function(event)
      {
      air.NativeApplication.nativeApplication.icon.bitmaps = new runtime.Array(event.target.content.bitmapData);
      }

      //Creates the menus
      function AIRMenus(){
      //Set OS-specific variables
      var preface = document.getElementById("preface");
      var currentOS = air.Capabilities.os;
      var containsWindows = currentOS.search("Windows");
      if(containsWindows > -1){
      standardModifier = winStandardModifier;
      quitLabel = winQuitLabel;
      } else {
      standardModifier = macStandardModifier;
      quitLabel = macQuitLabel;
      }

      //For application menu (on MAC OS X)
      if(air.NativeApplication.supportsMenu){
      air.NativeApplication.nativeApplication.menu = createRootMenu("application menu");
      }

      //Create Dock menu and set icon image
      if(air.NativeApplication.supportsDockIcon){
      air.NativeApplication.nativeApplication.icon.menu = createRootMenu("dock icon menu");
      var dockIconLoader = new runtime.flash.display.Loader();
      dockIconLoader.contentLoaderInfo.addEventListener(air.Event.COMPLETE,iconLoadComplete);
      dockIconLoader.load(new air.URLRequest("icons/AIRApp_128.png"));
      }

      //For window menu (on Microsoft Windows)
      if(air.NativeWindow.supportsMenu){
      window.nativeWindow.menu = createRootMenu("window menu");
      }

      //Create system tray icon menu, tooltip and set the image so that the icon will be shown
      if(air.NativeApplication.supportsSystemTrayIcon){
      air.NativeApplication.nativeApplication.icon.tooltip = "AIR Menus HTML";
      air.NativeApplication.nativeApplication.icon.menu = createRootMenu("system tray icon menu");
      var systrayIconLoader = new runtime.flash.display.Loader();
      systrayIconLoader.contentLoaderInfo.addEventListener(air.Event.COMPLETE,iconLoadComplete) ;
      systrayIconLoader.load(new air.URLRequest("icons/AIRApp_16.png"));
      }

      window.htmlLoader.contextMenu = createRootMenu("htmlLoader context menu");

      //Create the pop-up menu
      popUp = createRootMenu("pop-up menu");

      //Activate this window so that it will be visible
      window.nativeWindow.activate();

      //Get a reference to the eventLog element where the selection events are displayed
      eventLog = document.getElementById("eventLog");
      }


      //Displays the pop-up menu
      function popUpMenu(event){
      popUp.display(window.nativeWindow.stage, event.clientX, event.clientY);
      }

      //Displays the context menu
      function showContextMenu(event){
      event.preventDefault();
      window.htmlLoader.contextMenu.display(window.nativeWindow.stage, event.clientX, event.clientY);
      }

      function createRootMenu(menuType){
      var menu = new air.NativeMenu();
      menu.addSubmenu(createFileMenu(menuType),"Datei");
      menu.addSubmenu(createEditMenu(menuType),"Bearbeiten");
      menu.addSubmenu(createPrefMenu(menuType),"Einstellungen");
      menu.addSubmenu(createHelpMenu(menuType),"Hilfe");
      return menu;
      }

      function createFileMenu(menuType){
      var temp;
      var menu = new air.NativeMenu();
      temp = menu.addItem(new air.NativeMenuItem("Bilder importieren"));
      temp.keyEquivalent = 'i';
      temp.data = menuType;
      temp.addEventListener(air.Event.SELECT, doImportPic);
      temp = menu.addItem(new air.NativeMenuItem("Ordner importieren"));
      temp.keyEquivalent = 'o';
      temp.data = menuType;
      temp.addEventListener(air.Event.SELECT, doImportDir);
      menu.addItem(new air.NativeMenuItem("",true));//separator
      temp = menu.addItem(new air.NativeMenuItem(quitLabel));
      temp.keyEquivalent = 'q';
      temp.data = menuType;
      temp.addEventListener(air.Event.SELECT, doCloseApp);

      return menu;
      }

      function createEditMenu(menuType){
      var temp;
      var menu = new air.NativeMenu();
      temp = menu.addItem(new air.NativeMenuItem("Metadatenvorlage"));
      temp.keyEquivalent = 'm';
      temp.data = menuType;
      temp.addEventListener(air.Event.SELECT, doModel);
      temp = menu.addItem(new air.NativeMenuItem("Stichwortkatalog"));
      temp.keyEquivalent = 'k';
      temp.data = menuType;
      temp.addEventListener(air.Event.SELECT, doCatalogue);

      return menu;
      }

      function createPrefMenu(menuType){
      var temp;
      var menu = new air.NativeMenu();
      temp = menu.addItem(new air.NativeMenuItem("Speicherverzeichnis"));
      temp.keyEquivalent = "v";
      temp.data = menuType;
      temp.addEventListener(air.Event.SELECT, doPref);

      return menu;
      }

      function createHelpMenu(menuType){
      var temp;
      var menu = new air.NativeMenu();
      temp = menu.addItem(new air.NativeMenuItem("Handbuch"));
      temp.keyEquivalent = "h";
      temp.data = menuType;
      temp.addEventListener(air.Event.SELECT, doHelp);

      return menu;
      }

      function noMenu(event){
      event.preventDefault();
      }
      -------------------------------------------------

      in my index.html I call AIRMenus(); in my doLoad()-function.
      has anybody an idea how to control the visibility of menu items?
      thanks in advance.