@@ -25,6 +25,8 @@ import { IDocumentManager, renameDialog } from '@jupyterlab/docmanager';
25
25
26
26
import { DocumentWidget } from '@jupyterlab/docregistry' ;
27
27
28
+ import { IFileBrowserCommands } from '@jupyterlab/filebrowser' ;
29
+
28
30
import { IMainMenu } from '@jupyterlab/mainmenu' ;
29
31
30
32
import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
@@ -243,16 +245,22 @@ const menuSpacer: JupyterFrontEndPlugin<void> = {
243
245
244
246
/**
245
247
* 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.
246
253
*/
247
254
const pages : JupyterFrontEndPlugin < void > = {
248
255
id : '@jupyter-notebook/application-extension:pages' ,
249
256
autoStart : true ,
250
257
requires : [ ITranslator ] ,
251
- optional : [ ICommandPalette ] ,
258
+ optional : [ ICommandPalette , IFileBrowserCommands ] ,
252
259
activate : (
253
260
app : JupyterFrontEnd ,
254
261
translator : ITranslator ,
255
- palette : ICommandPalette | null
262
+ palette : ICommandPalette | null ,
263
+ fileBrowserCommands : null
256
264
) : void => {
257
265
const trans = translator . load ( 'notebook' ) ;
258
266
const baseUrl = PageConfig . getBaseUrl ( ) ;
@@ -264,7 +272,7 @@ const pages: JupyterFrontEndPlugin<void> = {
264
272
}
265
273
} ) ;
266
274
267
- if ( ! app . commands . isVisible ( " filebrowser:toggle-main" ) ) {
275
+ if ( ! app . commands . isVisible ( ' filebrowser:toggle-main' ) ) {
268
276
app . commands . addCommand ( CommandIDs . openTree , {
269
277
label : trans . __ ( 'File Browser' ) ,
270
278
execute : ( ) => {
@@ -274,9 +282,15 @@ const pages: JupyterFrontEndPlugin<void> = {
274
282
}
275
283
276
284
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
+ }
280
294
}
281
295
}
282
296
} ;
0 commit comments