From 50c02f215d7f0d4d87537d2e2616300ffcd76a77 Mon Sep 17 00:00:00 2001 From: Jared Lumpe Date: Tue, 4 Dec 2018 20:39:44 -0800 Subject: [PATCH 1/2] Enable extension settings --- package.json | 7 +++++-- schema/vim.json | 9 +++++++++ src/index.ts | 15 ++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 schema/vim.json diff --git a/package.json b/package.json index 6dbfb40..f194aa2 100644 --- a/package.json +++ b/package.json @@ -28,16 +28,19 @@ }, "files": [ "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}", - "style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}" + "style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}", + "schema/*.json" ], "jupyterlab": { - "extension": true + "extension": true, + "schemaDir": "schema" }, "dependencies": { "@jupyterlab/application": "^1.0.1", "@jupyterlab/codemirror": "^1.0.1", "@jupyterlab/cells": "^1.0.1", "@jupyterlab/notebook": "^1.0.1", + "@jupyterlab/coreutils": "^3.0.0", "@phosphor/commands": "^1.6.3", "@phosphor/coreutils": "^1.3.1", "@phosphor/domutils": "^1.1.3", diff --git a/schema/vim.json b/schema/vim.json new file mode 100644 index 0000000..941b7db --- /dev/null +++ b/schema/vim.json @@ -0,0 +1,9 @@ +{ + "jupyter.lab.setting-icon-class": "jp-NotebookIcon", + "jupyter.lab.setting-icon-label": "Notebook", + "title": "Vim Notebook Cell", + "description": "Vim Notebook Cell Settings", + "properties": { + }, + "type": "object" +} diff --git a/src/index.ts b/src/index.ts index 11f0e05..49604de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,10 @@ import { MarkdownCell } from '@jupyterlab/cells'; +import { + ISettingRegistry +} from '@jupyterlab/coreutils'; + import { CodeMirrorEditor } from '@jupyterlab/codemirror'; @@ -38,10 +42,10 @@ const IS_MAC = !!navigator.platform.match(/Mac/i); * Initialization data for the jupyterlab_vim extension. */ const extension: JupyterFrontEndPlugin = { - id: 'jupyterlab_vim', + id: 'jupyterlab_vim:vim', autoStart: true, activate: activateCellVim, - requires: [INotebookTracker] + requires: [INotebookTracker, ISettingRegistry] }; class VimCell { @@ -189,10 +193,11 @@ class VimCell { private _app: JupyterFrontEnd; } -function activateCellVim(app: JupyterFrontEnd, tracker: INotebookTracker): Promise { +function activateCellVim(app: JupyterFrontEnd, tracker: INotebookTracker, settingRegistry: ISettingRegistry): Promise { + const id = extension.id; + const { commands, shell } = app; - Promise.all([app.restored]).then(([args]) => { - const { commands, shell } = app; + Promise.all([settingRegistry.load(id), app.restored]).then(([settings, args]) => { function getCurrent(args: ReadonlyJSONObject): NotebookPanel | null { const widget = tracker.currentWidget; const activate = args['activate'] !== false; From f2556bd8ed8f73f66f972989951b9517ceb64bda Mon Sep 17 00:00:00 2001 From: Jared Lumpe Date: Tue, 4 Dec 2018 20:46:57 -0800 Subject: [PATCH 2/2] Setting to enable/disable extension --- schema/vim.json | 6 ++++++ src/index.ts | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/schema/vim.json b/schema/vim.json index 941b7db..254ec4b 100644 --- a/schema/vim.json +++ b/schema/vim.json @@ -4,6 +4,12 @@ "title": "Vim Notebook Cell", "description": "Vim Notebook Cell Settings", "properties": { + "enable": { + "type": "boolean", + "title": "Enable", + "description": "Whether to enable the extension.", + "default": true + } }, "type": "object" } diff --git a/src/index.ts b/src/index.ts index 49604de..10ef043 100644 --- a/src/index.ts +++ b/src/index.ts @@ -198,6 +198,10 @@ function activateCellVim(app: JupyterFrontEnd, tracker: INotebookTracker, settin const { commands, shell } = app; Promise.all([settingRegistry.load(id), app.restored]).then(([settings, args]) => { + const enabled = settings.get('enable').composite as boolean; + if (enabled === false) { + return; + } function getCurrent(args: ReadonlyJSONObject): NotebookPanel | null { const widget = tracker.currentWidget; const activate = args['activate'] !== false;