Skip to content

Commit ffd5a15

Browse files
committed
chore: add a cell toolbar extension
1 parent 42a5e02 commit ffd5a15

File tree

9 files changed

+83
-5
lines changed

9 files changed

+83
-5
lines changed

docs/dev.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ conda activate jupyterlabextensions && \
9090
./content
9191
```
9292

93-
PS: You can run both `shell 1` and `shell 2` commands with `npm run dev`.
93+
PS: You can run both `shell 1` and `shell 2` commands with `yarn run dev`.
9494

9595
Open JupyterLab in your browser.
9696

docs/plugins-application.md

+28
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,31 @@ TODO Enable back the `Theme Toggle` extension (disabled for now for CI).
129129
The `Top Bar` extension transforms the existing JupyterLab topbar into a draggable area where third party plugins can add their widgets.
130130

131131
TODO Enable back the `Theme Toggle` extension (disabled for now for CI).
132+
133+
## Cell Toolbar
134+
135+
This extension removes the `duplicate cell` icon and add a new `restart and run all` icon in the notebook cell toolbar. This is achieved by adding the needed definition in the pluing setting
136+
137+
```json
138+
{
139+
"title": "Cell Toolbar",
140+
"description": "Settings for the Cell Toolbar extension",
141+
"type": "object",
142+
"properties": {},
143+
"additionalProperties": false,
144+
"jupyter.lab.toolbars": {
145+
"Cell": [
146+
{
147+
"name": "restart-run-all",
148+
"command": "notebook:restart-run-all",
149+
"rank": 10
150+
},
151+
{
152+
"name": "duplicate-cell",
153+
"command": "notebook:duplicate-cell",
154+
"disabled": true
155+
}
156+
]
157+
}
158+
}
159+
```

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@datalayer/example-jupyterlab-extensions",
2+
"name": "jupyterlabextensions",
33
"version": "0.1.0",
44
"description": "JupyterLab Extensions Example.",
55
"keywords": [

schema/cell-toolbar.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"title": "Cell Toolbar",
3+
"description": "Settings for the Cell Toolbar extension",
4+
"type": "object",
5+
"properties": {},
6+
"additionalProperties": false,
7+
"jupyter.lab.toolbars": {
8+
"Cell": [
9+
{
10+
"name": "restart-run-all",
11+
"command": "notebook:restart-run-all",
12+
"rank": 10
13+
},
14+
{
15+
"name": "duplicate-cell",
16+
"command": "notebook:duplicate-cell",
17+
"disabled": true
18+
}
19+
]
20+
}
21+
}

src/apod-left/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function activate(
113113
palette: ICommandPalette,
114114
restorer: ILayoutRestorer
115115
): void {
116-
console.log('jupyterlab_apod_left is activated.');
116+
console.log('JupyterLab extension apod_left is activated.');
117117

118118
const content = new APODWidget();
119119
const widget = new MainAreaWidget({ content });

src/apod-main/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function activate(
8080
palette: ICommandPalette,
8181
restorer: ILayoutRestorer | null
8282
): void {
83-
console.log('JupyterLab extension jupyterlab_apod is activated!');
83+
console.log('JupyterLab extension apod_main is activated!');
8484
let widget: MainAreaWidget<APODWidget>;
8585
const command = 'apod:open';
8686
app.commands.addCommand(command, {

src/applicationPlugins.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import apodLeft from './apod-left';
22
import apodMain from './apod-main';
33
import cellFlash from './cell-flash';
4+
import cellToolbar from './cell-toolbar';
45
import codeCellButton from './code-cell-button';
56
import contextMenu from './context-menu';
67
import execTime from './exec-time';
@@ -27,6 +28,7 @@ export default [
2728
apodLeft,
2829
apodMain,
2930
cellFlash,
31+
cellToolbar,
3032
contextMenu,
3133
execTime,
3234
internals,

src/cell-toolbar/index.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {
2+
JupyterFrontEnd,
3+
JupyterFrontEndPlugin
4+
} from '@jupyterlab/application';
5+
6+
import { ISettingRegistry } from '@jupyterlab/settingregistry';
7+
8+
/**
9+
* The plugin registration information.
10+
*/
11+
const cellToolbar: JupyterFrontEndPlugin<void> = {
12+
id: 'jupyterlabextensions:cell-toolbar',
13+
description: 'A JupyterLab extension changing the Cell Toolbar.',
14+
autoStart: true,
15+
optional: [ISettingRegistry],
16+
activate: async (_: JupyterFrontEnd, settingRegistry: ISettingRegistry) => {
17+
console.log('The Cell Toolbar extension is activated.');
18+
// Nothing is needed, this is done by config.
19+
// The following is just to show in the browser console the loaded setting.
20+
if (settingRegistry) {
21+
const setting = await settingRegistry.load(cellToolbar.id);
22+
console.log('--- cellToolbar setting', setting);
23+
}
24+
}
25+
};
26+
27+
export default cellToolbar;

src/code-cell-button/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const cellFactoryPlugin: JupyterFrontEndPlugin<NotebookPanel.IContentFact
130130
provides: NotebookPanel.IContentFactory,
131131
autoStart: true,
132132
activate: (app: JupyterFrontEnd, editorServices: IEditorServices) => {
133-
console.log('jupyterlabextensions:cellcodebtn overrides default nootebook content factory.');
133+
console.log('jupyterlabextensions:cellcodebtn overrides default notebook content factory.');
134134
const { commands } = app;
135135
const editorFactory = editorServices.factoryService.newInlineEditor;
136136
return new ContentFactoryWithFooterButton(commands, { editorFactory });

0 commit comments

Comments
 (0)