Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of Notebook and Console Content Factories #1482

Merged
merged 45 commits into from Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b5c6fed
wip refactor cell factories
blink1073 Jan 11, 2017
f26f18c
Finish refactor of notebook content factories
blink1073 Jan 12, 2017
59906dc
Finish refactor of content factories
blink1073 Jan 12, 2017
e36d609
Fix notebook widget factory
blink1073 Jan 12, 2017
2e908b7
Clean up notebook addon widgets
blink1073 Jan 12, 2017
cc2accc
Refactor handling of keydown event in console prompt
blink1073 Jan 12, 2017
ced293f
Move completer and inspection handler to panel
blink1073 Jan 12, 2017
32093ad
Clean up signal handlers
blink1073 Jan 12, 2017
93bf924
Clean up handling of signals and promise results
blink1073 Jan 12, 2017
29658b5
Only pass parent reference to cell creators
blink1073 Jan 13, 2017
8362ce2
Expose the banner widget of the console
blink1073 Jan 13, 2017
8fe811b
Rename Console -> CodeConsole to avoid shadowing builtin
blink1073 Jan 13, 2017
537609b
Clean up remaining logic errors
blink1073 Jan 13, 2017
45cd9d0
Reorganize test files
blink1073 Jan 13, 2017
b9406e4
wip update tests
blink1073 Jan 13, 2017
8177142
wip update tests
blink1073 Jan 13, 2017
cae14e9
wip update tests
blink1073 Jan 13, 2017
8e93a55
wip update tests
blink1073 Jan 13, 2017
db213e3
add more tests for content factories
blink1073 Jan 13, 2017
0ef9279
Update output area widget pattern
blink1073 Jan 16, 2017
aa3a937
Update cell contentFactory tests
blink1073 Jan 16, 2017
f0361d7
Update notebook widget contentfactory tests
blink1073 Jan 16, 2017
c0b8b1a
Update notebook panel contentfactory tests
blink1073 Jan 16, 2017
0febe7c
Add tests for console contentFactory
blink1073 Jan 16, 2017
47ca910
Update console panel contentfactory tests
blink1073 Jan 16, 2017
1f52643
Fix failing tests
blink1073 Jan 16, 2017
77a3f8e
Use Console for menu and commands
blink1073 Jan 16, 2017
7c2072f
Update code console tests
blink1073 Jan 16, 2017
023d05a
Fix the update script in the examples
blink1073 Jan 16, 2017
ec5d702
Allow threading of content factories through the constructor
blink1073 Jan 17, 2017
bc8e7ef
Update tests
blink1073 Jan 17, 2017
84ef908
update examples
blink1073 Jan 17, 2017
7f74f6c
set the contentFactory on the notebook
blink1073 Jan 17, 2017
d64facd
Add debug info for CI
blink1073 Jan 17, 2017
af404cd
more debug info
blink1073 Jan 17, 2017
4313b0d
Clean up install script
blink1073 Jan 17, 2017
2a5611d
Remove the error exit in install
blink1073 Jan 17, 2017
15e6cac
Update console _execute
blink1073 Jan 17, 2017
aad56e4
Update onEdgeRequest test
blink1073 Jan 17, 2017
830772c
update onedgerequest test
blink1073 Jan 17, 2017
d11e9e0
update onedgerequest again
blink1073 Jan 17, 2017
8c7388e
Remove edgechanged request
blink1073 Jan 17, 2017
aaeb975
Cleanup and fix doc typo
blink1073 Jan 17, 2017
3552a9b
Remove unused import
blink1073 Jan 17, 2017
cc9855d
Actually attach the completer
blink1073 Jan 17, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/console/package.json
Expand Up @@ -5,7 +5,7 @@
"build": "tsc --project src && webpack --config webpack.conf.js",
"clean": "rimraf build && rimraf node_modules",
"postinstall": "node ../../scripts/dedupe.js && npm run build",
"update": "rimraf node_modules/jupyterlab || npm install",
"update": "(rimraf node_modules/jupyterlab || true) && npm install",
"watch": "watch \"npm run update && npm run build\" ../../src src --wait 10"
},
"dependencies": {
Expand Down
18 changes: 12 additions & 6 deletions examples/console/src/index.ts
Expand Up @@ -94,8 +94,14 @@ function startApp(session: Session.ISession) {
}
let sanitizer = defaultSanitizer;
let rendermime = new RenderMime({ renderers, order, sanitizer });
let renderer = new ConsolePanel.Renderer({ editorServices });
let consolePanel = renderer.createConsole(rendermime, session);
let editorFactory = editorServices.factoryService.newInlineEditor;
let contentFactory = new ConsolePanel.ContentFactory({ editorFactory });
let consolePanel = new ConsolePanel({
rendermime,
session,
contentFactory,
mimeTypeService: editorServices.mimeTypeService
});
consolePanel.title.label = TITLE;

let palette = new CommandPalette({ commands, keymap });
Expand All @@ -119,30 +125,30 @@ function startApp(session: Session.ISession) {
command = 'console:clear';
commands.addCommand(command, {
label: 'Clear',
execute: () => { consolePanel.content.clear(); }
execute: () => { consolePanel.console.clear(); }
});
palette.addItem({ command, category });

command = 'console:execute';
commands.addCommand(command, {
label: 'Execute Prompt',
execute: () => { consolePanel.content.execute(); }
execute: () => { consolePanel.console.execute(); }
});
palette.addItem({ command, category });
keymap.addBinding({ command, selector, keys: ['Enter'] });

command = 'console:execute-forced';
commands.addCommand(command, {
label: 'Execute Cell (forced)',
execute: () => { consolePanel.content.execute(true); }
execute: () => { consolePanel.console.execute(true); }
});
palette.addItem({ command, category });
keymap.addBinding({ command, selector, keys: ['Shift Enter'] });

command = 'console:linebreak';
commands.addCommand(command, {
label: 'Insert Line Break',
execute: () => { consolePanel.content.insertLinebreak(); }
execute: () => { consolePanel.console.insertLinebreak(); }
});
palette.addItem({ command, category });
keymap.addBinding({ command, selector, keys: ['Ctrl Enter'] });
Expand Down
2 changes: 1 addition & 1 deletion examples/filebrowser/package.json
Expand Up @@ -5,7 +5,7 @@
"build": "tsc --project src && webpack --config webpack.conf.js",
"clean": "rimraf build && rimraf node_modules",
"postinstall": "node ../../scripts/dedupe.js && npm run build",
"update": "rimraf node_modules/jupyterlab || npm install",
"update": "(rimraf node_modules/jupyterlab || true) && npm install",
"watch": "watch \"npm run update && npm run build\" ../../src src --wait 10"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/lab/package.json
Expand Up @@ -5,7 +5,7 @@
"build": "webpack --config webpack.conf.js",
"clean": "rimraf build && rimraf node_modules",
"postinstall": "node ../../scripts/dedupe.js && npm run build",
"update": "rimraf node_modules/jupyterlab || npm install",
"update": "(rimraf node_modules/jupyterlab || true) && npm install",
"watch": "watch \"npm run update && npm run build\" ../../src --wait 10"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/notebook/package.json
Expand Up @@ -5,7 +5,7 @@
"build": "tsc --project src && webpack --config webpack.conf.js",
"clean": "rimraf build && rimraf node_modules",
"postinstall": "node ../../scripts/dedupe.js && npm run build",
"update": "rimraf node_modules/jupyterlab || npm install",
"update": "(rimraf node_modules/jupyterlab || true) && npm install",
"watch": "watch \"npm run update && npm run build\" ../../src src --wait 10"
},
"dependencies": {
Expand Down
29 changes: 15 additions & 14 deletions examples/notebook/src/index.ts
Expand Up @@ -129,8 +129,8 @@ function createApp(manager: ServiceManager.IManager): void {
});
let mFactory = new NotebookModelFactory();
let clipboard = new MimeData();
let notebookRenderer = new Notebook.Renderer({ editorServices });
let renderer = new NotebookPanel.Renderer({ notebookRenderer });
let editorFactory = editorServices.factoryService.newInlineEditor;
let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });

