@@ -9,6 +9,10 @@ import { SharingService } from './sharing-service';
99
1010import { createSuccessDialog , createErrorDialog } from './ui-components/share-dialog' ;
1111
12+ import { LabIcon } from '@jupyterlab/ui-components' ;
13+ import refreshIcon from '../style/icons/refresh.svg' ;
14+ import fastForwardSvg from '../style/icons/fast-forward.svg' ;
15+
1216import { exportNotebookAsPDF } from './pdf' ;
1317import { files } from './pages/files' ;
1418import { Commands } from './commands' ;
@@ -211,6 +215,75 @@ const plugin: JupyterFrontEndPlugin<void> = {
211215 }
212216 } ) ;
213217
218+ /**
219+ * Add a command to restart the notebook kernel, terming it as "memory"
220+ */
221+ const RefreshLabIcon = new LabIcon ( {
222+ name : 'jupytereverywhere:refresh' ,
223+ svgstr : refreshIcon
224+ } ) ;
225+
226+ commands . addCommand ( Commands . restartMemoryCommand , {
227+ label : 'Restart Notebook Memory' ,
228+ icon : RefreshLabIcon ,
229+ execute : async ( ) => {
230+ const panel = tracker . currentWidget ;
231+ if ( ! panel ) {
232+ console . warn ( 'No active notebook to restart.' ) ;
233+ return ;
234+ }
235+
236+ const result = await showDialog ( {
237+ title : 'Would you like to restart the notebook’s memory?' ,
238+ buttons : [ Dialog . cancelButton ( { label : 'Cancel' } ) , Dialog . okButton ( { label : 'Restart' } ) ]
239+ } ) ;
240+
241+ if ( result . button . accept ) {
242+ try {
243+ await panel . sessionContext . restartKernel ( ) ;
244+ } catch ( err ) {
245+ console . error ( 'Memory restart failed' , err ) ;
246+ }
247+ }
248+ }
249+ } ) ;
250+
251+ /**
252+ * Add a command to restart the notebook kernel, terming it as "memory",
253+ * and run all cells after the restart.
254+ */
255+ const customFastForwardIcon = new LabIcon ( {
256+ name : 'jupytereverywhere:restart-run' ,
257+ svgstr : fastForwardSvg
258+ } ) ;
259+
260+ commands . addCommand ( Commands . restartMemoryAndRunAllCommand , {
261+ label : 'Restart Notebook Memory and Run All Cells' ,
262+ icon : customFastForwardIcon ,
263+ isEnabled : ( ) => ! ! tracker . currentWidget ,
264+ execute : async ( ) => {
265+ const panel = tracker . currentWidget ;
266+ if ( ! panel ) {
267+ console . warn ( 'No active notebook to restart and run.' ) ;
268+ return ;
269+ }
270+
271+ const result = await showDialog ( {
272+ title : 'Would you like to restart the notebook’s memory and rerun all cells?' ,
273+ buttons : [ Dialog . cancelButton ( { label : 'Cancel' } ) , Dialog . okButton ( { label : 'Restart' } ) ]
274+ } ) ;
275+
276+ if ( result . button . accept ) {
277+ try {
278+ await panel . sessionContext . restartKernel ( ) ;
279+ await commands . execute ( 'notebook:run-all-cells' ) ;
280+ } catch ( err ) {
281+ console . error ( 'Restarting and running all cells failed' , err ) ;
282+ }
283+ }
284+ }
285+ } ) ;
286+
214287 /**
215288 * Add custom Share notebook command
216289 */
0 commit comments