Skip to content

Commit

Permalink
Add a disposed signal on Drive and use it for disposing the proper si…
Browse files Browse the repository at this point in the history
…depanel and its respective drive filebrowser.
  • Loading branch information
HaudinFlorence committed Dec 19, 2023
1 parent 1e13fbe commit f25ec49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ export class Drive implements Contents.IDrive {
return this._isDisposed;
}

/**
* A signal emitted when the drive is disposed.
*/
get disposed(): ISignal<this, void> {
return this._disposed;
}

/**
* Dispose of the resources held by the manager.
*/
Expand All @@ -275,6 +282,7 @@ export class Drive implements Contents.IDrive {
return;
}
this._isDisposed = true;
this._disposed.emit();
Signal.clearData(this);
}

Expand Down Expand Up @@ -768,6 +776,7 @@ export class Drive implements Contents.IDrive {
private _creationDate: string = '';
private _fileChanged = new Signal<this, Contents.IChangedArgs>(this);
private _isDisposed: boolean = false;
private _disposed = new Signal<this, void>(this);
}

export namespace Drive {
Expand Down
23 changes: 7 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DriveIcon } from './icons';
import { IDocumentManager } from '@jupyterlab/docmanager';
import { Drive } from './contents';
import {
FileBrowser,
/*FileBrowser,*/
/*FilterFileBrowserModel,*/
IFileBrowserFactory
} from '@jupyterlab/filebrowser';
Expand Down Expand Up @@ -100,12 +100,10 @@ export async function activateAddDrivesPlugin(
function restoreDriveName(id: string) {
const list1 = id.split('-file-');
let driveName = list1[0];
console.log('driveName:', driveName);
for (let i = 0; i < driveName.length; i++) {
if (driveName[i] === '-') {
const index = i;
const char = driveName.charAt(index + 1).toUpperCase();
console.log('char:', char);
driveName = driveName.replace(driveName.charAt(index + 1), char);
driveName = driveName.replace(driveName.charAt(index), '');
}
Expand Down Expand Up @@ -134,16 +132,17 @@ export async function activateAddDrivesPlugin(

return panel;
}
const PanelDriveBrowserMap = new Map<FileBrowser, SidePanel>();
function addDriveToPanel(
drive: Drive,
factory: IFileBrowserFactory
): Map<FileBrowser, SidePanel> {
): void {
const driveBrowser = factory.createFileBrowser('drive-browser', {
driveName: drive.name
});
const panel = createSidePanel(drive.name);
PanelDriveBrowserMap.set(driveBrowser, panel);
drive.disposed.connect(() => {
panel.dispose();
});
panel.addWidget(driveBrowser);
factory.tracker.add(driveBrowser);

Expand All @@ -157,7 +156,6 @@ export async function activateAddDrivesPlugin(
translator
)
);
return PanelDriveBrowserMap;
}

driveList.forEach(drive => {
Expand All @@ -179,16 +177,9 @@ export async function activateAddDrivesPlugin(
const node = app.contextMenuHitTest(test);
if (node?.dataset.id) {
const driveName = restoreDriveName(node?.dataset.id);
driveList.forEach(drive => {
if (drive.name === driveName) {
drive.dispose();
}
});
const drive = driveList.find(drive => drive.name === driveName);
drive?.dispose();
}
const panelToDispose = Array.from(app.shell.widgets('left')).find(
widget => widget.id === node?.dataset.id
);
panelToDispose?.dispose();
}
},
caption: trans.__('Remove drive filebrowser.'),
Expand Down

0 comments on commit f25ec49

Please sign in to comment.