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


TypeScript CommandRegistry.addCommand方法代码示例

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


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

示例1: it

 it('should resolve an exact match of partial match time out', (done) => {
   let called1 = false;
   let called2 = false;
   registry.addCommand('test1', {
     execute: () => { called1 = true; }
   });
   registry.addCommand('test2', {
     execute: () => { called2 = true; }
   });
   registry.addKeyBinding({
     keys: ['D', 'D'],
     selector: `#${elem.id}`,
     command: 'test1'
   });
   registry.addKeyBinding({
     keys: ['D'],
     selector: `#${elem.id}`,
     command: 'test2'
   });
   let event = generate('keydown', { keyCode: 68 });
   elem.dispatchEvent(event);
   expect(called1).to.equal(false);
   expect(called2).to.equal(false);
   setTimeout(() => {
     expect(called1).to.equal(false);
     expect(called2).to.equal(true);
     done();
   }, 1300);
 });
开发者ID:afshin,项目名称:phosphor,代码行数:29,代码来源:index.spec.ts

示例2: it

      it('should stop routing if returned by a routed command', done => {
        const wanted = ['a', 'b'];
        const recorded: string[] = [];

        commands.addCommand('a', {
          execute: () => {
            recorded.push('a');
          }
        });
        commands.addCommand('b', {
          execute: () => {
            recorded.push('b');
          }
        });
        commands.addCommand('c', { execute: () => router.stop });
        commands.addCommand('d', {
          execute: () => {
            recorded.push('d');
          }
        });

        router.register({ command: 'a', pattern: /.*/, rank: 10 });
        router.register({ command: 'b', pattern: /.*/, rank: 20 });
        router.register({ command: 'c', pattern: /.*/, rank: 30 });
        router.register({ command: 'd', pattern: /.*/, rank: 40 });

        router.routed.connect(() => {
          expect(recorded).to.deep.equal(wanted);
          done();
        });
        router.route();
      });
开发者ID:dalejung,项目名称:jupyterlab,代码行数:32,代码来源:router.spec.ts

示例3: it

      it('should stop routing if returned by a routed command', async () => {
        const wanted = ['a', 'b'];
        const recorded: string[] = [];

        commands.addCommand('a', {
          execute: () => {
            recorded.push('a');
          }
        });
        commands.addCommand('b', {
          execute: () => {
            recorded.push('b');
          }
        });
        commands.addCommand('c', { execute: () => router.stop });
        commands.addCommand('d', {
          execute: () => {
            recorded.push('d');
          }
        });

        router.register({ command: 'a', pattern: /.*/, rank: 10 });
        router.register({ command: 'b', pattern: /.*/, rank: 20 });
        router.register({ command: 'c', pattern: /.*/, rank: 30 });
        router.register({ command: 'd', pattern: /.*/, rank: 40 });

        let promise = signalToPromise(router.routed);
        await router.route();
        await promise;
        expect(recorded).to.deep.equal(wanted);
      });
开发者ID:AlbertHilb,项目名称:jupyterlab,代码行数:31,代码来源:router.spec.ts

示例4: addDefaultCommands

function addDefaultCommands(tracker: ITerminalTracker, commands: CommandRegistry) {

  /**
   * Whether there is an active terminal.
   */
  function hasWidget(): boolean {
    return tracker.currentWidget !== null;
  }

  commands.addCommand('terminal:increase-font', {
    label: 'Increase Terminal Font Size',
    execute: () => {
      let options = TerminalWidget.defaultOptions;
      if (options.fontSize < 72) {
        options.fontSize++;
        tracker.forEach(widget => { widget.fontSize = options.fontSize; });
      }
    },
    isEnabled: hasWidget
  });

  commands.addCommand('terminal:decrease-font', {
    label: 'Decrease Terminal Font Size',
    execute: () => {
      let options = TerminalWidget.defaultOptions;
      if (options.fontSize > 9) {
        options.fontSize--;
        tracker.forEach(widget => { widget.fontSize = options.fontSize; });
      }
    },
    isEnabled: hasWidget
  });

  commands.addCommand('terminal:toggle-theme', {
    label: 'Toggle Terminal Theme',
    caption: 'Switch Terminal Background and Font Colors',
    execute: () => {
      let options = TerminalWidget.defaultOptions;
      if (options.background === 'black') {
        options.background = 'white';
        options.color = 'black';
      } else {
        options.background = 'black';
        options.color = 'white';
      }
      tracker.forEach(widget => {
        widget.background = options.background;
        widget.color = options.color;
      });
    },
    isEnabled: hasWidget
  });
}
开发者ID:faricacarroll,项目名称:jupyterlab,代码行数:53,代码来源:index.ts

示例5: addDefaultCommands

function addDefaultCommands(tracker: IImageTracker, commands: CommandRegistry) {
  commands.addCommand('imagewidget:zoom-in', {
    execute: zoomIn,
    label: 'Zoom In'
  });

  commands.addCommand('imagewidget:zoom-out', {
    execute: zoomOut,
    label: 'Zoom Out'
  });

  commands.addCommand('imagewidget:reset-zoom', {
    execute: resetZoom,
    label: 'Reset Zoom'
  });

  function zoomIn(): void {
    let widget = tracker.currentWidget;
    if (!widget) {
      return;
    }
    if (widget.scale > 1) {
      widget.scale += .5;
    } else {
      widget.scale *= 2;
    }
  }

  function zoomOut(): void {
    let widget = tracker.currentWidget;
    if (!widget) {
      return;
    }
    if (widget.scale > 1) {
      widget.scale -= .5;
    } else {
      widget.scale /= 2;
    }
  }

  function resetZoom(): void {
    let widget = tracker.currentWidget;
    if (!widget) {
      return;
    }
    widget.scale = 1;
  }
}
开发者ID:faricacarroll,项目名称:jupyterlab,代码行数:48,代码来源:index.ts

示例6: it

      it('should restore the widgets in a tracker', done => {
        let tracker = new InstanceTracker<Widget>({
          namespace: 'foo-widget',
          shell: new ApplicationShell()
        });
        let registry = new CommandRegistry();
        let state = new StateDB({ namespace: NAMESPACE });
        let ready = new PromiseDelegate<void>();
        let restorer = new LayoutRestorer({
          first: ready.promise, registry, state
        });
        let called = false;
        let key = `${tracker.namespace}:${tracker.namespace}`;

        registry.addCommand(tracker.namespace, {
          execute: () => { called = true; }
        });
        state.save(key, { data: null }).then(() => {
          return restorer.restore(tracker, {
            args: () => null,
            name: () => tracker.namespace,
            command: tracker.namespace
          });
        }).catch(done);
        ready.resolve(void 0);
        restorer.restored.then(() => { expect(called).to.be(true); })
          .then(() => state.remove(key))
          .then(() => { done(); })
          .catch(done);
      });
开发者ID:charnpreetsingh185,项目名称:jupyterlab,代码行数:30,代码来源:layoutrestorer.spec.ts

示例7: before

  before(() => {
    commands = new CommandRegistry();
    bkoMenu = new BkoMenu({ commands });

    commands.addCommand('test', { execute: () => {} });
    bkoMenu.addItem({command: 'test', submenu: bkoMenu, type: 'submenu'});
  });
开发者ID:twosigma,项目名称:beaker-notebook,代码行数:7,代码来源:BkoMenu.spec.ts


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