@@ -220,29 +220,44 @@ const fullWidthNotebook: JupyterFrontEndPlugin<void> = {
220
220
description : 'A plugin to set the notebook to full width.' ,
221
221
autoStart : true ,
222
222
requires : [ INotebookTracker ] ,
223
- optional : [ ISettingRegistry ] ,
223
+ optional : [ ICommandPalette , ISettingRegistry , ITranslator ] ,
224
224
activate : (
225
225
app : JupyterFrontEnd ,
226
226
tracker : INotebookTracker ,
227
- settingRegistry : ISettingRegistry | null
227
+ palette : ICommandPalette | null ,
228
+ settingRegistry : ISettingRegistry | null ,
229
+ translator : ITranslator | null
228
230
) => {
229
- const setFullWidth = ( value : boolean ) => {
231
+ const trans = ( translator ?? nullTranslator ) . load ( 'notebook' ) ;
232
+
233
+ let fullWidth = false ;
234
+
235
+ const toggleFullWidth = ( ) => {
230
236
const current = tracker . currentWidget ;
237
+ fullWidth = ! fullWidth ;
231
238
if ( ! current ) {
232
239
return ;
233
240
}
234
- current . content . toggleClass ( FULL_WIDTH_NOTEBOOK_CLASS , value ) ;
241
+ const content = current . content ;
242
+ content . toggleClass ( FULL_WIDTH_NOTEBOOK_CLASS , fullWidth ) ;
235
243
} ;
236
244
245
+ let notebookSettings : ISettingRegistry . ISettings ;
246
+
237
247
if ( settingRegistry ) {
238
248
const loadSettings = settingRegistry . load ( fullWidthNotebook . id ) ;
239
249
240
250
const updateSettings = ( settings : ISettingRegistry . ISettings ) : void => {
241
- setFullWidth ( settings . get ( 'fullWidthNotebook' ) . composite as boolean ) ;
251
+ const newFullWidth = settings . get ( 'fullWidthNotebook' )
252
+ . composite as boolean ;
253
+ if ( newFullWidth !== fullWidth ) {
254
+ toggleFullWidth ( ) ;
255
+ }
242
256
} ;
243
257
244
258
Promise . all ( [ loadSettings , app . restored ] )
245
259
. then ( ( [ settings ] ) => {
260
+ notebookSettings = settings ;
246
261
updateSettings ( settings ) ;
247
262
settings . changed . connect ( ( settings ) => {
248
263
updateSettings ( settings ) ;
@@ -252,6 +267,25 @@ const fullWidthNotebook: JupyterFrontEndPlugin<void> = {
252
267
console . error ( reason . message ) ;
253
268
} ) ;
254
269
}
270
+
271
+ app . commands . addCommand ( CommandIDs . toggleFullWidth , {
272
+ label : trans . __ ( 'Enable Full Width Notebook' ) ,
273
+ execute : ( ) => {
274
+ toggleFullWidth ( ) ;
275
+ if ( notebookSettings ) {
276
+ notebookSettings . set ( 'fullWidthNotebook' , fullWidth ) ;
277
+ }
278
+ } ,
279
+ isEnabled : ( ) => tracker . currentWidget !== null ,
280
+ isToggled : ( ) => fullWidth ,
281
+ } ) ;
282
+
283
+ if ( palette ) {
284
+ palette . addItem ( {
285
+ command : CommandIDs . toggleFullWidth ,
286
+ category : 'Notebook Operations' ,
287
+ } ) ;
288
+ }
255
289
} ,
256
290
} ;
257
291
0 commit comments