Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a command to enable the extension manager #6200

Merged
merged 8 commits into from May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/extensionmanager-extension/package.json
Expand Up @@ -35,7 +35,8 @@
"@jupyterlab/application": "^1.0.0-alpha.6",
"@jupyterlab/apputils": "^1.0.0-alpha.6",
"@jupyterlab/coreutils": "^3.0.0-alpha.6",
"@jupyterlab/extensionmanager": "^1.0.0-alpha.6"
"@jupyterlab/extensionmanager": "^1.0.0-alpha.6",
"@jupyterlab/mainmenu": "^1.0.0-alpha.6"
},
"devDependencies": {
"rimraf": "~2.6.2",
Expand Down
75 changes: 27 additions & 48 deletions packages/extensionmanager-extension/src/index.ts
Expand Up @@ -8,23 +8,19 @@ import {
JupyterFrontEndPlugin
} from '@jupyterlab/application';

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

import { ISettingRegistry } from '@jupyterlab/coreutils';

import { IMainMenu } from '@jupyterlab/mainmenu';

import { ExtensionView } from '@jupyterlab/extensionmanager';

/**
* IDs of the commands added by this extension.
*/
namespace CommandIDs {
export const enable = 'extensionmanager:enable';

export const hide = 'extensionmanager:hide-main';

export const show = 'extensionmanager:activate-main';

export const toggle = 'extensionmanager:toggle-main';
export const toggle = 'extensionmanager:toggle';
}

/**
Expand All @@ -34,17 +30,19 @@ const plugin: JupyterFrontEndPlugin<void> = {
id: '@jupyterlab/extensionmanager-extension:plugin',
autoStart: true,
requires: [ISettingRegistry],
optional: [ILabShell, ILayoutRestorer],
optional: [ILabShell, ILayoutRestorer, IMainMenu, ICommandPalette],
activate: async (
app: JupyterFrontEnd,
registry: ISettingRegistry,
labShell: ILabShell | null,
restorer: ILayoutRestorer | null
restorer: ILayoutRestorer | null,
mainMenu: IMainMenu | null,
palette: ICommandPalette | null
) => {
const settings = await registry.load(plugin.id);
let enabled = settings.composite['enabled'] === true;

const { serviceManager, shell } = app;
const { commands, serviceManager, shell } = app;
let view: ExtensionView | undefined;

const createView = () => {
Expand Down Expand Up @@ -82,47 +80,28 @@ const plugin: JupyterFrontEndPlugin<void> = {
});
});

addCommands(app, view, labShell);
}
};

/**
* Add the main file view commands to the application's command registry.
*/
function addCommands(
app: JupyterFrontEnd,
view: ExtensionView,
labShell: ILabShell | null
): void {
const { commands, shell } = app;

commands.addCommand(CommandIDs.show, {
label: 'Show Extension Manager',
execute: () => {
shell.activateById(view.id);
}
});
commands.addCommand(CommandIDs.toggle, {
label: 'Enable Extension Manager (experimental)',
execute: () => {
if (registry) {
registry.set(plugin.id, 'enabled', !enabled);
}
},
isToggled: () => enabled,
isEnabled: () => serviceManager.builder.isAvailable
});

commands.addCommand(CommandIDs.hide, {
execute: () => {
if (labShell && !view.isHidden) {
labShell.collapseLeft();
}
const category = 'Extension Manager';
const command = CommandIDs.toggle;
if (palette) {
palette.addItem({ command, category });
}
});

commands.addCommand(CommandIDs.toggle, {
execute: () => {
if (view.isHidden) {
return commands.execute(CommandIDs.show, undefined);
} else {
return commands.execute(CommandIDs.hide, undefined);
}
if (mainMenu) {
mainMenu.settingsMenu.addGroup([{ command }], 100);
}
});

// TODO: Also add to command palette.
}
}
};

/**
* Export the plugin as the default.
Expand Down
3 changes: 3 additions & 0 deletions packages/extensionmanager-extension/tsconfig.json
Expand Up @@ -17,6 +17,9 @@
},
{
"path": "../extensionmanager"
},
{
"path": "../mainmenu"
}
]
}