Example #1
0
 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);
 });
Example #2
0
      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();
      });
Example #3
0
 it('should pick the selector with greater specificity', () => {
   elem.classList.add('test');
   let called1 = false;
   let called2 = false;
   registry.addCommand('test1', {
     execute: () => { called1 = true; }
   });
   registry.addCommand('test2', {
     execute: () => { called2 = true; }
   });
   registry.addKeyBinding({
     keys: ['Ctrl ;'],
     selector: '.test',
     command: 'test1'
   });
   registry.addKeyBinding({
     keys: ['Ctrl ;'],
     selector: `#${elem.id}`,
     command: 'test2'
   });
   let event = generate('keydown', { keyCode: 59, ctrlKey: true });
   elem.dispatchEvent(event);
   expect(called1).to.equal(false);
   expect(called2).to.equal(true);
 });
Example #4
0
      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);
      });
Example #5
0
 it('should be a new array', () => {
   registry.addCommand('test0', NULL_COMMAND);
   registry.addCommand('test1', NULL_COMMAND);
   let cmds = registry.listCommands();
   cmds.push('test2');
   expect(registry.listCommands()).to.deep.equal(['test0', 'test1']);
 });
Example #6
0
 it('should register partial and exact matches', () => {
   let count1 = 0;
   let count2 = 0;
   registry.addCommand('test1', {
     execute: () => { count1++; }
   });
   registry.addCommand('test2', {
     execute: () => { count2++; }
   });
   registry.addKeyBinding({
     keys: ['Ctrl S'],
     selector: `#${elem.id}`,
     command: 'test1'
   });
   registry.addKeyBinding({
     keys: ['Ctrl S', 'Ctrl D'],
     selector: `#${elem.id}`,
     command: 'test2'
   });
   let event1 = generate('keydown', { keyCode: 83, ctrlKey: true });
   let event2 = generate('keydown', { keyCode: 68, ctrlKey: true });
   expect(count1).to.equal(0);
   expect(count2).to.equal(0);
   elem.dispatchEvent(event1);
   expect(count1).to.equal(0);
   expect(count2).to.equal(0);
   elem.dispatchEvent(event2);
   expect(count1).to.equal(0);
   expect(count2).to.equal(1);
 });
Example #7
0
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
  });
}
Example #8
0
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;
  }
}
      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);
      });
Example #10
0
  before(() => {
    commands = new CommandRegistry();
    bkoMenu = new BkoMenu({ commands });

    commands.addCommand('test', { execute: () => {} });
    bkoMenu.addItem({command: 'test', submenu: bkoMenu, type: 'submenu'});
  });