From 66f0256abebcbdfbe91a7cf436b362ea45a5caa1 Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Fri, 26 Sep 2025 19:28:25 +0200 Subject: [PATCH 1/2] update root level icons --- src/plugins/driveBrowserPlugin.ts | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 2d3fe78..494ef6e 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -196,6 +196,43 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { restorer.add(driveBrowser, 'drive-file-browser'); } + const updateRootIcons = () => { + const listing = driveBrowser.model; + + if (listing.items) { + // Get all items at root level + const rootItems = Array.from(listing.items()).filter(item => { + return driveBrowser.model.path === 's3:'; + }); + + rootItems.forEach(item => { + // Find the DOM element for this item + const itemElements = driveBrowser.node.querySelectorAll('li.jp-DirListing-item'); + itemElements.forEach(element => { + const itemName = element.querySelector('.jp-DirListing-itemText')?.textContent; + if (itemName === item.name) { + // Replace the icon + const iconElement = element.querySelector('.jp-DirListing-itemIcon'); + if (iconElement) { + iconElement.innerHTML = driveBrowserIcon.svgstr; + iconElement.classList.add('jp-icon', 'jp-icon-3', 'icon-selectable'); + } + } + }); + }); + } + }; + + driveBrowser.model.pathChanged.connect(() => { + setTimeout(updateRootIcons, 50); + }); + driveBrowser.model.refreshed.connect(() => { + setTimeout(updateRootIcons, 50); + }); + + // Initial update + setTimeout(updateRootIcons, 50); + // Register status bar widget if (statusBar) { const driveStatusWidget = new DriveStatusWidget(); From 361812bd08f6f8d70b70c805d2189abe1adfdbde Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Mon, 29 Sep 2025 17:44:43 +0200 Subject: [PATCH 2/2] refactor custom directory logic for drives --- src/contents.ts | 2 +- src/plugins/driveBrowserPlugin.ts | 47 ++++++++----------------------- 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/src/contents.ts b/src/contents.ts index 08f864a..8aa0640 100644 --- a/src/contents.ts +++ b/src/contents.ts @@ -302,7 +302,7 @@ export class Drive implements Contents.IDrive { mimetype: '', size: undefined, writable: true, - type: 'directory' + type: 'drive' }); } } catch (err) { diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 494ef6e..deb727d 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -162,7 +162,7 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { console.log( 'JupyterLab extension jupyter-drives:drives-file-browser is activated!' ); - const { commands } = app; + const { commands, docRegistry } = app; // create drive for drive file browser const drive = new Drive({ @@ -196,42 +196,17 @@ export const driveFileBrowser: JupyterFrontEndPlugin = { restorer.add(driveBrowser, 'drive-file-browser'); } - const updateRootIcons = () => { - const listing = driveBrowser.model; - - if (listing.items) { - // Get all items at root level - const rootItems = Array.from(listing.items()).filter(item => { - return driveBrowser.model.path === 's3:'; - }); - - rootItems.forEach(item => { - // Find the DOM element for this item - const itemElements = driveBrowser.node.querySelectorAll('li.jp-DirListing-item'); - itemElements.forEach(element => { - const itemName = element.querySelector('.jp-DirListing-itemText')?.textContent; - if (itemName === item.name) { - // Replace the icon - const iconElement = element.querySelector('.jp-DirListing-itemIcon'); - if (iconElement) { - iconElement.innerHTML = driveBrowserIcon.svgstr; - iconElement.classList.add('jp-icon', 'jp-icon-3', 'icon-selectable'); - } - } - }); - }); - } - }; - - driveBrowser.model.pathChanged.connect(() => { - setTimeout(updateRootIcons, 50); + // Registering the custom directory file type + docRegistry.addFileType({ + name: 'drive', + displayName: 'Drive', + contentType: 'directory', + fileFormat: 'json', + mimeTypes: ['text/directory'], + extensions: [], + icon: driveBrowserIcon, + pattern: '^' }); - driveBrowser.model.refreshed.connect(() => { - setTimeout(updateRootIcons, 50); - }); - - // Initial update - setTimeout(updateRootIcons, 50); // Register status bar widget if (statusBar) {