diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e801d067..f56ad183 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,7 +30,7 @@ jobs: - react-widget - settings - state - - toolbar-button + - toolbar-buttons - widgets - completer - contentheader diff --git a/README.md b/README.md index 639f0107..a340d1bd 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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) diff --git a/lerna.json b/lerna.json index 1afb0982..ebc3f39f 100644 --- a/lerna.json +++ b/lerna.json @@ -18,7 +18,7 @@ "settings", "signals", "state", - "toolbar-button", + "toolbar-buttons", "widgets" ], "npmClient": "jlpm", diff --git a/package.json b/package.json index 19e53407..6b6a8f13 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "settings", "signals", "state", - "toolbar-button", + "toolbar-buttons", "widgets" ] }, diff --git a/scripts/run_all_ui_tests.sh b/scripts/run_all_ui_tests.sh index f766322f..321a8ea5 100755 --- a/scripts/run_all_ui_tests.sh +++ b/scripts/run_all_ui_tests.sh @@ -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 diff --git a/toolbar-button/src/index.ts b/toolbar-button/src/index.ts deleted file mode 100644 index 8c66487c..00000000 --- a/toolbar-button/src/index.ts +++ /dev/null @@ -1,73 +0,0 @@ -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 = { - activate, - id: 'toolbar-button', - autoStart: true, -}; - -/** - * A notebook widget extension that adds a button to the toolbar. - */ -export class ButtonExtension - implements DocumentRegistry.IWidgetExtension -{ - /** - * 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 - ): 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(); - }); - } -} - -/** - * Activate the extension. - * - * @param app Main application object - */ -function activate(app: JupyterFrontEnd): void { - app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension()); -} - -/** - * Export the plugin as default. - */ -export default plugin; diff --git a/toolbar-button/.eslintignore b/toolbar-buttons/.eslintignore similarity index 100% rename from toolbar-button/.eslintignore rename to toolbar-buttons/.eslintignore diff --git a/toolbar-button/.eslintrc.js b/toolbar-buttons/.eslintrc.js similarity index 100% rename from toolbar-button/.eslintrc.js rename to toolbar-buttons/.eslintrc.js diff --git a/toolbar-button/.gitignore b/toolbar-buttons/.gitignore similarity index 100% rename from toolbar-button/.gitignore rename to toolbar-buttons/.gitignore diff --git a/toolbar-button/MANIFEST.in b/toolbar-buttons/MANIFEST.in similarity index 100% rename from toolbar-button/MANIFEST.in rename to toolbar-buttons/MANIFEST.in diff --git a/toolbar-button/Preview.gif b/toolbar-buttons/Preview.gif similarity index 100% rename from toolbar-button/Preview.gif rename to toolbar-buttons/Preview.gif diff --git a/toolbar-button/README.md b/toolbar-buttons/README.md similarity index 99% rename from toolbar-button/README.md rename to toolbar-buttons/README.md index c26c3b21..03500b57 100644 --- a/toolbar-button/README.md +++ b/toolbar-buttons/README.md @@ -36,7 +36,7 @@ Firstly you have to register the plugin information. For that you have to pass a const plugin: JupyterFrontEndPlugin = { activate, - id: 'toolbar-button', + id: 'toolbar-buttons', autoStart: true, }; ``` diff --git a/toolbar-button/RELEASE.md b/toolbar-buttons/RELEASE.md similarity index 100% rename from toolbar-button/RELEASE.md rename to toolbar-buttons/RELEASE.md diff --git a/toolbar-button/install.json b/toolbar-buttons/install.json similarity index 100% rename from toolbar-button/install.json rename to toolbar-buttons/install.json diff --git a/toolbar-button/jupyterlab_examples_toolbar_button/__init__.py b/toolbar-buttons/jupyterlab_examples_toolbar_button/__init__.py similarity index 100% rename from toolbar-button/jupyterlab_examples_toolbar_button/__init__.py rename to toolbar-buttons/jupyterlab_examples_toolbar_button/__init__.py diff --git a/toolbar-button/jupyterlab_examples_toolbar_button/_version.py b/toolbar-buttons/jupyterlab_examples_toolbar_button/_version.py similarity index 100% rename from toolbar-button/jupyterlab_examples_toolbar_button/_version.py rename to toolbar-buttons/jupyterlab_examples_toolbar_button/_version.py diff --git a/toolbar-button/package.json b/toolbar-buttons/package.json similarity index 98% rename from toolbar-button/package.json rename to toolbar-buttons/package.json index e90317e1..6822c880 100644 --- a/toolbar-button/package.json +++ b/toolbar-buttons/package.json @@ -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": [ diff --git a/toolbar-button/pyproject.toml b/toolbar-buttons/pyproject.toml similarity index 100% rename from toolbar-button/pyproject.toml rename to toolbar-buttons/pyproject.toml diff --git a/toolbar-button/setup.py b/toolbar-buttons/setup.py similarity index 97% rename from toolbar-button/setup.py rename to toolbar-buttons/setup.py index bcaf517a..d72e373d 100644 --- a/toolbar-button/setup.py +++ b/toolbar-buttons/setup.py @@ -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)), "**"), diff --git a/toolbar-buttons/src/index.ts b/toolbar-buttons/src/index.ts new file mode 100644 index 00000000..ee1dbaa9 --- /dev/null +++ b/toolbar-buttons/src/index.ts @@ -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 = { + activate, + id: 'toolbar-buttons', + autoStart: true, +}; + +/** + * A notebook widget extension that adds a button to the toolbar. + */ + export class NotebookButtonExtension + implements DocumentRegistry.IWidgetExtension +{ + /** + * 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 + ): 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 +{ + /** + * 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 + ): 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; diff --git a/toolbar-button/style/base.css b/toolbar-buttons/style/base.css similarity index 100% rename from toolbar-button/style/base.css rename to toolbar-buttons/style/base.css diff --git a/toolbar-button/style/index.css b/toolbar-buttons/style/index.css similarity index 100% rename from toolbar-button/style/index.css rename to toolbar-buttons/style/index.css diff --git a/toolbar-button/style/index.js b/toolbar-buttons/style/index.js similarity index 100% rename from toolbar-button/style/index.js rename to toolbar-buttons/style/index.js diff --git a/toolbar-button/tsconfig.json b/toolbar-buttons/tsconfig.json similarity index 100% rename from toolbar-button/tsconfig.json rename to toolbar-buttons/tsconfig.json diff --git a/toolbar-button/ui-tests/.env b/toolbar-buttons/ui-tests/.env similarity index 100% rename from toolbar-button/ui-tests/.env rename to toolbar-buttons/ui-tests/.env diff --git a/toolbar-buttons/ui-tests/.eslintignore b/toolbar-buttons/ui-tests/.eslintignore new file mode 100644 index 00000000..8bd31f70 --- /dev/null +++ b/toolbar-buttons/ui-tests/.eslintignore @@ -0,0 +1,5 @@ +node_modules +dist +coverage +**/*.d.ts +ui-tests diff --git a/toolbar-button/ui-tests/README.md b/toolbar-buttons/ui-tests/README.md similarity index 100% rename from toolbar-button/ui-tests/README.md rename to toolbar-buttons/ui-tests/README.md diff --git a/toolbar-button/ui-tests/package.json b/toolbar-buttons/ui-tests/package.json similarity index 69% rename from toolbar-button/ui-tests/package.json rename to toolbar-buttons/ui-tests/package.json index 282fd934..5f8450cd 100644 --- a/toolbar-button/ui-tests/package.json +++ b/toolbar-buttons/ui-tests/package.json @@ -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", diff --git a/toolbar-button/ui-tests/playwright.config.ts b/toolbar-buttons/ui-tests/playwright.config.ts similarity index 100% rename from toolbar-button/ui-tests/playwright.config.ts rename to toolbar-buttons/ui-tests/playwright.config.ts diff --git a/toolbar-button/ui-tests/tests/toolbar-button.spec.ts b/toolbar-buttons/ui-tests/tests/toolbar-button.spec.ts similarity index 100% rename from toolbar-button/ui-tests/tests/toolbar-button.spec.ts rename to toolbar-buttons/ui-tests/tests/toolbar-button.spec.ts diff --git a/widgets/README.md b/widgets/README.md index d2440f16..4878fe11 100644 --- a/widgets/README.md +++ b/widgets/README.md @@ -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)