2011年4月4日月曜日

メニューの出し方

結局、メニューすらWidgetの一部な訳だった。stage-assistant.jsに以下の行を書き込む。
(要するにアプリ起動時のJavaScript)


(アプリケーション名).MenuAttr = {omitDefaultItems: true}; //標準のメニューを一端削除

(アプリケーション名).MenuModel = {
     visible: true,
     items: [
          {label: "About (アプリケーション名)...", command: "do-about(アプリケーション名)"},//他にもメニューに加えたいなら、 label:とcommand:で加えていく。
          Mojo.Menu.editItem,
          Mojo.Menu.prefsItem,
          Mojo.Menu.helpItem
     ]
};

あと忘れてはいけないのは、メニューで選択された場合の処理。prototype.handleCommandで定義しておく。

StageAssistant.prototype.handleCommand = function(event) {
    if(event.type == Mojo.Event.command) {
        switch(event.command) {
            case "do-about(アプリケーション名)": //他のメニューを作った場合はcase が増える。
                var currentScene = this.controller.activeScene();
                currentScene.showAlertDialog({
                    onChoose: function(value) {},
                        title: "(アプリケーション名) — v#{version}".interpolate({
                        version: (アプリケーション名).versionString}),
                        message: "Copyright xxxx",
                        choices:[
                            {label:"OK", value:""}
                        ]
                });
            break;
        }
    }
};
 メニューを作成したSceneの-assistant.jsに、以下の行を書き込む。

this.controller.setupWidget(Mojo.Menu.appMenu, (アプリケーション名).MenuAttr, (アプリケーション名).MenuModel);

これで大丈夫なはず。

0 件のコメント:

コメントを投稿