当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript CommandRegistry.isEnabled方法代码示例

本文整理汇总了TypeScript中@phosphor/commands.CommandRegistry.isEnabled方法的典型用法代码示例。如果您正苦于以下问题:TypeScript CommandRegistry.isEnabled方法的具体用法?TypeScript CommandRegistry.isEnabled怎么用?TypeScript CommandRegistry.isEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@phosphor/commands.CommandRegistry的用法示例。


在下文中一共展示了CommandRegistry.isEnabled方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

 it('should test whether a specific command is enabled', () => {
   let cmd = {
     execute: (args: JSONObject) => { return args; },
     isEnabled: (args: JSONObject) => { return args.enabled as boolean; }
   };
   registry.addCommand('test', cmd);
   expect(registry.isEnabled('test', { enabled: true })).to.equal(true);
   expect(registry.isEnabled('test', { enabled: false })).to.equal(false);
 });
开发者ID:afshin,项目名称:phosphor,代码行数:9,代码来源:index.spec.ts

示例2: onChange

    // Ensure that we pick up relevant changes to the command:
    function onChange(sender: CommandRegistry, args: CommandRegistry.ICommandChangedArgs) {
      if (args.id !== id) {
        return;  // Not our command
      }

      if (args.type === 'removed') {
        // Dispose of button
        button.dispose();
        return;
      }

      if (args.type !== 'changed') {
        return;
      }

      // Update all fields (onClick is already indirected)
      const newClasses = Private.commandClassName(sender, id).split(/\s/);

      for (let cls of oldClasses) {
        if (cls && newClasses.indexOf(cls) === -1) {
          button.removeClass(cls);
        }
      }
      for (let cls of newClasses) {
        if (cls && oldClasses.indexOf(cls) === -1) {
          button.addClass(cls);
        }
      }
      oldClasses = newClasses;
      button.node.title = Private.commandTooltip(sender, id);
      Private.setNodeContentFromCommand(button.node, sender, id);
      (button.node as HTMLButtonElement).disabled = !sender.isEnabled(id);
    }
开发者ID:7125messi,项目名称:jupyterlab,代码行数:34,代码来源:toolbar.ts

示例3: createFromCommand

  function createFromCommand(commands: CommandRegistry, id: string): ToolbarButton | null {
    if (!commands.hasCommand(id)) {
      return null;
    }

    const button = new ToolbarButton({
      onClick: () => {
        commands.execute(id);
        button.node.blur();
      },
      className: Private.commandClassName(commands, id),
      tooltip: Private.commandTooltip(commands, id)
    });
    let oldClasses = Private.commandClassName(commands, id).split(/\s/);

    (button.node as HTMLButtonElement).disabled = !commands.isEnabled(id);
    Private.setNodeContentFromCommand(button.node, commands, id);

    // Ensure that we pick up relevant changes to the command:
    function onChange(sender: CommandRegistry, args: CommandRegistry.ICommandChangedArgs) {
      if (args.id !== id) {
        return;  // Not our command
      }

      if (args.type === 'removed') {
        // Dispose of button
        button.dispose();
        return;
      }

      if (args.type !== 'changed') {
        return;
      }

      // Update all fields (onClick is already indirected)
      const newClasses = Private.commandClassName(sender, id).split(/\s/);

      for (let cls of oldClasses) {
        if (cls && newClasses.indexOf(cls) === -1) {
          button.removeClass(cls);
        }
      }
      for (let cls of newClasses) {
        if (cls && oldClasses.indexOf(cls) === -1) {
          button.addClass(cls);
        }
      }
      oldClasses = newClasses;
      button.node.title = Private.commandTooltip(sender, id);
      Private.setNodeContentFromCommand(button.node, sender, id);
      (button.node as HTMLButtonElement).disabled = !sender.isEnabled(id);
    }
    commands.commandChanged.connect(onChange, button);

    return button;
  }
开发者ID:7125messi,项目名称:jupyterlab,代码行数:56,代码来源:toolbar.ts


注:本文中的@phosphor/commands.CommandRegistry.isEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。