@@ -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' ;
@@ -242,16 +244,22 @@ const menuSpacer: JupyterFrontEndPlugin<void> = {
242
244
243
245
/**
244
246
* 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.
245
252
*/
246
253
const pages : JupyterFrontEndPlugin < void > = {
247
254
id : '@jupyter-notebook/application-extension:pages' ,
248
255
autoStart : true ,
249
256
requires : [ ITranslator ] ,
250
- optional : [ ICommandPalette ] ,
257
+ optional : [ ICommandPalette , IFileBrowserCommands ] ,
251
258
activate : (
252
259
app : JupyterFrontEnd ,
253
260
translator : ITranslator ,
254
- palette : ICommandPalette | null
261
+ palette : ICommandPalette | null ,
262
+ fileBrowserCommands : null
255
263
) : void => {
256
264
const trans = translator . load ( 'notebook' ) ;
257
265
const baseUrl = PageConfig . getBaseUrl ( ) ;
@@ -263,7 +271,7 @@ const pages: JupyterFrontEndPlugin<void> = {
263
271
}
264
272
} ) ;
265
273
266
- if ( ! app . commands . isVisible ( " filebrowser:toggle-main" ) ) {
274
+ if ( ! app . commands . isVisible ( ' filebrowser:toggle-main' ) ) {
267
275
app . commands . addCommand ( CommandIDs . openTree , {
268
276
label : trans . __ ( 'File Browser' ) ,
269
277
execute : ( ) => {
@@ -273,9 +281,15 @@ const pages: JupyterFrontEndPlugin<void> = {
273
281
}
274
282
275
283
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
+ }
279
293
}
280
294
}
281
295
} ;
0 commit comments