From f614f7c6387cc7da82e0307b70e10593b2cd6bff Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Thu, 24 Oct 2024 18:10:02 +0200 Subject: [PATCH] Move handling of the file browser settings to a separate plugin, enable file browser single click navigation (#7481) * Move handling of the file browser settings to a separate plugin * fix typo * optional settingregistry * remove upstream filebrowser plugin * fix file actions buttons * hold ctrl * update changelog * wording * remove console.log * fix comments --- CHANGELOG.md | 4 +- app/package.json | 1 - packages/tree-extension/src/index.ts | 75 +++++++++++++++++++++------- ui-tests/test/filebrowser.spec.ts | 2 + 4 files changed, 61 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 412836d758..f99316278b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,11 +40,13 @@ The file browser now: - supports resizing the columns and remembers the column sizes after reloading JupyterLab - supports uploading folders by drag-and-drop -- supports navigation with a single click (opt-in) +- supports navigation with a single click - adds a file filter collapsed by default (funnel icon) ![a screenshot showing that it's now possible to resize the file browser columns](https://github.com/user-attachments/assets/b0d9cd0a-2828-43f7-a922-e8b271e5f7fc) +In Jupyter Notebook, the single click navigation is enabled by default. If you would like to disable it to get the same experience as in JupyterLab, go to `Settings → File Browser` and make sure "Navigate files and directories with single click" is unchecked. + ### Improved kernel and server interactions The previous release enabled connecting to external kernels, such as those spawned by a third-party application like Blender. In this release the kernel selector dialog was improved to also show the external kernels. diff --git a/app/package.json b/app/package.json index b8c509a150..e64523e9fe 100644 --- a/app/package.json +++ b/app/package.json @@ -310,7 +310,6 @@ "@jupyterlab/filebrowser-extension:file-upload-status", "@jupyterlab/filebrowser-extension:open-with", "@jupyterlab/filebrowser-extension:search", - "@jupyterlab/filebrowser-extension:settings", "@jupyterlab/filebrowser-extension:share-file" ], "@jupyter-notebook/tree-extension": true, diff --git a/packages/tree-extension/src/index.ts b/packages/tree-extension/src/index.ts index 2fb092bfa2..da80df842e 100644 --- a/packages/tree-extension/src/index.ts +++ b/packages/tree-extension/src/index.ts @@ -170,6 +170,9 @@ const fileActions: JupyterFrontEndPlugin = { selectionChanged.emit(void 0); }; }); + browser.model.pathChanged.connect(() => { + selectionChanged.emit(void 0); + }); // Create a toolbar item that adds buttons to the file browser toolbar // to perform actions on the files @@ -186,6 +189,58 @@ const fileActions: JupyterFrontEndPlugin = { }, }; +/** + * A plugin to set the default file browser settings. + */ +const fileBrowserSettings: JupyterFrontEndPlugin = { + id: '@jupyter-notebook/tree-extension:settings', + description: 'Set up the default file browser settings', + requires: [IDefaultFileBrowser], + optional: [ISettingRegistry], + autoStart: true, + activate: ( + app: JupyterFrontEnd, + browser: IDefaultFileBrowser, + settingRegistry: ISettingRegistry | null + ) => { + // Default config for notebook. + // This is a different set of defaults than JupyterLab. + const defaultFileBrowserConfig = { + navigateToCurrentDirectory: false, + singleClickNavigation: true, + showLastModifiedColumn: true, + showFileSizeColumn: true, + showHiddenFiles: false, + showFileCheckboxes: true, + sortNotebooksFirst: true, + showFullPath: false, + }; + + // Apply defaults on plugin activation + let key: keyof typeof defaultFileBrowserConfig; + for (key in defaultFileBrowserConfig) { + browser[key] = defaultFileBrowserConfig[key]; + } + + if (settingRegistry) { + void settingRegistry.load(FILE_BROWSER_PLUGIN_ID).then((settings) => { + function onSettingsChanged(settings: ISettingRegistry.ISettings): void { + let key: keyof typeof defaultFileBrowserConfig; + for (key in defaultFileBrowserConfig) { + const value = settings.get(key).user as boolean; + // only set the setting if it is defined by the user + if (value !== undefined) { + browser[key] = value; + } + } + } + settings.changed.connect(onSettingsChanged); + onSettingsChanged(settings); + }); + } + }, +}; + /** * A plugin to add the file filter toggle command to the palette */ @@ -360,25 +415,6 @@ const notebookTreeWidget: JupyterFrontEndPlugin = { nbTreeWidget.tabBar.addTab(running.title); } - const settings = settingRegistry.load(FILE_BROWSER_PLUGIN_ID); - Promise.all([settings, app.restored]) - .then(([settings]) => { - // Set Notebook 7 defaults if there is no user setting override - [ - 'showFileCheckboxes', - 'showFileSizeColumn', - 'sortNotebooksFirst', - 'showFullPath', - ].forEach((setting) => { - if (settings.user[setting] === undefined) { - void settings.set(setting, true); - } - }); - }) - .catch((reason: Error) => { - console.error(reason.message); - }); - app.shell.add(nbTreeWidget, 'main', { rank: 100 }); // add a separate tab for each setting editor @@ -419,6 +455,7 @@ const notebookTreeWidget: JupyterFrontEndPlugin = { const plugins: JupyterFrontEndPlugin[] = [ createNew, fileActions, + fileBrowserSettings, fileFilterCommand, loadPlugins, openFileBrowser, diff --git a/ui-tests/test/filebrowser.spec.ts b/ui-tests/test/filebrowser.spec.ts index df99fc3f5d..dd10752565 100644 --- a/ui-tests/test/filebrowser.spec.ts +++ b/ui-tests/test/filebrowser.spec.ts @@ -20,6 +20,7 @@ test.describe('File Browser', () => { test('Select one folder', async ({ page, tmpPath }) => { await page.filebrowser.refresh(); + await page.keyboard.down('Control'); await page.getByText('folder1').last().click(); const toolbar = page.getByRole('toolbar'); @@ -31,6 +32,7 @@ test.describe('File Browser', () => { test('Select one file', async ({ page, tmpPath }) => { await page.filebrowser.refresh(); + await page.keyboard.down('Control'); await page.getByText('empty.ipynb').last().click(); const toolbar = page.getByRole('toolbar');