|
@@ -1,27 +1,14 @@
|
|
|
// Copyright (c) Jupyter Development Team.
|
|
|
// Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
-import 'codemirror/addon/edit/matchbrackets.js';
|
|
|
-import 'codemirror/addon/edit/closebrackets.js';
|
|
|
-import 'codemirror/addon/comment/comment.js';
|
|
|
-import 'codemirror/keymap/vim.js';
|
|
|
-
|
|
|
import {
|
|
|
AttachedProperty
|
|
|
} from 'phosphor/lib/core/properties';
|
|
|
|
|
|
-import {
|
|
|
- Menu
|
|
|
-} from 'phosphor/lib/ui/menu';
|
|
|
-
|
|
|
import {
|
|
|
JupyterLab, JupyterLabPlugin
|
|
|
} from '../application';
|
|
|
|
|
|
-import {
|
|
|
- ICommandPalette
|
|
|
-} from '../commandpalette';
|
|
|
-
|
|
|
import {
|
|
|
InstanceTracker
|
|
|
} from '../common/instancetracker';
|
|
@@ -34,10 +21,6 @@ import {
|
|
|
ILayoutRestorer
|
|
|
} from '../layoutrestorer';
|
|
|
|
|
|
-import {
|
|
|
- IMainMenu
|
|
|
-} from '../mainmenu';
|
|
|
-
|
|
|
import {
|
|
|
IStateDB
|
|
|
} from '../statedb';
|
|
@@ -65,16 +48,13 @@ const EDITOR_ICON_CLASS = 'jp-ImageTextEditor';
|
|
|
*/
|
|
|
const FACTORY = 'Editor';
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* The map of command ids used by the editor.
|
|
|
*/
|
|
|
const cmdIds = {
|
|
|
lineNumbers: 'editor:line-numbers',
|
|
|
lineWrap: 'editor:line-wrap',
|
|
|
- matchBrackets: 'editor:match-brackets',
|
|
|
- vimMode: 'editor:vim-mode',
|
|
|
- closeAll: 'editor:close-all',
|
|
|
- changeTheme: 'editor:change-theme',
|
|
|
createConsole: 'editor:create-console',
|
|
|
runCode: 'editor:run-code'
|
|
|
};
|
|
@@ -87,8 +67,7 @@ export
|
|
|
const plugin: JupyterLabPlugin<IEditorTracker> = {
|
|
|
id: 'jupyter.services.editor-handler',
|
|
|
requires: [
|
|
|
- IDocumentRegistry, IMainMenu, ICommandPalette, IStateDB, ILayoutRestorer,
|
|
|
- IEditorServices
|
|
|
+ IDocumentRegistry, IStateDB, ILayoutRestorer, IEditorServices
|
|
|
],
|
|
|
provides: IEditorTracker,
|
|
|
activate: activateEditorHandler,
|
|
@@ -99,7 +78,7 @@ const plugin: JupyterLabPlugin<IEditorTracker> = {
|
|
|
/**
|
|
|
* Sets up the editor widget
|
|
|
*/
|
|
|
-function activateEditorHandler(app: JupyterLab, registry: IDocumentRegistry, mainMenu: IMainMenu, palette: ICommandPalette, state: IStateDB, layout: ILayoutRestorer, editorServices: IEditorServices): IEditorTracker {
|
|
|
+function activateEditorHandler(app: JupyterLab, registry: IDocumentRegistry, state: IStateDB, layout: ILayoutRestorer, editorServices: IEditorServices): IEditorTracker {
|
|
|
const factory = new EditorWidgetFactory(editorServices, {
|
|
|
name: FACTORY,
|
|
|
fileExtensions: ['*'],
|
|
@@ -130,21 +109,13 @@ function activateEditorHandler(app: JupyterLab, registry: IDocumentRegistry, mai
|
|
|
});
|
|
|
registry.addWidgetFactory(factory);
|
|
|
|
|
|
- /**
|
|
|
- * An attached property for the session id associated with an editor widget.
|
|
|
- */
|
|
|
- const sessionIdProperty = new AttachedProperty<EditorWidget, string>({
|
|
|
- name: 'sessionId'
|
|
|
- });
|
|
|
-
|
|
|
/**
|
|
|
* Toggle editor line numbers
|
|
|
*/
|
|
|
function toggleLineNums() {
|
|
|
if (tracker.currentWidget) {
|
|
|
let editor = tracker.currentWidget.editor;
|
|
|
- // TODO: move to Codemirror
|
|
|
- // editor.setOption('lineNumbers', !editor.getOption('lineNumbers'));
|
|
|
+ editor.lineNumbers = !editor.lineNumbers;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -154,86 +125,16 @@ function activateEditorHandler(app: JupyterLab, registry: IDocumentRegistry, mai
|
|
|
function toggleLineWrap() {
|
|
|
if (tracker.currentWidget) {
|
|
|
let editor = tracker.currentWidget.editor;
|
|
|
- // TODO: move to Codemirror
|
|
|
- // editor.setOption('lineWrapping', !editor.getOption('lineWrapping'));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Toggle editor matching brackets
|
|
|
- */
|
|
|
- function toggleMatchBrackets() {
|
|
|
- if (tracker.currentWidget) {
|
|
|
- let editor = tracker.currentWidget.editor;
|
|
|
- // TODO: move to Codemirror
|
|
|
- // editor.setOption('matchBrackets', !editor.getOption('matchBrackets'));
|
|
|
+ editor.wordWrap = !editor.wordWrap;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Toggle the editor's vim mode
|
|
|
- */
|
|
|
- function toggleVim() {
|
|
|
- tracker.forEach(widget => {
|
|
|
- // TODO: move to Codemirror
|
|
|
- // let keymap = widget.editor.getOption('keyMap') === 'vim' ? 'default'
|
|
|
- // : 'vim';
|
|
|
- // widget.editor.setOption('keyMap', keymap);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Close all currently open text editor files
|
|
|
- */
|
|
|
- function closeAllFiles() {
|
|
|
- tracker.forEach(widget => { widget.close(); });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Create a menu for the editor.
|
|
|
+ * An attached property for the session id associated with an editor widget.
|
|
|
*/
|
|
|
- function createMenu(app: JupyterLab): Menu {
|
|
|
- let { commands, keymap } = app;
|
|
|
- let settings = new Menu({ commands, keymap });
|
|
|
- let theme = new Menu({ commands, keymap });
|
|
|
- let menu = new Menu({ commands, keymap });
|
|
|
-
|
|
|
- menu.title.label = 'Editor';
|
|
|
- settings.title.label = 'Settings';
|
|
|
- theme.title.label = 'Theme';
|
|
|
-
|
|
|
- settings.addItem({ command: cmdIds.lineNumbers });
|
|
|
- settings.addItem({ command: cmdIds.lineWrap });
|
|
|
- settings.addItem({ command: cmdIds.matchBrackets });
|
|
|
- settings.addItem({ command: cmdIds.vimMode });
|
|
|
-
|
|
|
- // TODO: move to codemirror
|
|
|
- // commands.addCommand(cmdIds.changeTheme, {
|
|
|
- // label: args => args['theme'] as string,
|
|
|
- // execute: args => {
|
|
|
- // let name: string = args['theme'] as string || DEFAULT_CODEMIRROR_THEME;
|
|
|
- // tracker.forEach(widget => { widget.editor.setOption('theme', name); });
|
|
|
- // }
|
|
|
- // });
|
|
|
-
|
|
|
- [
|
|
|
- 'jupyter', 'default', 'abcdef', 'base16-dark', 'base16-light',
|
|
|
- 'hopscotch', 'material', 'mbo', 'mdn-like', 'seti', 'the-matrix',
|
|
|
- 'xq-light', 'zenburn'
|
|
|
- ].forEach(name => theme.addItem({
|
|
|
- command: 'editor:change-theme',
|
|
|
- args: { theme: name }
|
|
|
- }));
|
|
|
-
|
|
|
- menu.addItem({ command: cmdIds.closeAll });
|
|
|
- menu.addItem({ type: 'separator' });
|
|
|
- menu.addItem({ type: 'submenu', menu: settings });
|
|
|
- menu.addItem({ type: 'submenu', menu: theme });
|
|
|
-
|
|
|
- return menu;
|
|
|
- }
|
|
|
-
|
|
|
- mainMenu.addMenu(createMenu(app), { rank: 30 });
|
|
|
+ const sessionIdProperty = new AttachedProperty<EditorWidget, string>({
|
|
|
+ name: 'sessionId'
|
|
|
+ });
|
|
|
|
|
|
let commands = app.commands;
|
|
|
|
|
@@ -247,21 +148,6 @@ function activateEditorHandler(app: JupyterLab, registry: IDocumentRegistry, mai
|
|
|
label: 'Toggle Line Wrap',
|
|
|
});
|
|
|
|
|
|
- commands.addCommand(cmdIds.matchBrackets, {
|
|
|
- execute: () => { toggleMatchBrackets(); },
|
|
|
- label: 'Toggle Match Brackets',
|
|
|
- });
|
|
|
-
|
|
|
- commands.addCommand(cmdIds.vimMode, {
|
|
|
- execute: () => { toggleVim(); },
|
|
|
- label: 'Toggle Vim Mode'
|
|
|
- });
|
|
|
-
|
|
|
- commands.addCommand(cmdIds.closeAll, {
|
|
|
- execute: () => { closeAllFiles(); },
|
|
|
- label: 'Close all files'
|
|
|
- });
|
|
|
-
|
|
|
commands.addCommand(cmdIds.createConsole, {
|
|
|
execute: () => {
|
|
|
let widget = tracker.currentWidget;
|
|
@@ -301,15 +187,5 @@ function activateEditorHandler(app: JupyterLab, registry: IDocumentRegistry, mai
|
|
|
label: 'Run Code',
|
|
|
});
|
|
|
|
|
|
- [
|
|
|
- cmdIds.lineNumbers,
|
|
|
- cmdIds.lineWrap,
|
|
|
- cmdIds.matchBrackets,
|
|
|
- cmdIds.vimMode,
|
|
|
- cmdIds.closeAll,
|
|
|
- cmdIds.createConsole,
|
|
|
- cmdIds.runCode,
|
|
|
- ].forEach(command => palette.addItem({ command, category: 'Editor' }));
|
|
|
-
|
|
|
return tracker;
|
|
|
}
|