From ab2e32224b8d3bd1b5c36c155089c33eb73127bc Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Fri, 27 Jun 2025 18:20:07 +0200 Subject: [PATCH 01/11] override new directory command for drive browser --- schema/drives-file-browser.json | 17 ++++++++++++++++- src/plugins/driveBrowserPlugin.ts | 18 ++++++++++++++++-- src/token.ts | 1 + 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/schema/drives-file-browser.json b/schema/drives-file-browser.json index 5ec33a1..ae71329 100644 --- a/schema/drives-file-browser.json +++ b/schema/drives-file-browser.json @@ -11,7 +11,7 @@ }, { "name": "new-directory", - "command": "filebrowser:create-new-directory", + "command": "drives:create-new-directory", "label": "", "rank": 10 }, @@ -36,6 +36,21 @@ } ] }, + "jupyter.lab.menus": { + "context": [ + { + "command": "filebrowser:create-new-directory", + "selector": ".jp-DirListing-content", + "rank": 55, + "disabled": true + }, + { + "command": "drives:create-new-directory", + "selector": ".jp-DirListing-content", + "rank": 55 + } + ] + }, "jupyter.lab.setting-icon": "jupyter-drives:drive-browser", "jupyter.lab.setting-icon-label": "Drive Browser", "type": "object", diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 01ba119..1578674 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -22,7 +22,8 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry'; import { filterIcon, FilenameSearcher, - IScore + IScore, + newFolderIcon } from '@jupyterlab/ui-components'; import { CommandRegistry } from '@lumino/commands'; import { Widget } from '@lumino/widgets'; @@ -148,8 +149,9 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { ); const updateVisibility = () => { - // Visibility of command changed. + // Visibility of context menu and toolbar commands changed. app.commands.notifyCommandChanged(CommandIDs.createNewDrive); + app.commands.notifyCommandChanged(CommandIDs.createNewDirectory); }; // Listen for path changes. @@ -370,5 +372,17 @@ namespace Private { icon: filterIcon.bindprops({ stylesheet: 'menuItem' }), label: 'Toggle File Filter' }); + + app.commands.addCommand(CommandIDs.createNewDirectory, { + isVisible: () => { + return browser.model.path !== 's3:'; + }, + execute: () => { + console.log('NEW COMMAND DIR'); + app.commands.execute('filebrowser:create-new-directory'); + }, + icon: newFolderIcon.bindprops({ stylesheet: 'menuItem' }), + label: 'New Folder' + }); } } diff --git a/src/token.ts b/src/token.ts index d5842f2..8444a2b 100644 --- a/src/token.ts +++ b/src/token.ts @@ -10,6 +10,7 @@ export namespace CommandIDs { export const createNewDrive = 'drives:create-new-drive'; export const launcher = 'launcher:create'; export const toggleFileFilter = 'drives:toggle-file-filter'; + export const createNewDirectory = 'drives:create-new-directory'; } /** From 3e0026a422d5ec1016ecb63253beabebaf20a3b7 Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Fri, 27 Jun 2025 18:25:40 +0200 Subject: [PATCH 02/11] override create new file command --- schema/drives-file-browser.json | 11 +++++++++++ src/plugins/driveBrowserPlugin.ts | 14 +++++++++++++- src/token.ts | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/schema/drives-file-browser.json b/schema/drives-file-browser.json index ae71329..57eb972 100644 --- a/schema/drives-file-browser.json +++ b/schema/drives-file-browser.json @@ -38,6 +38,17 @@ }, "jupyter.lab.menus": { "context": [ + { + "command": "filebrowser:create-new-file", + "selector": ".jp-DirListing-content", + "rank": 51, + "disabled": true + }, + { + "command": "drives:create-new-file", + "selector": ".jp-DirListing-content", + "rank": 51 + }, { "command": "filebrowser:create-new-directory", "selector": ".jp-DirListing-content", diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 1578674..df7d237 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -23,7 +23,8 @@ import { filterIcon, FilenameSearcher, IScore, - newFolderIcon + newFolderIcon, + fileIcon } from '@jupyterlab/ui-components'; import { CommandRegistry } from '@lumino/commands'; import { Widget } from '@lumino/widgets'; @@ -384,5 +385,16 @@ namespace Private { icon: newFolderIcon.bindprops({ stylesheet: 'menuItem' }), label: 'New Folder' }); + + app.commands.addCommand(CommandIDs.createNewFile, { + isVisible: () => { + return browser.model.path !== 's3:'; + }, + execute: () => { + app.commands.execute('filebrowser:create-new-file'); + }, + icon: fileIcon.bindprops({ stylesheet: 'menuItem' }), + label: 'New File' + }); } } diff --git a/src/token.ts b/src/token.ts index 8444a2b..fe4eaa8 100644 --- a/src/token.ts +++ b/src/token.ts @@ -11,6 +11,7 @@ export namespace CommandIDs { export const launcher = 'launcher:create'; export const toggleFileFilter = 'drives:toggle-file-filter'; export const createNewDirectory = 'drives:create-new-directory'; + export const createNewFile = 'drives:create-new-file'; } /** From ad6b127c8e34f093cd242fabd7a2a9cf26715642 Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Fri, 27 Jun 2025 18:51:17 +0200 Subject: [PATCH 03/11] override new notebook command --- schema/drives-file-browser.json | 13 +++++++++++++ src/plugins/driveBrowserPlugin.ts | 15 +++++++++++++-- src/token.ts | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/schema/drives-file-browser.json b/schema/drives-file-browser.json index 57eb972..48a02ab 100644 --- a/schema/drives-file-browser.json +++ b/schema/drives-file-browser.json @@ -59,6 +59,19 @@ "command": "drives:create-new-directory", "selector": ".jp-DirListing-content", "rank": 55 + }, + { + "command": "notebook:create-new", + "selector": ".jp-DirListing-content", + "args": { + "isContextMenu": true + }, + "disabled": true + }, + { + "command": "drives:create-new-notebook", + "selector": ".jp-DirListing-content", + "rank": 54 } ] }, diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index df7d237..99691eb 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -24,7 +24,8 @@ import { FilenameSearcher, IScore, newFolderIcon, - fileIcon + fileIcon, + notebookIcon } from '@jupyterlab/ui-components'; import { CommandRegistry } from '@lumino/commands'; import { Widget } from '@lumino/widgets'; @@ -379,7 +380,6 @@ namespace Private { return browser.model.path !== 's3:'; }, execute: () => { - console.log('NEW COMMAND DIR'); app.commands.execute('filebrowser:create-new-directory'); }, icon: newFolderIcon.bindprops({ stylesheet: 'menuItem' }), @@ -396,5 +396,16 @@ namespace Private { icon: fileIcon.bindprops({ stylesheet: 'menuItem' }), label: 'New File' }); + + app.commands.addCommand(CommandIDs.createNewNotebook, { + isVisible: () => { + return browser.model.path !== 's3:'; + }, + execute: () => { + app.commands.execute('notebook:create-new'); + }, + icon: notebookIcon.bindprops({ stylesheet: 'menuItem' }), + label: 'New Notebook' + }); } } diff --git a/src/token.ts b/src/token.ts index fe4eaa8..bd317f4 100644 --- a/src/token.ts +++ b/src/token.ts @@ -12,6 +12,7 @@ export namespace CommandIDs { export const toggleFileFilter = 'drives:toggle-file-filter'; export const createNewDirectory = 'drives:create-new-directory'; export const createNewFile = 'drives:create-new-file'; + export const createNewNotebook = 'drives:create-new-notebook'; } /** From cf52aca3378eee3eda947b8f2d00cdd5fa7b754c Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Fri, 27 Jun 2025 21:35:50 +0200 Subject: [PATCH 04/11] lint --- schema/drives-file-browser.json | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/schema/drives-file-browser.json b/schema/drives-file-browser.json index 48a02ab..30bd463 100644 --- a/schema/drives-file-browser.json +++ b/schema/drives-file-browser.json @@ -9,12 +9,6 @@ "label": "", "rank": 1 }, - { - "name": "new-directory", - "command": "drives:create-new-directory", - "label": "", - "rank": 10 - }, { "name": "uploader", "label": "", "rank": 20 }, { "name": "refresh", @@ -63,12 +57,12 @@ { "command": "notebook:create-new", "selector": ".jp-DirListing-content", - "args": { - "isContextMenu": true - }, + "args": { + "isContextMenu": true + }, "disabled": true }, - { + { "command": "drives:create-new-notebook", "selector": ".jp-DirListing-content", "rank": 54 From dd0c2fc515f2a8f216b20154aaaf227e7142a7de Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 2 Jul 2025 15:58:24 +0200 Subject: [PATCH 05/11] disabled new directory command at root level --- schema/drives-file-browser.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/schema/drives-file-browser.json b/schema/drives-file-browser.json index 30bd463..51067c4 100644 --- a/schema/drives-file-browser.json +++ b/schema/drives-file-browser.json @@ -9,6 +9,11 @@ "label": "", "rank": 1 }, + { + "name": "new-directory", + "command": "drives:create-new-directory", + "rank": 10 + }, { "name": "uploader", "label": "", "rank": 20 }, { "name": "refresh", @@ -26,7 +31,7 @@ "name": "new-drive", "command": "drives:create-new-drive", "label": "", - "rank": 50 + "rank": 10 } ] }, From 1bc3a1ea52640344a2cbbaa66460c18c5af4b36d Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 2 Jul 2025 16:42:32 +0200 Subject: [PATCH 06/11] change upload button visibility --- src/plugins/driveBrowserPlugin.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 99691eb..8a1c431 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -121,12 +121,10 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { restorer.add(driveBrowser, 'drive-file-browser'); } - toolbarRegistry.addFactory( - FILE_BROWSER_FACTORY, - 'uploader', - (fileBrowser: FileBrowser) => - new Uploader({ model: fileBrowser.model, translator }) - ); + const uploader = new Uploader({ model: driveBrowser.model, translator }); + toolbarRegistry.addFactory(FILE_BROWSER_FACTORY, 'uploader', () => { + return uploader; + }); toolbarRegistry.addFactory( FILE_BROWSER_FACTORY, @@ -152,6 +150,11 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { const updateVisibility = () => { // Visibility of context menu and toolbar commands changed. + if (driveBrowser.model.path !== 's3:') { + uploader.show(); + } else { + uploader.hide(); + } app.commands.notifyCommandChanged(CommandIDs.createNewDrive); app.commands.notifyCommandChanged(CommandIDs.createNewDirectory); }; From 8aebc1d959a8ba414698090950a28b2b5c63a06e Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 2 Jul 2025 17:01:02 +0200 Subject: [PATCH 07/11] disable launcher at root level --- src/plugins/driveBrowserPlugin.ts | 1 + src/plugins/launcherPlugin.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 8a1c431..46b4ef3 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -157,6 +157,7 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { } app.commands.notifyCommandChanged(CommandIDs.createNewDrive); app.commands.notifyCommandChanged(CommandIDs.createNewDirectory); + app.commands.notifyCommandChanged(CommandIDs.launcher); }; // Listen for path changes. diff --git a/src/plugins/launcherPlugin.ts b/src/plugins/launcherPlugin.ts index ca7e767..7d18c8f 100644 --- a/src/plugins/launcherPlugin.ts +++ b/src/plugins/launcherPlugin.ts @@ -44,6 +44,10 @@ function activate( commands.addCommand(CommandIDs.launcher, { label: trans.__('New Launcher'), icon: args => (args.toolbar ? addIcon : undefined), + isEnabled: () => { + const currentBrowser = factory?.tracker.currentWidget; + return currentBrowser?.model.path !== 's3:'; + }, execute: (args: ReadonlyPartialJSONObject) => { // get current file browser used const currentBrowser = factory?.tracker.currentWidget; From bf75dbab3bd8480e0d85fa4a038546cec8eb86a8 Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 2 Jul 2025 17:15:30 +0200 Subject: [PATCH 08/11] update toolbar buttons visibility on initial load --- src/plugins/driveBrowserPlugin.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 46b4ef3..e92a95f 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -148,6 +148,9 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { } ); + // Add commands + Private.addCommands(app, drive, driveBrowser); + const updateVisibility = () => { // Visibility of context menu and toolbar commands changed. if (driveBrowser.model.path !== 's3:') { @@ -162,9 +165,7 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { // Listen for path changes. driveBrowser.model.pathChanged.connect(updateVisibility); - - // Add commands - Private.addCommands(app, drive, driveBrowser); + updateVisibility(); // Connect the filebrowser toolbar to the settings registry for the plugin. setToolbar( From d300ebb6e82728553284ff07ccf432a6dcbe9f5f Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Thu, 3 Jul 2025 16:22:59 +0200 Subject: [PATCH 09/11] update new drive command rank --- schema/drives-file-browser.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema/drives-file-browser.json b/schema/drives-file-browser.json index 51067c4..55f3be1 100644 --- a/schema/drives-file-browser.json +++ b/schema/drives-file-browser.json @@ -31,7 +31,7 @@ "name": "new-drive", "command": "drives:create-new-drive", "label": "", - "rank": 10 + "rank": 5 } ] }, From 1e0cbf29e1acc5780af68e60864410a9525f0091 Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Thu, 3 Jul 2025 16:23:23 +0200 Subject: [PATCH 10/11] update min width of drive browser to fit all toolbar commands --- style/base.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/style/base.css b/style/base.css index eb58e6f..5c6483c 100644 --- a/style/base.css +++ b/style/base.css @@ -3,6 +3,10 @@ https://jupyterlab.readthedocs.io/en/stable/developer/css.html */ +.drive-browser { + min-width: 285px !important; +} + li { list-style-type: none; } From bd3e4688333c9bc0d9fea6027a7c15a37ebc992b Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Thu, 3 Jul 2025 16:23:46 +0200 Subject: [PATCH 11/11] update commands visibility --- src/plugins/driveBrowserPlugin.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index e92a95f..a919b95 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -113,6 +113,7 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { driveBrowser.title.icon = driveBrowserIcon; driveBrowser.title.caption = 'Drive File Browser'; driveBrowser.id = 'drive-file-browser'; + driveBrowser.addClass('drive-browser'); void Private.restoreBrowser(driveBrowser, commands, router, tree, labShell); @@ -154,9 +155,9 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { const updateVisibility = () => { // Visibility of context menu and toolbar commands changed. if (driveBrowser.model.path !== 's3:') { - uploader.show(); + uploader.enabled = true; } else { - uploader.hide(); + uploader.enabled = false; } app.commands.notifyCommandChanged(CommandIDs.createNewDrive); app.commands.notifyCommandChanged(CommandIDs.createNewDirectory); @@ -335,7 +336,7 @@ namespace Private { browser: FileBrowser ): void { app.commands.addCommand(CommandIDs.createNewDrive, { - isVisible: () => { + isEnabled: () => { return browser.model.path === 's3:'; }, execute: async () => { @@ -363,7 +364,7 @@ namespace Private { app.contextMenu.addItem({ command: CommandIDs.createNewDrive, selector: '#drive-file-browser.jp-SidePanel .jp-DirListing-content', - rank: 100 + rank: 105 }); app.commands.addCommand(CommandIDs.toggleFileFilter, { @@ -381,7 +382,7 @@ namespace Private { }); app.commands.addCommand(CommandIDs.createNewDirectory, { - isVisible: () => { + isEnabled: () => { return browser.model.path !== 's3:'; }, execute: () => { @@ -392,7 +393,7 @@ namespace Private { }); app.commands.addCommand(CommandIDs.createNewFile, { - isVisible: () => { + isEnabled: () => { return browser.model.path !== 's3:'; }, execute: () => { @@ -403,7 +404,7 @@ namespace Private { }); app.commands.addCommand(CommandIDs.createNewNotebook, { - isVisible: () => { + isEnabled: () => { return browser.model.path !== 's3:'; }, execute: () => {