Skip to content

Commit 441b957

Browse files
committed
Wait for the file browser commands from JupyterLab to be fully created before create a new one
1 parent 7c68346 commit 441b957

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';
@@ -242,16 +244,22 @@ const menuSpacer: JupyterFrontEndPlugin<void> = {
242244

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

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

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

0 commit comments

Comments
 (0)