Skip to content

Commit 2e5bbfe

Browse files
committed
Better implementation
1 parent 4d61652 commit 2e5bbfe

File tree

1 file changed

+29
-38
lines changed

1 file changed

+29
-38
lines changed

src/plugins/driveBrowserPlugin.ts

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
JupyterFrontEnd,
66
JupyterFrontEndPlugin
77
} from '@jupyterlab/application';
8+
import { IDocumentWidgetOpener } from '@jupyterlab/docmanager';
89
import { IStatusBar } from '@jupyterlab/statusbar';
910
import {
1011
IFileBrowserFactory,
@@ -46,8 +47,7 @@ class DriveStatusWidget extends Widget {
4647
constructor() {
4748
super();
4849
this.addClass('jp-drive-status-widget');
49-
this.node.textContent = 'Drives: Ready';
50-
this._currentPath = '';
50+
this.node.textContent = '';
5151
this._isLoading = false;
5252
}
5353

@@ -58,18 +58,16 @@ class DriveStatusWidget extends Widget {
5858
/**
5959
* Update status when loading a directory or file
6060
*/
61-
setLoading(path: string, type: 'directory' | 'file' = 'directory') {
62-
console.log('[DEBUG] Setting loading:', path, 'type:', type);
61+
setLoading(path: string, type: string) {
6362
this._isLoading = true;
64-
this._currentPath = path;
6563

6664
if (type === 'directory') {
6765
const displayPath =
6866
path === '' ? 'Root' : path.split('/').pop() || 'Directory';
69-
this.node.textContent = `Drives: Opening ${displayPath}...`;
67+
this.updateStatus(displayPath);
7068
} else {
7169
const fileName = path.split('/').pop() || 'File';
72-
this.node.textContent = `Drives: Opening ${fileName}...`;
70+
this.updateStatus(fileName);
7371
}
7472

7573
this.addClass('jp-drive-status-loading');
@@ -78,26 +76,11 @@ class DriveStatusWidget extends Widget {
7876
/**
7977
* Clear loading state and show current status
8078
*/
81-
setLoaded(path: string, type: 'directory' | 'file' = 'directory') {
79+
setLoaded(path?: string) {
8280
this._isLoading = false;
83-
this._currentPath = path;
8481
this.removeClass('jp-drive-status-loading');
8582

86-
if (type === 'directory') {
87-
const displayPath =
88-
path === '' ? 'Root' : path.split('/').pop() || 'Directory';
89-
this.node.textContent = `Drives: ${displayPath}`;
90-
} else {
91-
const fileName = path.split('/').pop() || 'File';
92-
this.node.textContent = `Drives: ${fileName}`;
93-
}
94-
}
95-
96-
/**
97-
* Get current path
98-
*/
99-
get currentPath(): string {
100-
return this._currentPath;
83+
this.updateStatus('');
10184
}
10285

10386
/**
@@ -107,7 +90,6 @@ class DriveStatusWidget extends Widget {
10790
return this._isLoading;
10891
}
10992

110-
private _currentPath: string;
11193
private _isLoading: boolean;
11294
}
11395

@@ -142,7 +124,8 @@ export const driveFileBrowser: JupyterFrontEndPlugin<void> = {
142124
IFileBrowserFactory,
143125
IToolbarWidgetRegistry,
144126
ISettingRegistry,
145-
ITranslator
127+
ITranslator,
128+
IDocumentWidgetOpener
146129
],
147130
optional: [
148131
IRouter,
@@ -157,6 +140,7 @@ export const driveFileBrowser: JupyterFrontEndPlugin<void> = {
157140
toolbarRegistry: IToolbarWidgetRegistry,
158141
settingsRegistry: ISettingRegistry,
159142
translator: ITranslator,
143+
docWidgetOpener: IDocumentWidgetOpener,
160144
router: IRouter | null,
161145
tree: JupyterFrontEnd.ITreeResolver | null,
162146
labShell: ILabShell | null,
@@ -211,20 +195,27 @@ export const driveFileBrowser: JupyterFrontEndPlugin<void> = {
211195
isActive: () => true
212196
});
213197

214-
// Update status when drive browser is ready
215-
driveStatusWidget.updateStatus('Connected');
198+
// Item being opened
199+
//@ts-expect-error listing is protected
200+
driveBrowser.listing.onItemOpened.connect((_, args) => {
201+
console.log('[search] PLEASE]', args);
202+
const { path, type } = args;
203+
driveStatusWidget.setLoading(path, type);
204+
console.log('loaded');
205+
});
216206

217-
// Listen for drive changes and update status
218-
drive.loadingContents.connect((sender, args) => {
219-
const { path, type, itemType } = args;
220-
console.log('[DEBUG] Path changed:', path, 'args:', args);
221-
if (type === 'loading') {
222-
driveStatusWidget.setLoading(path, itemType);
223-
} else if (type === 'loaded') {
224-
console.log('loaded');
225-
// driveStatusWidget.setLoaded(path, itemType);
226-
}
207+
// Item done opening
208+
docWidgetOpener.opened.connect((_, args) => {
209+
console.log('[search] opened signal', args);
210+
211+
const { context } = args;
212+
213+
const { contentsModel } = context;
214+
console.log('contentsModel', contentsModel);
215+
driveStatusWidget.setLoaded();
227216
});
217+
218+
driveStatusWidget.updateStatus('Connected');
228219
}
229220

230221
const uploader = new Uploader({ model: driveBrowser.model, translator });

0 commit comments

Comments
 (0)