Skip to content

Commit

Permalink
Merge pull request #6063 from vatlab/inject_metadata
Browse files Browse the repository at this point in the history
Pass metadata from notebook to console
  • Loading branch information
jasongrout committed Apr 22, 2019
2 parents 9c338a1 + 56f31fd commit 7635934
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/console-extension/src/index.ts
Expand Up @@ -39,7 +39,7 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';

import { find } from '@phosphor/algorithm';

import { ReadonlyJSONObject } from '@phosphor/coreutils';
import { ReadonlyJSONObject, JSONObject } from '@phosphor/coreutils';

import { DisposableSet } from '@phosphor/disposable';

Expand Down Expand Up @@ -460,7 +460,10 @@ async function activateConsole(
if (args['activate'] !== false) {
shell.activateById(widget.id);
}
void widget.console.inject(args['code'] as string);
void widget.console.inject(
args['code'] as string,
args['metadata'] as JSONObject
);
return true;
}
return false;
Expand Down
7 changes: 5 additions & 2 deletions packages/console/src/widget.ts
Expand Up @@ -28,7 +28,7 @@ import { KernelMessage } from '@jupyterlab/services';

import { each } from '@phosphor/algorithm';

import { MimeData } from '@phosphor/coreutils';
import { MimeData, JSONObject } from '@phosphor/coreutils';

import { Drag } from '@phosphor/dragdrop';

Expand Down Expand Up @@ -337,9 +337,12 @@ export class CodeConsole extends Widget {
*
* @returns A promise that indicates when the injected cell's execution ends.
*/
inject(code: string): Promise<void> {
inject(code: string, metadata: JSONObject = {}): Promise<void> {
let cell = this.createCodeCell();
cell.model.value.text = code;
for (let key of Object.keys(metadata)) {
cell.model.metadata.set(key, metadata[key]);
}
this.addCell(cell);
return this._execute(cell);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/notebook-extension/src/index.ts
Expand Up @@ -956,6 +956,7 @@ function addCommands(
const { context, content } = current;

let cell = content.activeCell;
let metadata = cell.model.metadata.toJSON();
let path = context.path;
// ignore action in non-code cell
if (!cell || cell.model.type !== 'code') {
Expand Down Expand Up @@ -997,7 +998,8 @@ function addCommands(
await commands.execute('console:inject', {
activate: false,
code,
path
path,
metadata
});
},
isEnabled
Expand Down

0 comments on commit 7635934

Please sign in to comment.