Skip to content

Commit 375ebd3

Browse files
committed
Wait for the file browser commands from JupyterLab to be fully created before create a new one
1 parent 8559a4d commit 375ebd3

File tree

1 file changed

+20
-6
lines changed
  • packages/application-extension/src

1 file changed

+20
-6
lines changed

packages/application-extension/src/index.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { IDocumentManager, renameDialog } from '@jupyterlab/docmanager';
2525

2626
import { DocumentWidget } from '@jupyterlab/docregistry';
2727

28+
import { IFileBrowserCommands } from '@jupyterlab/filebrowser';
29+
2830
import { IMainMenu } from '@jupyterlab/mainmenu';
2931

3032
import { ISettingRegistry } from '@jupyterlab/settingregistry';
@@ -243,16 +245,22 @@ const menuSpacer: JupyterFrontEndPlugin<void> = {
243245

244246
/**
245247
* Add commands to open the tree and running pages.
248+
*
249+
* ## NOTES:
250+
* The optional token IFileBrowserCommands is useful to ensure the corresponding
251+
* plugin has been activated. Otherwise this plugin can be activated before the commands
252+
* 'toggle-main' has been added, which create a duplicated entry.
246253
*/
247254
const pages: JupyterFrontEndPlugin<void> = {
248255
id: '@jupyter-notebook/application-extension:pages',
249256
autoStart: true,
250257
requires: [ITranslator],
251-
optional: [ICommandPalette],
258+
optional: [ICommandPalette, IFileBrowserCommands],
252259
activate: (
253260
app: JupyterFrontEnd,
254261
translator: ITranslator,
255-
palette: ICommandPalette | null
262+
palette: ICommandPalette | null,
263+
fileBrowserCommands: null
256264
): void => {
257265
const trans = translator.load('notebook');
258266
const baseUrl = PageConfig.getBaseUrl();
@@ -264,7 +272,7 @@ const pages: JupyterFrontEndPlugin<void> = {
264272
}
265273
});
266274

267-
if (!app.commands.isVisible("filebrowser:toggle-main")) {
275+
if (!app.commands.isVisible('filebrowser:toggle-main')) {
268276
app.commands.addCommand(CommandIDs.openTree, {
269277
label: trans.__('File Browser'),
270278
execute: () => {
@@ -274,9 +282,15 @@ const pages: JupyterFrontEndPlugin<void> = {
274282
}
275283

276284
if (palette) {
277-
[CommandIDs.openLab, CommandIDs.openTree].forEach(command => {
278-
palette.addItem({ command, category: 'View' });
279-
});
285+
palette.addItem({ command: CommandIDs.openLab, category: 'View' });
286+
if (!app.commands.isVisible('filebrowser:toggle-main')) {
287+
palette.addItem({ command: CommandIDs.openTree, category: 'View' });
288+
} else {
289+
palette.addItem({
290+
command: 'filebrowser:toggle-main',
291+
category: 'View'
292+
});
293+
}
280294
}
281295
}
282296
};

0 commit comments

Comments
 (0)