WebOSDev - Programming has just evolved

The online blog for the webOS developer community you can find everything you need here to get a strong start developing applications for the webOS platform
Showing posts with label menu. Show all posts
Showing posts with label menu. Show all posts

Activating one app menu for all the scenes

Posted by codesos Tuesday, November 3, 2009 0 comments

Want to define one app menu , Handle it once but acrivate it from all scenes?

Here is the way

1. Define the  menue modal and att as globals in the stage scene

glob = {};


glob.MenuAttr = {omitDefaultItems: true};



glob.appMenuModel = {

               visible: true,

               items: [

                           Mojo.Menu.editItem, //must


                            {label: $L("Preferences..."), command: "do-Prefs"},

                            {label: $L("Help"), command: "do-about"}


                          ]

                    };

define the handle command in the same stage scene :

StageAssistant.prototype.handleCommand = function(event)
{
                      var currentScene = Mojo.Controller.stageController.activeScene();

                      if (event.type == Mojo.Event.commandEnable) {

                                  if ((event.command == "do-Update")) {

                                            event.preventDefault();
                                   }

                       }

else {

           if(event.type == Mojo.Event.command) {

               switch(event.command) {

                     case "do-about":

                         Mojo.Controller.stageController.pushScene('support');

                     break;

                     case "do-Prefs":

                          Mojo.Log.info("do-Prefs");

                         Mojo.Controller.stageController.pushScene("preferences");

                     break;

                  case "do-Update":

                  break;

           }

     }

}
}

now in every scene's setup function do this:

this.controller.setupWidget(Mojo.Menu.appMenu, glob.MenuAttr, glob.appMenuModel);


Done!!