Custom MenuItem

What is Custom MenuItem?

Widget's right click menu support add custom menuitem. you can create "menu" node in "widget.json" file to create custom menuitem. Custom MenuItem can bind measure to send command to measure or run javascript code.

Measures are also can auto create custom menuitem by default. if you do not need custom menuitem by measure ,just add this code in measure section "autoCreateCustomMenu" : false

Sample

  "menu":[
    {
      "caption":"Update Weather",
      "measure":"weather1",
      "onClick":"update"
    },
    {
      "caption":"Change Location",
      "measure":"weather1",
      "onClick":"setting"
    }
  ]

How to Create MenuItem

Found the "menu" json node in file "widget.json",if not, you need create a json node named "menu" for excample :

{
  "information":{
    "author":"",
    "width":300,
    "height":300,
    "name":"Simple Weather"
  },
  "measure":{
    "weather":{
      "name":"weather1",
      "title":"Weather",
    }
  },
  "menu":[

  ]
}

Add MenuItems into the menu json node like this:

  "menu":[
    {
      "caption":"Update Weather",
      "measure":"weather1",
      "onClick":"update"
    },
    {
      "caption":"Change Location",
      "measure":"weather1",
      "onClick":"setting"
    }

  ]

caption : MenuItem title

measure: the measure name of bind

onClick: when the menuitem clicked,the command of the bind measure will be invoked

isChecked : the menuitem will be checked when the value is true

enabled: the menuitem will be gray and can not click when the value is false

How to Display Measure Setting Window by MenuItem

Measure setting menuitem is auto created by default, you can disable it by "autoCreateCustomMenu".

"measures":{
  "shortcut":{
    "name":"shortcut1",
    "autoCreateCustomMenu" : false,  //disable auto create menuitem for measure
    "autoCreateSettingTab" : false,  //disable auto create setting tab for measure
  }
}

You also can create measure menuitem by set the menuitem measure field with the measure name , and set the onClick field with "setting",for excample:

  "menu":[
    {
      "caption":"Change Location",
      "measure":"weather1",
      "onClick":"setting"
    }
  ]

You can found all the measure command from here

How to Run JavaScript Code

You can run javascript code when the menuitem was clicked by set the measure to blank and set the js code into the onClick property. It can execute multiple js statements at the same time.

"menu":[
  {
    "caption": "do some thing",
    "onClick" : " cmd('weather1','update');  cmd('showMsg','Weather Update Start!'); "
  }
]

Last updated