Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2524344

Browse files
committedJan 10, 2023
File Browser menu entry execution depends on the current page ('tree' or other)
1 parent 441b957 commit 2524344

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed
 

‎packages/application-extension/src/index.ts

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

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

28-
import { IFileBrowserCommands } from '@jupyterlab/filebrowser';
29-
3028
import { IMainMenu } from '@jupyterlab/mainmenu';
3129

3230
import { ISettingRegistry } from '@jupyterlab/settingregistry';
@@ -42,6 +40,8 @@ import {
4240
SidePanelPalette
4341
} from '@jupyter-notebook/application';
4442

43+
import { CommandIDs as filebrowserCommandIDs } from '@jupyter-notebook/tree';
44+
4545
import { jupyterIcon } from '@jupyter-notebook/ui-components';
4646

4747
import { PromiseDelegate } from '@lumino/coreutils';
@@ -254,12 +254,11 @@ const pages: JupyterFrontEndPlugin<void> = {
254254
id: '@jupyter-notebook/application-extension:pages',
255255
autoStart: true,
256256
requires: [ITranslator],
257-
optional: [ICommandPalette, IFileBrowserCommands],
257+
optional: [ICommandPalette],
258258
activate: (
259259
app: JupyterFrontEnd,
260260
translator: ITranslator,
261-
palette: ICommandPalette | null,
262-
fileBrowserCommands: null
261+
palette: ICommandPalette | null
263262
): void => {
264263
const trans = translator.load('notebook');
265264
const baseUrl = PageConfig.getBaseUrl();
@@ -270,26 +269,22 @@ const pages: JupyterFrontEndPlugin<void> = {
270269
window.open(`${baseUrl}lab`);
271270
}
272271
});
272+
const page = PageConfig.getOption('notebookPage');
273273

274-
if (!app.commands.isVisible('filebrowser:toggle-main')) {
275-
app.commands.addCommand(CommandIDs.openTree, {
276-
label: trans.__('File Browser'),
277-
execute: () => {
274+
app.commands.addCommand(CommandIDs.openTree, {
275+
label: trans.__('File Browser'),
276+
execute: () => {
277+
if (page === 'tree') {
278+
app.commands.execute(filebrowserCommandIDs.activate);
279+
} else {
278280
window.open(`${baseUrl}tree`);
279281
}
280-
});
281-
}
282+
}
283+
});
282284

283285
if (palette) {
284286
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-
}
287+
palette.addItem({ command: CommandIDs.openTree, category: 'View' });
293288
}
294289
}
295290
};

‎packages/tree-extension/src/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ import {
3232

3333
import { Menu, MenuBar } from '@lumino/widgets';
3434

35-
import { NotebookTreeWidget, INotebookTree } from '@jupyter-notebook/tree';
35+
import {
36+
CommandIDs,
37+
NotebookTreeWidget,
38+
INotebookTree
39+
} from '@jupyter-notebook/tree';
3640

3741
/**
3842
* The file browser factory.
@@ -107,7 +111,7 @@ const openFileBrowser: JupyterFrontEndPlugin<void> = {
107111
factory: IFileBrowserFactory
108112
) => {
109113
const { commands } = app;
110-
commands.addCommand('filebrowser:activate', {
114+
commands.addCommand(CommandIDs.activate, {
111115
execute: args => {
112116
const { defaultBrowser: browser } = factory;
113117
notebookTree.currentWidget = browser;

‎packages/tree/src/notebook-tree.ts

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { TabPanel } from '@lumino/widgets';
44

55
import { INotebookTree } from './token';
66

7+
/**
8+
* The namespace for command IDs.
9+
*/
10+
export declare namespace CommandIDs {
11+
// The command to activate the filebrowser widget in tree view.
12+
const activate = 'filebrowser:activate';
13+
}
14+
715
/**
816
* The widget added in main area of the tree view.
917
*/

0 commit comments

Comments
 (0)
Please sign in to comment.