Skip to content

Commit c059166

Browse files
committed
Add a clear widget state command as well.
1 parent 814020f commit c059166

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

widgetsnbextension/src/manager.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ WidgetManager.prototype._init_actions = function() {
134134
help: 'Save the notebook with the widget state information for static rendering'
135135
};
136136
Jupyter.menubar.actions.register(this.saveWidgetsAction, 'save-with-widgets', 'widgets');
137+
138+
this.clearWidgetsAction = {
139+
handler: (function() {
140+
delete Jupyter.notebook.metadata.widgets;
141+
Jupyter.menubar.actions.get('jupyter-notebook:save-notebook').handler({
142+
notebook: Jupyter.notebook
143+
});
144+
}),
145+
help: 'Clear the widget state information from the notebook'
146+
};
147+
Jupyter.menubar.actions.register(this.saveWidgetsAction, 'save-clear-widgets', 'widgets');
137148
};
138149

139150
/**
@@ -159,7 +170,12 @@ WidgetManager.prototype._init_menu = function() {
159170
widgetsSubmenu.classList.add('dropdown-menu');
160171
widgetsMenu.appendChild(widgetsSubmenu);
161172

162-
widgetsSubmenu.appendChild(this._createMenuItem('Save Notebook with Widgets', this.saveWidgetsAction));
173+
var divider = document.createElement('ul');
174+
divider.classList.add('divider');
175+
176+
widgetsSubmenu.appendChild(this._createMenuItem('Save Notebook Widget State', this.saveWidgetsAction));
177+
widgetsSubmenu.appendChild(this._createMenuItem('Clear Notebook Widget State', this.clearWidgetsAction));
178+
widgetsSubmenu.appendChild(divider);
163179
widgetsSubmenu.appendChild(this._createMenuItem('Download Widget State', saveState.action));
164180
widgetsSubmenu.appendChild(this._createMenuItem('Embed Widgets', embedWidgets.action));
165181
};

0 commit comments

Comments
 (0)