11import { Dialog , showDialog , showErrorMessage } from '@jupyterlab/apputils' ;
2+ import { PathExt } from '@jupyterlab/coreutils' ;
23import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
34import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
45import { Menu } from '@lumino/widgets' ;
@@ -30,6 +31,8 @@ export namespace CommandIDs {
3031 export const gitFileDiscard = 'git:context-discard' ;
3132 export const gitFileDiffWorking = 'git:context-diffWorking' ;
3233 export const gitFileDiffIndex = 'git:context-diffIndex' ;
34+ export const gitIgnore = 'git:context-ignore' ;
35+ export const gitIgnoreExtension = 'git:context-ignoreExtension' ;
3336}
3437
3538export interface IFileListState {
@@ -51,6 +54,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
5154 this . _contextMenuStaged = new Menu ( { commands } ) ;
5255 this . _contextMenuUnstaged = new Menu ( { commands } ) ;
5356 this . _contextMenuUntracked = new Menu ( { commands } ) ;
57+ this . _contextMenuUntrackedMin = new Menu ( { commands } ) ;
5458 this . _contextMenuSimpleUntracked = new Menu ( { commands } ) ;
5559 this . _contextMenuSimpleTracked = new Menu ( { commands } ) ;
5660
@@ -148,6 +152,51 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
148152 } ) ;
149153 }
150154
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+
151200 [
152201 CommandIDs . gitFileOpen ,
153202 CommandIDs . gitFileUnstage ,
@@ -165,10 +214,23 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
165214 this . _contextMenuUnstaged . addItem ( { command } ) ;
166215 } ) ;
167216
168- [ CommandIDs . gitFileOpen , CommandIDs . gitFileTrack ] . forEach ( command => {
217+ [
218+ CommandIDs . gitFileOpen ,
219+ CommandIDs . gitFileTrack ,
220+ CommandIDs . gitIgnore ,
221+ CommandIDs . gitIgnoreExtension
222+ ] . forEach ( command => {
169223 this . _contextMenuUntracked . addItem ( { command } ) ;
170224 } ) ;
171225
226+ [
227+ CommandIDs . gitFileOpen ,
228+ CommandIDs . gitFileTrack ,
229+ CommandIDs . gitIgnore
230+ ] . forEach ( command => {
231+ this . _contextMenuUntrackedMin . addItem ( { command } ) ;
232+ } ) ;
233+
172234 [
173235 CommandIDs . gitFileOpen ,
174236 CommandIDs . gitFileDiscard ,
@@ -197,7 +259,12 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
197259 /** Handle right-click on an untracked file */
198260 contextMenuUntracked = ( event : React . MouseEvent ) => {
199261 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+ }
201268 } ;
202269
203270 /** Handle right-click on an untracked file in Simple mode*/
@@ -751,6 +818,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
751818 private _contextMenuStaged : Menu ;
752819 private _contextMenuUnstaged : Menu ;
753820 private _contextMenuUntracked : Menu ;
821+ private _contextMenuUntrackedMin : Menu ;
754822 private _contextMenuSimpleTracked : Menu ;
755823 private _contextMenuSimpleUntracked : Menu ;
756824}
0 commit comments