From 5fa4b05145edbc77b90aa27e8ff2bd17206d2a50 Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Thu, 18 Oct 2018 16:02:43 -0700 Subject: [PATCH] Add editor syntax status item to codemirror-extension. --- packages/codemirror-extension/package.json | 8 ++- packages/codemirror-extension/src/index.ts | 8 ++- .../src/syntaxstatus.tsx} | 55 ++++++++++--------- packages/codemirror-extension/tsconfig.json | 6 ++ .../statusbar-extension/src/defaults/index.ts | 1 - packages/statusbar-extension/src/index.ts | 2 - 6 files changed, 48 insertions(+), 32 deletions(-) rename packages/{statusbar-extension/src/defaults/editorSyntax.tsx => codemirror-extension/src/syntaxstatus.tsx} (89%) diff --git a/packages/codemirror-extension/package.json b/packages/codemirror-extension/package.json index 347bec62efbf..bea53df61afa 100644 --- a/packages/codemirror-extension/package.json +++ b/packages/codemirror-extension/package.json @@ -32,14 +32,20 @@ }, "dependencies": { "@jupyterlab/application": "^0.19.1", + "@jupyterlab/apputils": "^0.19.1", "@jupyterlab/codeeditor": "^0.19.1", "@jupyterlab/codemirror": "^0.19.1", "@jupyterlab/coreutils": "^2.2.1", "@jupyterlab/docregistry": "^0.19.1", "@jupyterlab/fileeditor": "^0.19.1", "@jupyterlab/mainmenu": "^0.8.1", + "@jupyterlab/statusbar": "^0.7.1", + "@phosphor/commands": "^1.6.1", + "@phosphor/coreutils": "^1.3.0", + "@phosphor/signaling": "^1.2.2", "@phosphor/widgets": "^1.6.0", - "codemirror": "~5.39.0" + "codemirror": "~5.39.0", + "react": "~16.4.2" }, "devDependencies": { "rimraf": "~2.6.2", diff --git a/packages/codemirror-extension/src/index.ts b/packages/codemirror-extension/src/index.ts index 6f3e7aab17de..718757c55176 100644 --- a/packages/codemirror-extension/src/index.ts +++ b/packages/codemirror-extension/src/index.ts @@ -19,6 +19,8 @@ import { IDocumentWidget } from '@jupyterlab/docregistry'; import { IEditorTracker, FileEditor } from '@jupyterlab/fileeditor'; +import { editorSyntaxStatus } from './syntaxstatus'; + /** * The command IDs used by the codemirror plugin. */ @@ -58,7 +60,11 @@ const commands: JupyterLabPlugin = { /** * Export the plugins as default. */ -const plugins: JupyterLabPlugin[] = [commands, services]; +const plugins: JupyterLabPlugin[] = [ + commands, + services, + editorSyntaxStatus +]; export default plugins; /** diff --git a/packages/statusbar-extension/src/defaults/editorSyntax.tsx b/packages/codemirror-extension/src/syntaxstatus.tsx similarity index 89% rename from packages/statusbar-extension/src/defaults/editorSyntax.tsx rename to packages/codemirror-extension/src/syntaxstatus.tsx index 50604ca0f902..c2eb6a45c9e3 100644 --- a/packages/statusbar-extension/src/defaults/editorSyntax.tsx +++ b/packages/codemirror-extension/src/syntaxstatus.tsx @@ -1,32 +1,35 @@ -/** - * Default item to change the language syntax highlighting of the file editor. - */ -/** - * Part of Jupyterlab status bar defaults. - */ import React from 'react'; -import { TextItem } from '@jupyterlab/statusbar'; -import { ISignal } from '@phosphor/signaling'; -import { Token } from '@phosphor/coreutils'; import { JupyterLabPlugin, JupyterLab } from '@jupyterlab/application'; -import { IEditorTracker, FileEditor } from '@jupyterlab/fileeditor'; -import { IStatusContext } from '../contexts'; + import { VDomRenderer, VDomModel } from '@jupyterlab/apputils'; -import { IDocumentWidget, DocumentRegistry } from '@jupyterlab/docregistry'; + import { CodeEditor } from '@jupyterlab/codeeditor'; -import { Mode } from '@jupyterlab/codemirror'; + import { IChangedArgs } from '@jupyterlab/coreutils'; -import { CommandRegistry } from '@phosphor/commands'; -import { JSONObject } from '@phosphor/coreutils'; -import { Menu } from '@phosphor/widgets'; + +import { IDocumentWidget, DocumentRegistry } from '@jupyterlab/docregistry'; + +import { IEditorTracker, FileEditor } from '@jupyterlab/fileeditor'; + import { IStatusBar, interactiveItem, + Popup, showPopup, - Popup + TextItem } from '@jupyterlab/statusbar'; +import { Mode } from '@jupyterlab/codemirror'; + +import { CommandRegistry } from '@phosphor/commands'; + +import { JSONObject } from '@phosphor/coreutils'; + +import { ISignal } from '@phosphor/signaling'; + +import { Menu } from '@phosphor/widgets'; + namespace EditorSyntaxComponent { export interface IProps { mode: string; @@ -41,6 +44,9 @@ const EditorSyntaxComponent = ( return ; }; +/** + * StatusBar item to change the language syntax highlighting of the file editor. + */ class EditorSyntax extends VDomRenderer implements IEditorSyntax { constructor(opts: EditorSyntax.IOptions) { @@ -202,15 +208,9 @@ export namespace IEditorSyntax { } } -// tslint:disable-next-line:variable-name -export const IEditorSyntax = new Token( - '@jupyterlab/statusbar:IEditorSyntax' -); - -export const editorSyntax: JupyterLabPlugin = { +export const editorSyntaxStatus: JupyterLabPlugin = { id: '@jupyterlab/statusbar:editor-syntax-item', autoStart: true, - provides: IEditorSyntax, requires: [IStatusBar, IEditorTracker], activate: ( app: JupyterLab, @@ -221,9 +221,10 @@ export const editorSyntax: JupyterLabPlugin = { statusBar.registerStatusItem('editor-syntax-item', item, { align: 'left', rank: 0, - isActive: IStatusContext.delegateActive(app.shell, [{ tracker }]) + isActive: () => + app.shell.currentWidget && + tracker.currentWidget && + app.shell.currentWidget === tracker.currentWidget }); - - return item; } }; diff --git a/packages/codemirror-extension/tsconfig.json b/packages/codemirror-extension/tsconfig.json index da45e5c9072a..8ce67d01263f 100644 --- a/packages/codemirror-extension/tsconfig.json +++ b/packages/codemirror-extension/tsconfig.json @@ -26,6 +26,12 @@ }, { "path": "../mainmenu" + }, + { + "path": "../apputils" + }, + { + "path": "../statusbar" } ] } diff --git a/packages/statusbar-extension/src/defaults/index.ts b/packages/statusbar-extension/src/defaults/index.ts index 1c6f4d5acee2..6c413bc1bd88 100644 --- a/packages/statusbar-extension/src/defaults/index.ts +++ b/packages/statusbar-extension/src/defaults/index.ts @@ -4,6 +4,5 @@ export * from './kernelStatus'; export * from './runningSessions'; export * from './filePath'; export * from './tabSpace'; -export * from './editorSyntax'; export * from './memoryUsage'; export * from './savingStatus'; diff --git a/packages/statusbar-extension/src/index.ts b/packages/statusbar-extension/src/index.ts index 2d6ce84b817d..e718921ce94f 100644 --- a/packages/statusbar-extension/src/index.ts +++ b/packages/statusbar-extension/src/index.ts @@ -14,7 +14,6 @@ import { runningSessionsItem, filePathItem, tabSpaceItem, - editorSyntax, memoryUsageItem, savingStatusItem } from './defaults'; @@ -41,7 +40,6 @@ const plugins: JupyterLabPlugin[] = [ runningSessionsItem, filePathItem, tabSpaceItem, - editorSyntax, memoryUsageItem, savingStatusItem ];