123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- /*-----------------------------------------------------------------------------
- | Copyright (c) Jupyter Development Team.
- | Distributed under the terms of the Modified BSD License.
- |----------------------------------------------------------------------------*/
- import {
- ILayoutRestorer,
- JupyterFrontEnd,
- JupyterFrontEndPlugin
- } from '@jupyterlab/application';
- import {
- ICommandPalette,
- MainAreaWidget,
- WidgetTracker
- } from '@jupyterlab/apputils';
- import { IEditorServices } from '@jupyterlab/codeeditor';
- import { IStateDB } from '@jupyterlab/statedb';
- import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
- import {
- ISettingEditorTracker,
- SettingEditor
- } from '@jupyterlab/settingeditor';
- import { ISettingRegistry } from '@jupyterlab/settingregistry';
- /**
- * The command IDs used by the setting editor.
- */
- namespace CommandIDs {
- export const open = 'settingeditor:open';
- export const revert = 'settingeditor:revert';
- export const save = 'settingeditor:save';
- }
- /**
- * The default setting editor extension.
- */
- const plugin: JupyterFrontEndPlugin<ISettingEditorTracker> = {
- id: '@jupyterlab/settingeditor-extension:plugin',
- requires: [
- ILayoutRestorer,
- ISettingRegistry,
- IEditorServices,
- IStateDB,
- IRenderMimeRegistry,
- ICommandPalette
- ],
- autoStart: true,
- provides: ISettingEditorTracker,
- activate
- };
- /**
- * Activate the setting editor extension.
- */
- function activate(
- app: JupyterFrontEnd,
- restorer: ILayoutRestorer,
- registry: ISettingRegistry,
- editorServices: IEditorServices,
- state: IStateDB,
- rendermime: IRenderMimeRegistry,
- palette: ICommandPalette
- ): ISettingEditorTracker {
- const { commands, shell } = app;
- const namespace = 'setting-editor';
- const factoryService = editorServices.factoryService;
- const editorFactory = factoryService.newInlineEditor;
- const tracker = new WidgetTracker<MainAreaWidget<SettingEditor>>({
- namespace
- });
- let editor: SettingEditor;
- // Handle state restoration.
- void restorer.restore(tracker, {
- command: CommandIDs.open,
- args: widget => ({}),
- name: widget => namespace
- });
- commands.addCommand(CommandIDs.open, {
- execute: () => {
- if (tracker.currentWidget) {
- shell.activateById(tracker.currentWidget.id);
- return;
- }
- const key = plugin.id;
- const when = app.restored;
- editor = new SettingEditor({
- commands: {
- registry: commands,
- revert: CommandIDs.revert,
- save: CommandIDs.save
- },
- editorFactory,
- key,
- registry,
- rendermime,
- state,
- when
- });
- // Notify the command registry when the visibility status of the setting
- // editor's commands change. The setting editor toolbar listens for this
- // signal from the command registry.
- editor.commandsChanged.connect((sender: any, args: string[]) => {
- args.forEach(id => {
- commands.notifyCommandChanged(id);
- });
- });
- editor.id = namespace;
- editor.title.label = 'Settings';
- editor.title.iconClass = 'jp-SettingsIcon';
- let main = new MainAreaWidget({ content: editor });
- void tracker.add(main);
- shell.add(main);
- },
- label: 'Advanced Settings Editor'
- });
- palette.addItem({ category: 'Settings', command: CommandIDs.open });
- commands.addCommand(CommandIDs.revert, {
- execute: () => {
- tracker.currentWidget?.content.revert();
- },
- iconClass: 'jp-MaterialIcon jp-UndoIcon',
- label: 'Revert User Settings',
- isEnabled: () => tracker.currentWidget?.content.canRevertRaw ?? false
- });
- commands.addCommand(CommandIDs.save, {
- execute: () => tracker.currentWidget?.content.save(),
- iconClass: 'jp-MaterialIcon jp-SaveIcon',
- label: 'Save User Settings',
- isEnabled: () => tracker.currentWidget?.content.canSaveRaw ?? false
- });
- return tracker;
- }
- export default plugin;
|