1
1
import { Dialog , showDialog , showErrorMessage } from '@jupyterlab/apputils' ;
2
+ import { PathExt } from '@jupyterlab/coreutils' ;
2
3
import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
3
4
import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
4
5
import { Menu } from '@lumino/widgets' ;
@@ -30,6 +31,8 @@ export namespace CommandIDs {
30
31
export const gitFileDiscard = 'git:context-discard' ;
31
32
export const gitFileDiffWorking = 'git:context-diffWorking' ;
32
33
export const gitFileDiffIndex = 'git:context-diffIndex' ;
34
+ export const gitIgnore = 'git:context-ignore' ;
35
+ export const gitIgnoreExtension = 'git:context-ignoreExtension' ;
33
36
}
34
37
35
38
export interface IFileListState {
@@ -51,6 +54,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
51
54
this . _contextMenuStaged = new Menu ( { commands } ) ;
52
55
this . _contextMenuUnstaged = new Menu ( { commands } ) ;
53
56
this . _contextMenuUntracked = new Menu ( { commands } ) ;
57
+ this . _contextMenuUntrackedMin = new Menu ( { commands } ) ;
54
58
this . _contextMenuSimpleUntracked = new Menu ( { commands } ) ;
55
59
this . _contextMenuSimpleTracked = new Menu ( { commands } ) ;
56
60
@@ -148,6 +152,51 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
148
152
} ) ;
149
153
}
150
154
155
+ if ( ! commands . hasCommand ( CommandIDs . gitIgnore ) ) {
156
+ commands . addCommand ( CommandIDs . gitIgnore , {
157
+ label : ( ) => 'Ignore this file (add to .gitignore)' ,
158
+ caption : ( ) => 'Ignore this file (add to .gitignore)' ,
159
+ execute : async ( ) => {
160
+ if ( this . state . selectedFile ) {
161
+ await this . props . model . ignore ( this . state . selectedFile . to , false ) ;
162
+ await this . props . model . commands . execute ( 'docmanager:reload' ) ;
163
+ await this . props . model . commands . execute ( 'docmanager:open' , {
164
+ path : this . props . model . getRelativeFilePath ( '.gitignore' )
165
+ } ) ;
166
+ }
167
+ }
168
+ } ) ;
169
+ }
170
+
171
+ if ( ! commands . hasCommand ( CommandIDs . gitIgnoreExtension ) ) {
172
+ commands . addCommand ( CommandIDs . gitIgnoreExtension , {
173
+ label : 'Ignore this file extension (add to .gitignore)' ,
174
+ caption : 'Ignore this file extension (add to .gitignore)' ,
175
+ execute : async ( ) => {
176
+ if ( this . state . selectedFile ) {
177
+ const extension = PathExt . extname ( this . state . selectedFile . to ) ;
178
+ if ( extension . length > 0 ) {
179
+ const result = await showDialog ( {
180
+ title : 'Ignore file extension' ,
181
+ body : `Are you sure you want to ignore all ${ extension } files within this git repository?` ,
182
+ buttons : [
183
+ Dialog . cancelButton ( ) ,
184
+ Dialog . okButton ( { label : 'Ignore' } )
185
+ ]
186
+ } ) ;
187
+ if ( result . button . label === 'Ignore' ) {
188
+ await this . props . model . ignore ( this . state . selectedFile . to , true ) ;
189
+ await this . props . model . commands . execute ( 'docmanager:reload' ) ;
190
+ await this . props . model . commands . execute ( 'docmanager:open' , {
191
+ path : this . props . model . getRelativeFilePath ( '.gitignore' )
192
+ } ) ;
193
+ }
194
+ }
195
+ }
196
+ }
197
+ } ) ;
198
+ }
199
+
151
200
[
152
201
CommandIDs . gitFileOpen ,
153
202
CommandIDs . gitFileUnstage ,
@@ -165,10 +214,23 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
165
214
this . _contextMenuUnstaged . addItem ( { command } ) ;
166
215
} ) ;
167
216
168
- [ CommandIDs . gitFileOpen , CommandIDs . gitFileTrack ] . forEach ( command => {
217
+ [
218
+ CommandIDs . gitFileOpen ,
219
+ CommandIDs . gitFileTrack ,
220
+ CommandIDs . gitIgnore ,
221
+ CommandIDs . gitIgnoreExtension
222
+ ] . forEach ( command => {
169
223
this . _contextMenuUntracked . addItem ( { command } ) ;
170
224
} ) ;
171
225
226
+ [
227
+ CommandIDs . gitFileOpen ,
228
+ CommandIDs . gitFileTrack ,
229
+ CommandIDs . gitIgnore
230
+ ] . forEach ( command => {
231
+ this . _contextMenuUntrackedMin . addItem ( { command } ) ;
232
+ } ) ;
233
+
172
234
[
173
235
CommandIDs . gitFileOpen ,
174
236
CommandIDs . gitFileDiscard ,
@@ -197,7 +259,12 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
197
259
/** Handle right-click on an untracked file */
198
260
contextMenuUntracked = ( event : React . MouseEvent ) => {
199
261
event . preventDefault ( ) ;
200
- this . _contextMenuUntracked . open ( event . clientX , event . clientY ) ;
262
+ const extension = PathExt . extname ( this . state . selectedFile . to ) ;
263
+ if ( extension . length > 0 ) {
264
+ this . _contextMenuUntracked . open ( event . clientX , event . clientY ) ;
265
+ } else {
266
+ this . _contextMenuUntrackedMin . open ( event . clientX , event . clientY ) ;
267
+ }
201
268
} ;
202
269
203
270
/** Handle right-click on an untracked file in Simple mode*/
@@ -751,6 +818,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
751
818
private _contextMenuStaged : Menu ;
752
819
private _contextMenuUnstaged : Menu ;
753
820
private _contextMenuUntracked : Menu ;
821
+ private _contextMenuUntrackedMin : Menu ;
754
822
private _contextMenuSimpleTracked : Menu ;
755
823
private _contextMenuSimpleUntracked : Menu ;
756
824
}
0 commit comments