Example #1
0
/**
 * Create a launcher for a given filebrowser widget.
 */
function createLauncher(commands: CommandRegistry, browser: FileBrowser): Promise<Launcher> {
  const { model } = browser;

  return commands.execute('launcher:create', { cwd: model.path })
    .then((launcher: Launcher) => {
      model.pathChanged.connect(() => { launcher.cwd = model.path; }, launcher);
      return launcher;
    });
}
Example #2
0
 it('should reject if the command throws an error', (done) => {
   let cmd = {
     execute: (args: JSONObject) => { throw new Error(''); },
   };
   registry.addCommand('test', cmd);
   registry.execute('test').catch(() => {
     done();
   });
 });
Example #3
0
 it('should execute a specific command', () => {
   let called = false;
   let cmd = {
     execute: (args: JSONObject) => { called = true; },
   };
   registry.addCommand('test', cmd);
   registry.execute('test');
   expect(called).to.equal(true);
 });
Example #4
0
 it('should resolve with the result of the command', (done) => {
   let cmd = {
     execute: (args: JSONObject) => { return args; },
   };
   registry.addCommand('test', cmd);
   registry.execute('test', { foo: 12 }).then(result => {
     expect(result).to.deep.equal({ foo: 12 });
     done();
   });
 });
Example #5
0
 it('should be emitted when a command is executed', () => {
   let called = false;
   registry.addCommand('test', NULL_COMMAND);
   registry.commandExecuted.connect((reg, args) => {
     expect(reg).to.equal(registry);
     expect(args.id).to.equal('test');
     expect(args.args).to.deep.equal({});
     expect(args.result).to.be.an.instanceof(Promise);
     called = true;
   });
   registry.execute('test');
   expect(called).to.equal(true);
 });
Example #6
0
 execute: args => {
   let widget = tracker.currentWidget;
   if (!widget) {
     return;
   }
   let options: JSONObject = {
     path: widget.context.path,
     preferredLanguage: widget.context.model.defaultKernelLanguage,
     activate: args['activate']
   };
   return commands.execute('console:create', options)
     .then(id => { sessionIdProperty.set(widget, id); });
 },
Example #7
0
 execute: args => {
   let widget = tracker.currentWidget;
   if (!widget) {
     return;
   }
   // Get the session id.
   let id = sessionIdProperty.get(widget);
   if (!id) {
     return;
   }
   // Get the selected code from the editor.
   const editor = widget.editor;
   const selection = editor.getSelection();
   const start = editor.getOffsetAt(selection.start);
   const end = editor.getOffsetAt(selection.end);
   const options: JSONObject = {
     id,
     code: editor.model.value.text.substring(start, end),
     activate: args['activate']
   };
   return commands.execute('console:inject', options);
 },
Example #8
0
 recover(() => {
   commands.execute(recovery);
 });
Example #9
0
 execute: () => {
   if (nbWidget.content.activeCell.model.type === 'code') {
     return commands.execute(cmdIds.select);
   }
 }
Example #10
0
 onClick: () => {
   commands.execute(id);
   button.node.blur();
 },