Skip to content

Commit 1e13fbe

Browse files
Add logics to dispose a drive in the command RemoveDriveBrowser.
1 parent 579c9f5 commit 1e13fbe

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,30 @@ export async function activateAddDrivesPlugin(
8989
bananaDrive.provider = '';
9090
manager.services.contents.addDrive(bananaDrive);
9191
const driveList: Drive[] = [cocoDrive, bananaDrive];
92+
9293
function camelCaseToDashedCase(name: string) {
9394
if (name !== name.toLowerCase()) {
9495
name = name.replace(/[A-Z]/g, m => '-' + m.toLowerCase());
9596
}
9697
return name;
9798
}
9899

100+
function restoreDriveName(id: string) {
101+
const list1 = id.split('-file-');
102+
let driveName = list1[0];
103+
console.log('driveName:', driveName);
104+
for (let i = 0; i < driveName.length; i++) {
105+
if (driveName[i] === '-') {
106+
const index = i;
107+
const char = driveName.charAt(index + 1).toUpperCase();
108+
console.log('char:', char);
109+
driveName = driveName.replace(driveName.charAt(index + 1), char);
110+
driveName = driveName.replace(driveName.charAt(index), '');
111+
}
112+
}
113+
return driveName;
114+
}
115+
99116
app.commands.addCommand(CommandIDs.addDriveBrowser, {
100117
execute: args => {
101118
function createSidePanel(driveName: string) {
@@ -104,6 +121,7 @@ export async function activateAddDrivesPlugin(
104121
panel.title.iconClass = 'jp-SideBar-tabIcon';
105122
panel.title.caption = 'Browse Drives';
106123
panel.id = camelCaseToDashedCase(driveName) + '-file-browser';
124+
107125
app.shell.add(panel, 'left', { rank: 102 });
108126
if (restorer) {
109127
restorer.add(panel, driveName + '-browser');
@@ -159,6 +177,14 @@ export async function activateAddDrivesPlugin(
159177
execute: args => {
160178
if (test !== undefined) {
161179
const node = app.contextMenuHitTest(test);
180+
if (node?.dataset.id) {
181+
const driveName = restoreDriveName(node?.dataset.id);
182+
driveList.forEach(drive => {
183+
if (drive.name === driveName) {
184+
drive.dispose();
185+
}
186+
});
187+
}
162188
const panelToDispose = Array.from(app.shell.widgets('left')).find(
163189
widget => widget.id === node?.dataset.id
164190
);

0 commit comments

Comments
 (0)