Skip to content

Commit

Permalink
Merge pull request #4757 from ian-r-rose/launcher_commands
Browse files Browse the repository at this point in the history
Refactor launcher to use CommandRegistry.
  • Loading branch information
afshin committed Jun 27, 2018
2 parents d72b2a7 + 8889d59 commit 23ff0c1
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 164 deletions.
31 changes: 17 additions & 14 deletions packages/console-extension/src/index.ts
Expand Up @@ -6,7 +6,7 @@ import {
} from '@jupyterlab/application';

import {
Dialog, ICommandPalette, InstanceTracker, showDialog
Dialog, IClientSession, ICommandPalette, InstanceTracker, showDialog
} from '@jupyterlab/apputils';

import {
Expand Down Expand Up @@ -164,11 +164,6 @@ function activateConsole(app: JupyterLab, mainMenu: IMainMenu, palette: ICommand
when: manager.ready
});

// The launcher callback.
let callback = (cwd: string, name: string) => {
return createConsole({ basePath: cwd, kernelPreference: { name }});
};

// Add a launcher item if the launcher is available.
if (launcher) {
manager.ready.then(() => {
Expand All @@ -178,19 +173,16 @@ function activateConsole(app: JupyterLab, mainMenu: IMainMenu, palette: ICommand
}
let baseUrl = PageConfig.getBaseUrl();
for (let name in specs.kernelspecs) {
let displayName = specs.kernelspecs[name].display_name;
let rank = name === specs.default ? 0 : Infinity;
let kernelIconUrl = specs.kernelspecs[name].resources['logo-64x64'];
if (kernelIconUrl) {
let index = kernelIconUrl.indexOf('kernelspecs');
kernelIconUrl = baseUrl + kernelIconUrl.slice(index);
}
launcher.add({
displayName,
command: CommandIDs.create,
args: { isLauncher: true, kernelPreference: { name } },
category: 'Console',
name,
iconClass: 'jp-CodeConsoleIcon',
callback,
rank,
kernelIconUrl
});
Expand Down Expand Up @@ -265,9 +257,20 @@ function activateConsole(app: JupyterLab, mainMenu: IMainMenu, palette: ICommand

command = CommandIDs.create;
commands.addCommand(command, {
label: args => args['isPalette'] ? 'New Console' : 'Console',
execute: (args: Partial<ConsolePanel.IOptions>) => {
let basePath = args.basePath || browserFactory.defaultBrowser.model.path;
label: args => {
if (args['isPalette']) {
return 'New Console';
} else if (args['isLauncher'] && args['kernelPreference']) {
const kernelPreference =
args['kernelPreference'] as IClientSession.IKernelPreference;
return manager.specs.kernelspecs[kernelPreference.name].display_name;
}
return 'Console';
},
iconClass: 'jp-CodeConsoleIcon',
execute: args => {
let basePath = args['basePath'] as string || args['cwd'] as string ||
browserFactory.defaultBrowser.model.path;
return createConsole({ basePath, ...args });
}
});
Expand Down
11 changes: 5 additions & 6 deletions packages/fileeditor-extension/src/index.ts
Expand Up @@ -376,20 +376,19 @@ function activate(app: JupyterLab, consoleTracker: IConsoleTracker, editorServic
commands.addCommand(CommandIDs.createNew, {
label: 'Text File',
caption: 'Create a new text file',
execute: () => {
let cwd = browserFactory.defaultBrowser.model.path;
return createNew(cwd);
iconClass: EDITOR_ICON_CLASS,
execute: args => {
let cwd = args['cwd'] || browserFactory.defaultBrowser.model.path;
return createNew(cwd as string);
}
});

// Add a launcher item if the launcher is available.
if (launcher) {
launcher.add({
displayName: 'Text Editor',
command: CommandIDs.createNew,
category: 'Other',
rank: 1,
iconClass: EDITOR_ICON_CLASS,
callback: createNew
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/launcher-extension/src/index.ts
Expand Up @@ -70,7 +70,7 @@ function activate(app: JupyterLab, palette: ICommandPalette): ILauncher {
const callback = (item: Widget) => {
shell.addToMainArea(item, { ref: id });
};
const launcher = new Launcher({ cwd, callback });
const launcher = new Launcher({ cwd, callback, commands });

launcher.model = model;
launcher.title.label = 'Launcher';
Expand Down
1 change: 1 addition & 0 deletions packages/launcher/package.json
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"@jupyterlab/apputils": "^0.16.3",
"@phosphor/algorithm": "^1.1.2",
"@phosphor/commands": "^1.5.0",
"@phosphor/coreutils": "^1.3.0",
"@phosphor/disposable": "^1.1.2",
"@phosphor/properties": "^1.1.2",
Expand Down

0 comments on commit 23ff0c1

Please sign in to comment.