Skip to content

Commit cdfcec9

Browse files
classic: add UI to add/remove extra mime bundles
1 parent 3d9df55 commit cdfcec9

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

widgetsnbextension/src/manager.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,47 @@ export class WidgetManager extends ManagerBase {
298298
'save-clear-widgets',
299299
'widgets'
300300
);
301+
302+
this.extraMimeWidgetsAction = {
303+
handler: async () => {
304+
const models = this.get_models_sync();
305+
for (var result of findViewsAndOutputs(Jupyter.notebook, models)) {
306+
var bundle = await result.view.generateMimeBundleExtra();
307+
console.log(result.view, bundle);
308+
_.extend(result.output.data, bundle);
309+
}
310+
Jupyter.menubar.actions.get('jupyter-notebook:save-notebook').handler({
311+
notebook: Jupyter.notebook
312+
});
313+
},
314+
help: 'Add extra mime bundles to output cells'
315+
};
316+
Jupyter.menubar.actions.register(
317+
this.saveWidgetsAction,
318+
'mime-extra-widgets',
319+
'widgets'
320+
);
321+
322+
this.clearMimeWidgetsAction = {
323+
handler: async () => {
324+
const models = this.get_models_sync();
325+
for (var result of findViewsAndOutputs(Jupyter.notebook, models)) {
326+
result.output.data = _.pick(result.output.data, [
327+
MIME_TYPE,
328+
'text/plain'
329+
]);
330+
}
331+
Jupyter.menubar.actions.get('jupyter-notebook:save-notebook').handler({
332+
notebook: Jupyter.notebook
333+
});
334+
},
335+
help: 'Remove extra mime bundles from output cells'
336+
};
337+
Jupyter.menubar.actions.register(
338+
this.saveWidgetsAction,
339+
'mime-clear-widgets',
340+
'widgets'
341+
);
301342
}
302343

303344
/**
@@ -324,6 +365,8 @@ export class WidgetManager extends ManagerBase {
324365

325366
var divider = document.createElement('ul');
326367
divider.classList.add('divider');
368+
var divider2 = document.createElement('ul');
369+
divider2.classList.add('divider');
327370

328371
widgetsSubmenu.appendChild(
329372
this._createMenuItem('Save Notebook Widget State', this.saveWidgetsAction)
@@ -341,6 +384,19 @@ export class WidgetManager extends ManagerBase {
341384
widgetsSubmenu.appendChild(
342385
this._createMenuItem('Embed Widgets', embedWidgets.action)
343386
);
387+
widgetsSubmenu.appendChild(divider2);
388+
widgetsSubmenu.appendChild(
389+
this._createMenuItem(
390+
'Add extra to output cell mime bundle',
391+
this.extraMimeWidgetsAction
392+
)
393+
);
394+
widgetsSubmenu.appendChild(
395+
this._createMenuItem(
396+
'Clear extras mime bundle',
397+
this.clearMimeWidgetsAction
398+
)
399+
);
344400
}
345401

346402
/**

0 commit comments

Comments
 (0)