From 3114c2ee93f0c06141baeba1eed564b899a73d6c Mon Sep 17 00:00:00 2001 From: nmadhum Date: Sun, 12 Jan 2020 15:49:08 +0530 Subject: [PATCH] Changes to setting editor should trigger application dirty state Fixes #7757 --- packages/settingeditor-extension/package.json | 3 ++- packages/settingeditor-extension/src/index.ts | 24 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/settingeditor-extension/package.json b/packages/settingeditor-extension/package.json index 67b40726f011..55d78f75e154 100644 --- a/packages/settingeditor-extension/package.json +++ b/packages/settingeditor-extension/package.json @@ -43,7 +43,8 @@ "@jupyterlab/settingeditor": "^2.0.0-beta.2", "@jupyterlab/settingregistry": "^2.0.0-beta.2", "@jupyterlab/statedb": "^2.0.0-beta.2", - "@jupyterlab/ui-components": "^2.0.0-beta.2" + "@jupyterlab/ui-components": "^2.0.0-beta.2", + "@lumino/disposable": "^1.3.4" }, "devDependencies": { "rimraf": "~3.0.0", diff --git a/packages/settingeditor-extension/src/index.ts b/packages/settingeditor-extension/src/index.ts index a9ad4d27fdac..fb4c7bc8f3be 100644 --- a/packages/settingeditor-extension/src/index.ts +++ b/packages/settingeditor-extension/src/index.ts @@ -6,7 +6,8 @@ import { ILayoutRestorer, JupyterFrontEnd, - JupyterFrontEndPlugin + JupyterFrontEndPlugin, + ILabStatus } from '@jupyterlab/application'; import { ICommandPalette, @@ -22,6 +23,7 @@ import { } from '@jupyterlab/settingeditor'; import { ISettingRegistry } from '@jupyterlab/settingregistry'; import { settingsIcon } from '@jupyterlab/ui-components'; +import { IDisposable } from '@lumino/disposable'; /** * The command IDs used by the setting editor. @@ -45,7 +47,8 @@ const plugin: JupyterFrontEndPlugin = { IEditorServices, IStateDB, IRenderMimeRegistry, - ICommandPalette + ICommandPalette, + ILabStatus ], autoStart: true, provides: ISettingEditorTracker, @@ -62,7 +65,8 @@ function activate( editorServices: IEditorServices, state: IStateDB, rendermime: IRenderMimeRegistry, - palette: ICommandPalette + palette: ICommandPalette, + status: ILabStatus ): ISettingEditorTracker { const { commands, shell } = app; const namespace = 'setting-editor'; @@ -104,6 +108,7 @@ function activate( when }); + let disposable: IDisposable | null = null; // 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. @@ -111,6 +116,19 @@ function activate( args.forEach(id => { commands.notifyCommandChanged(id); }); + if (editor.canSaveRaw) { + if (!disposable) { + disposable = status.setDirty(); + } + } else if (disposable) { + disposable.dispose(); + disposable = null; + } + editor.disposed.connect(() => { + if (disposable) { + disposable.dispose(); + } + }); }); editor.id = namespace;