let wFactory = new NotebookWidgetFactory({
name: 'Notebook',
Expand All @@ -139,7 +139,8 @@ function createApp(manager: ServiceManager.IManager): void {
defaultFor: ['.ipynb'],
preferKernel: true,
canStartKernel: true,
rendermime, clipboard, renderer
rendermime, clipboard, contentFactory,
mimeTypeService: editorServices.mimeTypeService
});
docRegistry.addModelFactory(mFactory);
docRegistry.addWidgetFactory(wFactory);
Expand Down Expand Up @@ -182,48 +183,48 @@ function createApp(manager: ServiceManager.IManager): void {
commands.addCommand(cmdIds.runAndAdvance, {
label: 'Run and Advance',
execute: () => {
NotebookActions.runAndAdvance(nbWidget.content, nbWidget.context.kernel);
NotebookActions.runAndAdvance(nbWidget.notebook, nbWidget.context.kernel);
}
});
commands.addCommand(cmdIds.editMode, {
label: 'Edit Mode',
execute: () => { nbWidget.content.mode = 'edit'; }
execute: () => { nbWidget.notebook.mode = 'edit'; }
});
commands.addCommand(cmdIds.commandMode, {
label: 'Command Mode',
execute: () => { nbWidget.content.mode = 'command'; }
execute: () => { nbWidget.notebook.mode = 'command'; }
});
commands.addCommand(cmdIds.selectBelow, {
label: 'Select Below',
execute: () => NotebookActions.selectBelow(nbWidget.content)
execute: () => NotebookActions.selectBelow(nbWidget.notebook)
});
commands.addCommand(cmdIds.selectAbove, {
label: 'Select Above',
execute: () => NotebookActions.selectAbove(nbWidget.content)
execute: () => NotebookActions.selectAbove(nbWidget.notebook)
});
commands.addCommand(cmdIds.extendAbove, {
label: 'Extend Above',
execute: () => NotebookActions.extendSelectionAbove(nbWidget.content)
execute: () => NotebookActions.extendSelectionAbove(nbWidget.notebook)
});
commands.addCommand(cmdIds.extendBelow, {
label: 'Extend Below',
execute: () => NotebookActions.extendSelectionBelow(nbWidget.content)
execute: () => NotebookActions.extendSelectionBelow(nbWidget.notebook)
});
commands.addCommand(cmdIds.merge, {
label: 'Merge Cells',
execute: () => NotebookActions.mergeCells(nbWidget.content)
execute: () => NotebookActions.mergeCells(nbWidget.notebook)
});
commands.addCommand(cmdIds.split, {
label: 'Split Cell',
execute: () => NotebookActions.splitCell(nbWidget.content)
execute: () => NotebookActions.splitCell(nbWidget.notebook)
});
commands.addCommand(cmdIds.undo, {
label: 'Undo',
execute: () => NotebookActions.undo(nbWidget.content)
execute: () => NotebookActions.undo(nbWidget.notebook)
});
commands.addCommand(cmdIds.redo, {
label: 'Redo',
execute: () => NotebookActions.redo(nbWidget.content)
execute: () => NotebookActions.redo(nbWidget.notebook)
});

let category = 'Notebook Operations';
Expand Down
2 changes: 1 addition & 1 deletion examples/terminal/package.json
Expand Up @@ -5,7 +5,7 @@
"build": "tsc --project src && webpack --config webpack.conf.js",
"clean": "rimraf build && rimraf node_modules",
"postinstall": "node ../../scripts/dedupe.js && npm run build",
"update": "rimraf node_modules/jupyterlab || npm install",
"update": "(rimraf node_modules/jupyterlab || true) && npm install",
"watch": "watch \"npm run update && npm run build\" ../../src src --wait 10"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions scripts/travis_install.sh
Expand Up @@ -2,17 +2,17 @@

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
set -x

npm install
npm update
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda
export PATH="$HOME/miniconda/bin:$PATH"
hash -r
conda config --set always_yes yes --set changeps1 no
conda update -q conda
conda info -a
conda install jupyter pytest
conda install -c conda-forge notebook
conda install -c conda-forge notebook pytest

# create jupyter base dir (needed for config retreival)
mkdir ~/.jupyter
Expand Down
4 changes: 2 additions & 2 deletions src/codeeditor/editor.ts
Expand Up @@ -684,8 +684,8 @@ namespace CodeEditor {
readOnly?: boolean;

/**
* The default selection style for the editor.
*/
* The default selection style for the editor.
*/
selectionStyle?: CodeEditor.ISelectionStyle;
}
}
34 changes: 33 additions & 1 deletion src/codeeditor/widget.ts
Expand Up @@ -24,7 +24,14 @@ class CodeEditorWidget extends Widget {
*/
constructor(options: CodeEditorWidget.IOptions) {
super();
this._editor = options.factory({ host: this.node, model: options.model });
this._editor = options.factory({
host: this.node,
model: options.model,
uuid: options.uuid,
wordWrap: options.wordWrap,
readOnly: options.readOnly,
selectionStyle: options.selectionStyle
});
}

/**
Expand Down Expand Up @@ -175,5 +182,30 @@ namespace CodeEditorWidget {
* The model used to initialize the code editor.
*/
model: CodeEditor.IModel;

/**
* The desired uuid for the editor.
*/
uuid?: string;

/**
* Whether line numbers should be displayed. Defaults to `false`.
*/
lineNumbers?: boolean;

/**
* Set to false for horizontal scrolling. Defaults to `true`.
*/
wordWrap?: boolean;

/**
* Whether the editor is read-only. Defaults to `false`.
*/
readOnly?: boolean;

/**
* The default selection style for the editor.
*/
selectionStyle?: CodeEditor.ISelectionStyle;
}
}
2 changes: 1 addition & 1 deletion src/completer/handler.ts
Expand Up @@ -134,7 +134,7 @@ class CellCompleterHandler implements IDisposable {
coords,
line: position.line,
column: position.column
}
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/completer/widget.ts
Expand Up @@ -86,7 +86,7 @@ class CompleterWidget extends Widget {
super({ node: document.createElement('ul') });
this._renderer = options.renderer || CompleterWidget.defaultRenderer;
this.anchor = options.anchor || null;
this.model = options.model || null;
this.model = options.model;
this.addClass(COMPLETER_CLASS);

// Completer widgets are hidden until they are populated.
Expand Down
21 changes: 5 additions & 16 deletions src/console/foreign.ts
Expand Up @@ -25,7 +25,7 @@ class ForeignHandler implements IDisposable {
*/
constructor(options: ForeignHandler.IOptions) {
this.kernel = options.kernel;
this._renderer = options.renderer.createCell;
this._factory = options.cellFactory;
this._parent = options.parent;
}

Expand Down Expand Up @@ -149,7 +149,7 @@ class ForeignHandler implements IDisposable {
* Create a new code cell for an input originated from a foreign session.
*/
private _newCell(parentMsgId: string): CodeCellWidget {
let cell = this._renderer();
let cell = this._factory();
this._cells.set(parentMsgId, cell);
this._parent.addCell(cell);
return cell;
Expand All @@ -160,7 +160,7 @@ class ForeignHandler implements IDisposable {
private _isDisposed = false;
private _kernel: Kernel.IKernel = null;
private _parent: ForeignHandler.IReceiver = null;
private _renderer: () => CodeCellWidget = null;
private _factory: () => CodeCellWidget = null;
}


Expand All @@ -185,20 +185,9 @@ namespace ForeignHandler {
parent: IReceiver;

/**
* The renderer for creating cells to inject into the parent.
* The cell factory for foreign handlers.
*/
renderer: IRenderer;
}

/**
* A renderer for foreign handlers.
*/
export
interface IRenderer {
/**
* Create a code cell.
*/
createCell: () => CodeCellWidget;
cellFactory: () => CodeCellWidget;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/console/index.css
Expand Up @@ -18,34 +18,34 @@
}


.jp-ConsoleContent {
.jp-CodeConsole {
height: 100%;
padding: 0;
display: flex;
flex-direction: column;
}


.jp-ConsoleContent-content {
.jp-CodeConsole-content {
background-color: var(--jp-layout-color2);
flex: 1 1 auto;
overflow: auto;
}


.jp-ConsoleContent-content .jp-Cell.jp-ConsoleContent-foreignCell {
.jp-CodeConsole-content .jp-Cell.jp-CodeConsole-foreignCell {
background-color: var(--jp-layout-color3);
flex: 1 1 auto;
overflow: auto;
}


.jp-ConsoleContent-content .jp-Cell.jp-CodeCell.jp-mod-collapsed.jp-mod-readOnly {
.jp-CodeConsole-content .jp-Cell.jp-CodeCell.jp-mod-collapsed.jp-mod-readOnly {
padding-left: calc(2*var(--jp-private-console-cell-padding))
}


.jp-ConsoleContent-input {
.jp-CodeConsole-input {
max-height: 80%;
flex: 0 0 auto;
overflow: auto;
Expand All @@ -59,26 +59,26 @@
}


.jp-ConsoleContent-content .jp-InputArea-editor.jp-CellEditor {
.jp-CodeConsole-content .jp-InputArea-editor.jp-CellEditor {
background: transparent;
border-color: transparent;
}


/* TODO: we should be able to use notebook styles for this */
.jp-ConsoleContent-input .jp-ConsoleContent-prompt.jp-Cell {
.jp-CodeConsole-input .jp-CodeConsole-prompt.jp-Cell {
background: linear-gradient(to right, #66BB6A -40px, #66BB6A 5px, transparent 5px, transparent 100%);
border-color: #66BB6A;
border-left-width: var(--jp-border-width);
}


.jp-ConsoleContent-input .jp-ConsoleContent-prompt .jp-InputArea {
.jp-CodeConsole-input .jp-CodeConsole-prompt .jp-InputArea {
height: 100%;
min-height: 100%;
}


.jp-ConsoleContent-content .jp-ConsoleContent-banner .jp-Cell-prompt {
.jp-CodeConsole-content .jp-CodeConsole-banner .jp-Cell-prompt {
display: none;
}