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

Add example of a file editor toolbar button to the toolbar examples #189

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- react-widget
- settings
- state
- toolbar-button
- toolbar-buttons
- widgets
- completer
- contentheader
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Start with the [Hello World](hello-world) and then jump to the topic you are int
- [Settings](settings)
- [Signals](signals)
- [State](state)
- [Toolbar item](toolbar-button)
- [Toolbar item](toolbar-buttons)
- [Widgets](widgets)

You can expect from each example:
Expand Down Expand Up @@ -228,11 +228,11 @@ Use State persistence in an extension.

[![State](state/preview.gif)](state)

### [Toolbar Item](toolbar-button)
### [Toolbar Item](toolbar-buttons)

Add a new button to the notebook toolbar.
Add a new buttons to the notebook and editor toolbars.

[![Toolbar button](toolbar-button/Preview.gif)](toolbar-button)
[![Toolbar buttons](toolbar-buttons/Preview.gif)](toolbar-buttons)

### [Widgets](widgets)

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"settings",
"signals",
"state",
"toolbar-button",
"toolbar-buttons",
"widgets"
],
"npmClient": "jlpm",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"settings",
"signals",
"state",
"toolbar-button",
"toolbar-buttons",
"widgets"
]
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_all_ui_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ HERE=$(dirname $0)
## To update all screenshots run ./scripts/run_all_ui_tests.sh npx playwright test -u
COMMAND=${*:-npx playwright test}

declare -a extensions=("command-palette" "commands" "completer" "context-menu" "custom-log-console" "datagrid" "documents" "hello-world" "kernel-messaging" "kernel-output" "launcher" "log-messages" "main-menu" "react-widget" "settings" "server-extension" "signals" "state" "toolbar-button" "widgets")
declare -a extensions=("command-palette" "commands" "completer" "context-menu" "custom-log-console" "datagrid" "documents" "hello-world" "kernel-messaging" "kernel-output" "launcher" "log-messages" "main-menu" "react-widget" "settings" "server-extension" "signals" "state" "toolbar-buttons" "widgets")

# Build docker image
docker-compose -f $HERE/../end-to-end-tests/docker-compose.yml build --no-cache
Expand Down
73 changes: 0 additions & 73 deletions toolbar-button/src/index.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
2 changes: 1 addition & 1 deletion toolbar-button/README.md → toolbar-buttons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Firstly you have to register the plugin information. For that you have to pass a

const plugin: JupyterFrontEndPlugin<void> = {
activate,
id: 'toolbar-button',
id: 'toolbar-buttons',
autoStart: true,
};
```
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@jupyterlab-examples/toolbar-button",
"name": "@jupyterlab-examples/toolbar-buttons",
"version": "0.1.0",
"description": "A JupyterLab extension for clearing all cells output at once.",
"keywords": [
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion toolbar-button/setup.py → toolbar-buttons/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
str(lab_path / "static/style.js")
]

labext_name = "@jupyterlab-examples/toolbar-button"
labext_name = "@jupyterlab-examples/toolbar-buttons"

data_files_spec = [
("share/jupyter/labextensions/%s" % labext_name, str(lab_path.relative_to(HERE)), "**"),
Expand Down
110 changes: 110 additions & 0 deletions toolbar-buttons/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { IDisposable, DisposableDelegate } from '@lumino/disposable';

import {
JupyterFrontEnd,
JupyterFrontEndPlugin,
} from '@jupyterlab/application';

import { ToolbarButton } from '@jupyterlab/apputils';

import { DocumentRegistry } from '@jupyterlab/docregistry';

import {
NotebookActions,
NotebookPanel,
INotebookModel,
} from '@jupyterlab/notebook';

/**
* The plugin registration information.
*/
const plugin: JupyterFrontEndPlugin<void> = {
activate,
id: 'toolbar-buttons',
autoStart: true,
};

/**
* A notebook widget extension that adds a button to the toolbar.
*/
export class NotebookButtonExtension
implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel>
{
/**
* Create a new extension for the notebook panel widget.
*
* @param panel Notebook panel
* @param context Notebook context
* @returns Disposable on the added button
*/
createNew(
panel: NotebookPanel,
context: DocumentRegistry.IContext<INotebookModel>
): IDisposable {
const clearOutput = () => {
NotebookActions.clearAllOutputs(panel.content);
};
const button = new ToolbarButton({
className: 'clear-output-button',
label: 'Clear All Outputs',
onClick: clearOutput,
tooltip: 'Clear All Outputs',
});

panel.toolbar.insertItem(10, 'clearOutputs', button);
return new DisposableDelegate(() => {
button.dispose();
});
}
}

/**
* An editor widget extension that adds a button to the toolbar.
*/
export class EditorButtonExtension
implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel>
{
/**
* Create a new extension for the editor panel widget.
*
* @param panel Editor panel
* @param context Editor context
* @returns Disposable on the added button
*/
createNew(
panel: NotebookPanel,
context: DocumentRegistry.IContext<INotebookModel>
): IDisposable {
const testCommand = () => {
console.log('TESTING BUTTON');
};
const button = new ToolbarButton({
className: 'run-test-command',
label: 'Test Command',
onClick: testCommand,
tooltip: 'Test Command',
});

if (context.path.endsWith('.tex')) {
panel.toolbar.insertItem(10, 'clearOutputs', button);
}
return new DisposableDelegate(() => {
button.dispose();
});
}
}

/**
* Activate the extension.
*
* @param app Main application object
*/
function activate(app: JupyterFrontEnd): void {
app.docRegistry.addWidgetExtension('Notebook', new NotebookButtonExtension());
app.docRegistry.addWidgetExtension('Editor', new EditorButtonExtension());
}

/**
* Export the plugin as default.
*/
export default plugin;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions toolbar-buttons/ui-tests/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
coverage
**/*.d.ts
ui-tests
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@jupyterlab-examples/toolbar-button-tests",
"name": "@jupyterlab-examples/toolbar-buttons-tests",
"version": "0.1.0",
"description": "Integration test for toolbar-button example",
"description": "Integration test for toolbar-buttons example",
"repository": "https://github.com/jupyterlab/extension-examples",
"author": "Project Jupyter Contributors",
"license": "BSD-3-Clause",
Expand Down
2 changes: 1 addition & 1 deletion widgets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ widgets in the following examples:
- Widget showing a [Datagrid](../datagrid/README.md)
- Widget integrating [React components](../react-widget/README.md)
- Widget interacting with a [Kernel](../kernel-messaging/README.md)
- Extending document widget (like the notebook panel) with a new [Toolbar Button](../toolbar-button/README.md)
- Extending document widget (like the notebook panel and editor) with new [Toolbar Buttons](../toolbar-buttons/README.md)