Skip to content

Commit

Permalink
Changes to setting editor should trigger application
Browse files Browse the repository at this point in the history
dirty state

Fixes jupyterlab#7757
  • Loading branch information
Madhu94 committed Jan 12, 2020
1 parent 57cd454 commit 3114c2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/settingeditor-extension/package.json
Expand Up @@ -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",
Expand Down
24 changes: 21 additions & 3 deletions packages/settingeditor-extension/src/index.ts
Expand Up @@ -6,7 +6,8 @@
import {
ILayoutRestorer,
JupyterFrontEnd,
JupyterFrontEndPlugin
JupyterFrontEndPlugin,
ILabStatus
} from '@jupyterlab/application';
import {
ICommandPalette,
Expand All @@ -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.
Expand All @@ -45,7 +47,8 @@ const plugin: JupyterFrontEndPlugin<ISettingEditorTracker> = {
IEditorServices,
IStateDB,
IRenderMimeRegistry,
ICommandPalette
ICommandPalette,
ILabStatus
],
autoStart: true,
provides: ISettingEditorTracker,
Expand All @@ -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';
Expand Down Expand Up @@ -104,13 +108,27 @@ 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.
editor.commandsChanged.connect((sender: any, args: string[]) => {
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;
Expand Down

0 comments on commit 3114c2e

Please sign in to comment.