Skip to content

Command

The Command class is used to define toolbar and menu commands throughout the Application Center. Context menu for each app in NavigationView can be defined in each app via static App.commands property. When you start an app, toolbars and the Main menu commands are defined via App.commands property (not the static one). All context menus for controls are populated using an array of Command objects. See Examples below.

Constructor:

  • constructor(dict: Dict)
    Creates a Command instance. Parmeter is a dictionary like:
    {
      group: "Settings",  
      label: L`Show/Hide Search Box`,  
      shortcut: "Shift+F7",  
      icon: Icons.delete,  
      checked: this.isSettingsVisible,  
      enabled: this.canShowSettings,  
      command: ()=> code to show settings,
    }
    
  • group: string (optional)
    Used only for the Main Menu. If omitted all commands will be in Main Menu→Commands. If you specify the group property, the Main Menu will have a new submenu with that group’s name. The maximum of 7 different groups is allowed.
  • label: string | ()=> string (optional)
    Menu item label or toolbar button hint. Gan be a simple text or a getter function
  • shortcut: string (optional)
    Keyboard shortcut assigned to this command. For example: "Ctrl+S", "Cmd+O".
  • icon: string | Icon (optional)
    Icon drawn for the menu item or toolbar button. Value must be the name of an icon in SYS$ICON document class. The best practice is to use Icons.name_of_icon. You can add your own custom icons or change the existing ones via System Management→Icons app.
  • visible: boolean | ()=> boolean (optional)
    Whether the command is visible or not.
  • enabled: boolean | ()=> boolean (optional)
    Whether the command is enabled or not.
  • checked: boolean | ()=> boolean (optional)
    Whether the menu item is checked or not, or whether the toolbar button is pressed (down) or not.
Example
static get commands() {  
  return [  
    new Command( {   
      label: L`Show/Hide Search Box`, // L`some text` is i18n localization   
      checked: ui.navigation?.searchBox,   
      command: ()=> ui.navigation.searchBox = !ui.navigation.searchBox   
    } ),  
    {},                               // this is a separator  
    {                                 // you can omit 'new Command'  
      label: L`Properties...`,  
      visible: !!ui.navigation.focused,  
      command: async ()=> {  
        const {PropertiesApp} = await import('app:System.PropertiesApp');  
        let instance = new PropertiesApp(ui.navigation.focused?.app);  
          instance.run();  
      }  
    }  
  ];  
}