@@ -3,7 +3,8 @@ import { JupyterFrontEnd } from '@jupyterlab/application';
3
3
import {
4
4
changeStageButtonStyle ,
5
5
changeStageButtonLeftStyle ,
6
- discardFileButtonStyle
6
+ discardFileButtonStyle ,
7
+ diffFileButtonStyle
7
8
} from '../componentsStyle/GitStageStyle' ;
8
9
9
10
import {
@@ -17,7 +18,6 @@ import {
17
18
selectedFileChangedLabelStyle ,
18
19
fileChangedLabelBrandStyle ,
19
20
fileChangedLabelInfoStyle ,
20
- discardWarningStyle ,
21
21
fileButtonStyle ,
22
22
fileGitButtonStyle ,
23
23
discardFileButtonSelectedStyle ,
@@ -29,6 +29,10 @@ import { classes } from 'typestyle';
29
29
import * as React from 'react' ;
30
30
31
31
import { showDialog , Dialog } from '@jupyterlab/apputils' ;
32
+ import { ISpecialRef } from './diff/model' ;
33
+ import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
34
+ import { isDiffSupported } from './diff/Diff' ;
35
+ import { openDiffView } from './diff/DiffWidget' ;
32
36
33
37
export interface IFileItemProps {
34
38
topRepoPath : string ;
@@ -55,6 +59,7 @@ export interface IFileItemProps {
55
59
disableFile : boolean ;
56
60
toggleDisableFiles : Function ;
57
61
sideBarExpanded : boolean ;
62
+ renderMime : IRenderMimeRegistry ;
58
63
}
59
64
60
65
export class FileItem extends React . Component < IFileItemProps , { } > {
@@ -181,6 +186,15 @@ export class FileItem extends React.Component<IFileItemProps, {}> {
181
186
}
182
187
}
183
188
189
+ getDiffFileIconClass ( ) {
190
+ return classes (
191
+ fileButtonStyle ,
192
+ changeStageButtonStyle ,
193
+ fileGitButtonStyle ,
194
+ diffFileButtonStyle
195
+ ) ;
196
+ }
197
+
184
198
getDiscardFileIconClass ( ) {
185
199
if ( this . showDiscardWarning ( ) ) {
186
200
return classes (
@@ -206,10 +220,6 @@ export class FileItem extends React.Component<IFileItemProps, {}> {
206
220
}
207
221
}
208
222
209
- getDiscardWarningClass ( ) {
210
- return discardWarningStyle ;
211
- }
212
-
213
223
/**
214
224
* Callback method discarding unstanged changes for selected file.
215
225
* It shows modal asking for confirmation and when confirmed make
@@ -236,6 +246,7 @@ export class FileItem extends React.Component<IFileItemProps, {}> {
236
246
this . props . updateSelectedDiscardFile ( - 1 ) ;
237
247
} ) ;
238
248
}
249
+
239
250
render ( ) {
240
251
return (
241
252
< div
@@ -283,16 +294,49 @@ export class FileItem extends React.Component<IFileItemProps, {}> {
283
294
{ this . getFileChangedLabel ( this . props . file . y ) }
284
295
</ span >
285
296
{ this . props . stage === 'Changed' && (
286
- < button
287
- className = { `jp-Git-button ${ this . getDiscardFileIconClass ( ) } ` }
288
- title = { 'Discard this change' }
289
- onClick = { ( ) => {
290
- this . discardSelectedFileChanges ( ) ;
291
- } }
292
- />
297
+ < React . Fragment >
298
+ < button
299
+ className = { `jp-Git-button ${ this . getDiscardFileIconClass ( ) } ` }
300
+ title = { 'Discard this change' }
301
+ onClick = { ( ) => {
302
+ this . discardSelectedFileChanges ( ) ;
303
+ } }
304
+ />
305
+ { isDiffSupported ( this . props . file . to ) &&
306
+ this . diffButton ( { specialRef : 'WORKING' } ) }
307
+ </ React . Fragment >
293
308
) }
309
+ { this . props . stage === 'Staged' &&
310
+ isDiffSupported ( this . props . file . to ) &&
311
+ this . diffButton ( { specialRef : 'INDEX' } ) }
294
312
</ span >
295
313
</ div >
296
314
) ;
297
315
}
316
+
317
+ /**
318
+ * Creates a button element which is used to request diff from within the
319
+ * Git panel.
320
+ *
321
+ * @param currentRef the ref to diff against the git 'HEAD' ref
322
+ */
323
+ private diffButton ( currentRef : ISpecialRef ) : JSX . Element {
324
+ return (
325
+ < button
326
+ className = { `jp-Git-button ${ this . getDiffFileIconClass ( ) } ` }
327
+ title = { 'Diff this file' }
328
+ onClick = { ( ) => {
329
+ openDiffView (
330
+ this . props . file . to ,
331
+ this . props . app ,
332
+ {
333
+ previousRef : { gitRef : 'HEAD' } ,
334
+ currentRef : { specialRef : currentRef . specialRef }
335
+ } ,
336
+ this . props . renderMime
337
+ ) ;
338
+ } }
339
+ />
340
+ ) ;
341
+ }
298
342
}
0 commit comments