Skip to content

Commit

Permalink
Add logics to dispose a drive in the command RemoveDriveBrowser.
Browse files Browse the repository at this point in the history
  • Loading branch information
HaudinFlorence committed Dec 18, 2023
1 parent 579c9f5 commit 1e13fbe
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,30 @@ export async function activateAddDrivesPlugin(
bananaDrive.provider = '';
manager.services.contents.addDrive(bananaDrive);
const driveList: Drive[] = [cocoDrive, bananaDrive];

function camelCaseToDashedCase(name: string) {
if (name !== name.toLowerCase()) {
name = name.replace(/[A-Z]/g, m => '-' + m.toLowerCase());
}
return name;
}

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), '');
}
}
return driveName;
}

app.commands.addCommand(CommandIDs.addDriveBrowser, {
execute: args => {
function createSidePanel(driveName: string) {
Expand All @@ -104,6 +121,7 @@ export async function activateAddDrivesPlugin(
panel.title.iconClass = 'jp-SideBar-tabIcon';
panel.title.caption = 'Browse Drives';
panel.id = camelCaseToDashedCase(driveName) + '-file-browser';

app.shell.add(panel, 'left', { rank: 102 });
if (restorer) {
restorer.add(panel, driveName + '-browser');
Expand Down Expand Up @@ -159,6 +177,14 @@ export async function activateAddDrivesPlugin(
execute: args => {
if (test !== undefined) {
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 panelToDispose = Array.from(app.shell.widgets('left')).find(
widget => widget.id === node?.dataset.id
);
Expand Down

0 comments on commit 1e13fbe

Please sign in to comment.