Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable directory rename #41

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions schema/file-browser-toolbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
}
]
},
"jupyter.lab.menus": {
"context": [
{
"command": "filebrowser:rename",
"selector": ".jp-DirListing-item[data-isdir]",
"rank": 5,
"disabled": true
},
{
"command": "drives:rename",
"selector": ".jp-DirListing-item[data-isdir]",
"rank": 5
}
]
},
"jupyter.lab.setting-icon": "jupydrive-s3:drive",
"jupyter.lab.setting-icon-label": "Drive Browser",
"title": "Jupydrive-s3 Settings",
Expand Down
25 changes: 25 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Uploader
} from '@jupyterlab/filebrowser';
import { IStateDB } from '@jupyterlab/statedb';
import { editIcon } from '@jupyterlab/ui-components';

import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { ITranslator } from '@jupyterlab/translation';
Expand All @@ -44,6 +45,7 @@ namespace CommandIDs {
export const copyToAnotherBucket = 'drives:copy-to-another-bucket';
export const toggleBucketSwitching = 'drives:toggle-bucket-switching-ui';
export const toggleBrowser = 'filebrowser:toggle-main';
export const rename = 'drives:rename';
}

const FILE_BROWSER_FACTORY = 'DriveBrowser';
Expand Down Expand Up @@ -511,6 +513,29 @@ namespace Private {
'.jp-SidePanel .jp-DirListing-content .jp-DirListing-item[data-isDir]',
rank: 10
});

app.commands.addCommand(CommandIDs.rename, {
execute: args => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't use args and we rely on the widget to do all the work? Sort of funny to have a rename command that doesn't actually do the renaming.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, we don't use args, that's interesting. The command was modeled after the one in jupyterlab: https://github.com/jupyterlab/jupyterlab/blob/68075b17a11258481f5aba68f473788aeaa88650/packages/filebrowser-extension/src/index.ts#L1191-L1207

const widget = tracker.currentWidget;

if (widget) {
return widget.rename();
}
},
isVisible: () =>
// So long as this command only handles one file at time, don't show it
// if multiple files are selected.
!!tracker.currentWidget &&
Array.from(tracker.currentWidget.selectedItems()).length === 1,
isEnabled: () =>
// Disable directory rename for S3 folders.
!!tracker.currentWidget &&
tracker.currentWidget?.selectedItems().next()!.value.type !==
'directory',
icon: editIcon.bindprops({ stylesheet: 'menuItem' }),
label: 'Rename',
mnemonic: 0
});
}

/**
Expand Down
Loading