Commit fb7e3107 authored by Phil Jones's avatar Phil Jones

More advanced proof-of-concept.

Still neads an initial change to any part of the notebook to activate.
parent ad266141
......@@ -12,23 +12,24 @@ declare module 'codemirror' {
var modeInfo: any[];
}
CodeMirror.defineMode("finesse", (config) => {
CodeMirror.defineMode("finesse-python", (config) => {
let pmode = CodeMirror.getMode(config, "python");
return CodeMirror.multiplexingMode(
pmode,
{
open: '#katcode',
close: '"""',
open: /#katcode/,
close: /(?=""")/, // Match string end without consuming it
mode: CodeMirror.getMode(config, "text/html"),
delimStyleOpen: "delimit",
delimStyleClose: "string"
delimStyle: "delim"
}
)
});
CodeMirror.defineMIME("text/x-finesse-python", "finesse-python");
Mode.getModeInfo().push({
name: 'Finesse',
mime: "text/python",
mode: 'finesse',
name: 'Finesse Python',
mime: "text/x-finesse-python",
mode: 'finesse-python',
ext: [],
});
import {
IDisposable, DisposableDelegate
} from '@phosphor/disposable';
import {
JupyterFrontEnd, JupyterFrontEndPlugin
} from '@jupyterlab/application';
import {
ToolbarButton
} from '@jupyterlab/apputils';
import {
DocumentRegistry
} from '@jupyterlab/docregistry';
import {
NotebookPanel, INotebookModel
NotebookPanel, INotebookTracker, Notebook
} from '@jupyterlab/notebook';
import {
Mode, CodeMirrorEditor
} from '@jupyterlab/codemirror'
CodeCell
} from '@jupyterlab/cells';
import './codemirror-finesse';
......@@ -30,48 +18,27 @@ import './codemirror-finesse';
*/
const plugin: JupyterFrontEndPlugin<void> = {
activate,
id: 'my-extension-name:buttonPlugin',
id: 'finesse-syntax-jupyter',
requires: [INotebookTracker],
autoStart: true
};
function activate(app: JupyterFrontEnd, tracker: INotebookTracker) {
tracker.widgetAdded.connect(activate_finesse)
};
/**
* A notebook widget extension that adds a button to the toolbar.
*/
export
class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
/**
* Create a new extension object.
*/
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
let callback = () => {
console.log(Mode.getModeInfo());
panel.content.widgets.forEach(cell => {
(cell.editor as CodeMirrorEditor).setOption("mode", "finesse");
});
//NotebookActions.runAll(panel.content, context.session);
};
let button = new ToolbarButton({
className: 'myButton',
iconClassName: 'fa fa-fast-forward',
onClick: callback,
tooltip: 'Run All'
});
panel.toolbar.insertItem(0, 'runAll', button);
return new DisposableDelegate(() => {
button.dispose();
});
}
}
/**
* Activate the extension.
*/
function activate(app: JupyterFrontEnd) {
app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension());
function check_syntax(sender: Notebook): void {
sender.widgets.forEach(cell => {
if (cell instanceof CodeCell && cell.model.mimeType != "text/x-finesse-python") {
cell.model.mimeType = "text/x-finesse-python";
}
});
};
function activate_finesse(sender: INotebookTracker, panel: NotebookPanel): void {
panel.content.modelContentChanged.connect(check_syntax);
};
/**
* Export the plugin as default.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment