Skip to content

Commit

Permalink
Merge pull request #6200 from jtpio/toggle-ext-manager
Browse files Browse the repository at this point in the history
Add a command to enable the extension manager
  • Loading branch information
aschlaep committed May 21, 2019
2 parents 594076f + edce025 commit 7c05352
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 49 deletions.
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"
}
]
}

0 comments on commit 7c05352

Please sign in to comment.