Skip to content

Commit

Permalink
Extension does act on metadata #1
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Feb 7, 2019
1 parent 4d4fdde commit 0695388
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
},
"dependencies": {
"@jupyterlab/application": "^0.19.1",
"@jupyterlab/apputils": "^0.19.1"
"@jupyterlab/apputils": "^0.19.1",
"@jupyterlab/notebook": "^0.19.2"
},
"devDependencies": {
"rimraf": "^2.6.1",
Expand Down
21 changes: 14 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
ICommandPalette
} from '@jupyterlab/apputils';

import {
INotebookTracker
} from '@jupyterlab/notebook';

import '../style/index.css';

const JUPYTEXT_FORMATS = [
Expand Down Expand Up @@ -41,20 +45,23 @@ const JUPYTEXT_FORMATS = [
const extension: JupyterLabPlugin<void> = {
id: 'jupyterlab-jupytext',
autoStart: true,
requires: [ICommandPalette],
activate: (app: JupyterLab, palette: ICommandPalette) => {
requires: [ICommandPalette, INotebookTracker],
activate: (app: JupyterLab, palette: ICommandPalette, notebook_tracker: INotebookTracker) => {
console.log('JupyterLab extension jupyterlab-jupytext is activated');

// Jupytext formats
JUPYTEXT_FORMATS.forEach((args, rank) => {
const command: string = 'jupytext:' + args['formats']
const formats: string = args['formats']
const command: string = 'jupytext:' + formats
app.commands.addCommand(command, {
label: args['label'],
execute: args => {
// TODO: Replace the below with a code that sets/removes
// notebook.metadata.jupytext.formats=args['formats']
// when the focus is on a notebook.
console.log('Jupytext: executing command=' + command + ' with args=' + String(args))
console.log('Jupytext: executing command=' + command)

if (formats == 'unpair')
notebook_tracker.currentWidget.context.model.metadata.set('jupytext', {})
else
notebook_tracker.currentWidget.context.model.metadata.set('jupytext', { formats })
}
});

Expand Down

0 comments on commit 0695388

Please sign in to comment.