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
Readonly notebook #3251
Comments
Hi @zvikagart, you should be able to set the notebook model to readOnly. You can do this by setting |
I suspect that @zvikagart is referring to making the codemirror instances I think this behavior is confusing. It can be useful in some instances, however. In the |
Ah, yep, that makes sense. |
Correct, I want to prevent cells from entering edit mode, but also prevent other edits to the notebook like adding/deleting cells, moving cells around, etc. |
I use the following code to hide the toolbar and set codemirror cells to
I also disable execution of commands that modify the notebook. For example:
|
I landed on this topic while I was looking for making the file editor read-only when the filesystem was mounted read-only, and I wanted to share my findings. This is my first time digging into the source of Jupyterlab and I must say it was quite instructing. Basically, I was able to make the file editor read-only when the file opened was not writable by adding the below line:
in the method _onContextReady of file Also, the save button remains enabled and you therefore still have the "permission denied" when you try to use it (still in the context of a read-only filesystem). I saw there is a nicer message when the context model was flagged as
That being said, I am not sure you expect from a file editor to be read-only or to disable the save button when the file is read-only. Indeed, when opening a read-only file regular file editor (Gedit, Sublime Text, Atom, ...):
My conclusion, in my opinion, is that changing these behaviors should rather be done in the context of a specific extension/add-on, for instance by overriding The error message This is for the file editor rather than the notebook editor, but I think the same rules/behavior applies. |
@zvikagart If you want prevent editing, just override the class ReadonlyDrive extends Drive implements Contents.IDrive {
name = 'readonly';
async get(
path: string,
options?: Contents.IFetchOptions
): Promise<Contents.IModel> {
// ... get file content
content.cells.forEach((cell: any) => {
cell.metadata = cell.metadata || {};
cell.metadata.editable = false;
});
return {
name, path, content, ...
} as Contents.IModel;
}
} This way everything will be readOnly. |
I think we need a option in |
The goal is to render a notebook but prevent editing.
I've tried passing
readOnly: true
toNotebookWidgetFactory
but that doesn't seem to have any effect. I can see in the code that a readonly flag is being passed around and applied to cells, but I haven't been able to enable this feature. I also didn't find anything in the documentation.The text was updated successfully, but these errors were encountered: