@@ -2,23 +2,16 @@ import { ICellModel } from '@jupyterlab/cells';
22import { checkIcon , ToolbarButton , undoIcon } from '@jupyterlab/ui-components' ;
33import { Widget } from '@lumino/widgets' ;
44import { ICellFooterTracker } from 'jupyterlab-cell-input-footer' ;
5+ import { IDiffWidgetOptions } from './interfaces' ;
56
67/**
78 * Base class for diff widgets with shared action button functionality
89 */
910export abstract class BaseDiffWidget extends Widget {
10- protected _cell : ICellModel ;
11- protected _cellFooterTracker : ICellFooterTracker ;
12- protected _originalSource : string ;
13- protected _newSource : string ;
14- protected _showActionButtons : boolean ;
15- protected _openDiff : boolean ;
16- protected _toggleButton : ToolbarButton | null = null ;
17-
1811 /**
1912 * Construct a new BaseDiffWidget.
2013 */
21- constructor ( options : BaseDiffWidget . IOptions ) {
14+ constructor ( options : IDiffWidgetOptions ) {
2215 super ( ) ;
2316 this . _cell = options . cell ;
2417 this . _cellFooterTracker = options . cellFooterTracker ;
@@ -100,13 +93,11 @@ export abstract class BaseDiffWidget extends Widget {
10093 className : 'jp-DiffView-toggle' ,
10194 onClick : ( ) => {
10295 this . onToggleClick ( ) ;
103- this . _updateToggleButton ( ) ;
10496 }
10597 } ) ;
10698
10799 footer . addToolbarItemOnLeft ( 'toggle-diff' , this . _toggleButton ) ;
108100
109- // Only add action buttons if showActionButtons is true
110101 if ( this . _showActionButtons ) {
111102 const rejectButton = new ToolbarButton ( {
112103 icon : undoIcon ,
@@ -128,36 +119,11 @@ export abstract class BaseDiffWidget extends Widget {
128119 footer . addToolbarItemOnRight ( 'accept-diff' , acceptButton ) ;
129120 }
130121
131- // Show the diff view based on openDiff setting
132122 if ( this . _openDiff ) {
133123 this . show ( ) ;
134124 } else {
135125 this . hide ( ) ;
136126 }
137- this . _updateToggleButton ( ) ;
138- }
139-
140- /**
141- * Update the toggle button label based on visibility
142- */
143- private _updateToggleButton ( ) : void {
144- if ( this . _toggleButton ) {
145- // Remove and re-add with new label
146- const footer = this . _cellFooterTracker ?. getFooter ( this . _cell ?. id ) ;
147- if ( footer ) {
148- footer . removeToolbarItem ( 'toggle-diff' ) ;
149- this . _toggleButton = new ToolbarButton ( {
150- label : 'Compare changes' ,
151- enabled : true ,
152- className : 'jp-DiffView-toggle' ,
153- onClick : ( ) => {
154- this . onToggleClick ( ) ;
155- this . _updateToggleButton ( ) ;
156- }
157- } ) ;
158- footer . addToolbarItemOnLeft ( 'toggle-diff' , this . _toggleButton ) ;
159- }
160- }
161127 }
162128
163129 /**
@@ -177,21 +143,12 @@ export abstract class BaseDiffWidget extends Widget {
177143 this . _cellFooterTracker . hideFooter ( cellId ) ;
178144 }
179145 }
180- }
181146
182- /**
183- * A namespace for `BaseDiffWidget` statics.
184- */
185- export namespace BaseDiffWidget {
186- /**
187- * The options used to construct a `BaseDiffWidget`.
188- */
189- export interface IOptions {
190- cell : ICellModel ;
191- cellFooterTracker : ICellFooterTracker ;
192- originalSource : string ;
193- newSource ?: string ;
194- showActionButtons ?: boolean ;
195- openDiff ?: boolean ;
196- }
147+ protected _cell : ICellModel ;
148+ protected _cellFooterTracker : ICellFooterTracker ;
149+ protected _originalSource : string ;
150+ protected _newSource : string ;
151+ protected _showActionButtons : boolean ;
152+ protected _openDiff : boolean ;
153+ protected _toggleButton : ToolbarButton | null = null ;
197154}
0 commit comments