Skip to content

Commit

Permalink
Add editor syntax status item to codemirror-extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-r-rose committed Oct 18, 2018
1 parent ce5940f commit 5fa4b05
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 32 deletions.
8 changes: 7 additions & 1 deletion packages/codemirror-extension/package.json
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion packages/codemirror-extension/src/index.ts
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -58,7 +60,11 @@ const commands: JupyterLabPlugin<void> = {
/**
* Export the plugins as default.
*/
const plugins: JupyterLabPlugin<any>[] = [commands, services];
const plugins: JupyterLabPlugin<any>[] = [
commands,
services,
editorSyntaxStatus
];
export default plugins;

/**
Expand Down
@@ -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;
Expand All @@ -41,6 +44,9 @@ const EditorSyntaxComponent = (
return <TextItem source={props.mode} onClick={props.handleClick} />;
};

/**
* StatusBar item to change the language syntax highlighting of the file editor.
*/
class EditorSyntax extends VDomRenderer<EditorSyntax.Model>
implements IEditorSyntax {
constructor(opts: EditorSyntax.IOptions) {
Expand Down Expand Up @@ -202,15 +208,9 @@ export namespace IEditorSyntax {
}
}

// tslint:disable-next-line:variable-name
export const IEditorSyntax = new Token<IEditorSyntax>(
'@jupyterlab/statusbar:IEditorSyntax'
);

export const editorSyntax: JupyterLabPlugin<IEditorSyntax> = {
export const editorSyntaxStatus: JupyterLabPlugin<void> = {
id: '@jupyterlab/statusbar:editor-syntax-item',
autoStart: true,
provides: IEditorSyntax,
requires: [IStatusBar, IEditorTracker],
activate: (
app: JupyterLab,
Expand All @@ -221,9 +221,10 @@ export const editorSyntax: JupyterLabPlugin<IEditorSyntax> = {
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;
}
};
6 changes: 6 additions & 0 deletions packages/codemirror-extension/tsconfig.json
Expand Up @@ -26,6 +26,12 @@
},
{
"path": "../mainmenu"
},
{
"path": "../apputils"
},
{
"path": "../statusbar"
}
]
}
1 change: 0 additions & 1 deletion packages/statusbar-extension/src/defaults/index.ts
Expand Up @@ -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';
2 changes: 0 additions & 2 deletions packages/statusbar-extension/src/index.ts
Expand Up @@ -14,7 +14,6 @@ import {
runningSessionsItem,
filePathItem,
tabSpaceItem,
editorSyntax,
memoryUsageItem,
savingStatusItem
} from './defaults';
Expand All @@ -41,7 +40,6 @@ const plugins: JupyterLabPlugin<any>[] = [
runningSessionsItem,
filePathItem,
tabSpaceItem,
editorSyntax,
memoryUsageItem,
savingStatusItem
];
Expand Down

0 comments on commit 5fa4b05

Please sign in to comment.