@@ -581,7 +581,7 @@ public void CommitWithPush()
581581 DoCommit ( false , true ) ;
582582 }
583583
584- public ContextMenu CreateContextMenuForUnstagedChanges ( )
584+ public ContextMenu CreateContextMenuForUnstagedChanges ( string selectedSingleFolder )
585585 {
586586 if ( _selectedUnstaged == null || _selectedUnstaged . Count == 0 )
587587 return null ;
@@ -761,52 +761,87 @@ public ContextMenu CreateContextMenuForUnstagedChanges()
761761 var hasExtra = false ;
762762 if ( change . WorkTree == Models . ChangeState . Untracked )
763763 {
764- var isRooted = change . Path . IndexOf ( '/' , StringComparison . Ordinal ) <= 0 ;
765764 var addToIgnore = new MenuItem ( ) ;
766765 addToIgnore . Header = App . Text ( "WorkingCopy.AddToGitIgnore" ) ;
767766 addToIgnore . Icon = App . CreateMenuIcon ( "Icons.GitIgnore" ) ;
768767
769- var singleFile = new MenuItem ( ) ;
770- singleFile . Header = App . Text ( "WorkingCopy.AddToGitIgnore.SingleFile" ) ;
771- singleFile . Click += ( _ , e ) =>
768+ if ( ! string . IsNullOrEmpty ( selectedSingleFolder ) )
772769 {
773- Commands . GitIgnore . Add ( _repo . FullPath , change . Path ) ;
774- e . Handled = true ;
775- } ;
776- addToIgnore . Items . Add ( singleFile ) ;
777-
778- var byParentFolder = new MenuItem ( ) ;
779- byParentFolder . Header = App . Text ( "WorkingCopy.AddToGitIgnore.InSameFolder" ) ;
780- byParentFolder . IsVisible = ! isRooted ;
781- byParentFolder . Click += ( _ , e ) =>
782- {
783- var dir = Path . GetDirectoryName ( change . Path ) ! . Replace ( '\\ ' , '/' ) . TrimEnd ( '/' ) ;
784- Commands . GitIgnore . Add ( _repo . FullPath , dir + "/" ) ;
785- e . Handled = true ;
786- } ;
787- addToIgnore . Items . Add ( byParentFolder ) ;
788-
789- if ( ! string . IsNullOrEmpty ( extension ) )
770+ var ignoreFolder = new MenuItem ( ) ;
771+ ignoreFolder . Header = App . Text ( "WorkingCopy.AddToGitIgnore.InFolder" ) ;
772+ ignoreFolder . Click += ( _ , e ) =>
773+ {
774+ Commands . GitIgnore . Add ( _repo . FullPath , $ "{ selectedSingleFolder } /") ;
775+ e . Handled = true ;
776+ } ;
777+ addToIgnore . Items . Add ( ignoreFolder ) ;
778+ }
779+ else
790780 {
791- var byExtension = new MenuItem ( ) ;
792- byExtension . Header = App . Text ( "WorkingCopy.AddToGitIgnore.Extension" , extension ) ;
793- byExtension . Click += ( _ , e ) =>
781+ var isRooted = change . Path . IndexOf ( '/' , StringComparison . Ordinal ) <= 0 ;
782+ var singleFile = new MenuItem ( ) ;
783+ singleFile . Header = App . Text ( "WorkingCopy.AddToGitIgnore.SingleFile" ) ;
784+ singleFile . Click += ( _ , e ) =>
794785 {
795- Commands . GitIgnore . Add ( _repo . FullPath , $ "* { extension } " ) ;
786+ Commands . GitIgnore . Add ( _repo . FullPath , change . Path ) ;
796787 e . Handled = true ;
797788 } ;
798- addToIgnore . Items . Add ( byExtension ) ;
789+ addToIgnore . Items . Add ( singleFile ) ;
799790
800- var byExtensionInSameFolder = new MenuItem ( ) ;
801- byExtensionInSameFolder . Header = App . Text ( "WorkingCopy.AddToGitIgnore.ExtensionInSameFolder" , extension ) ;
802- byExtensionInSameFolder . IsVisible = ! isRooted ;
803- byExtensionInSameFolder . Click += ( _ , e ) =>
791+ var byParentFolder = new MenuItem ( ) ;
792+ byParentFolder . Header = App . Text ( "WorkingCopy.AddToGitIgnore.InSameFolder" ) ;
793+ byParentFolder . IsVisible = ! isRooted ;
794+ byParentFolder . Click += ( _ , e ) =>
804795 {
805796 var dir = Path . GetDirectoryName ( change . Path ) ! . Replace ( '\\ ' , '/' ) . TrimEnd ( '/' ) ;
806- Commands . GitIgnore . Add ( _repo . FullPath , $ " { dir } /* { extension } ") ;
797+ Commands . GitIgnore . Add ( _repo . FullPath , dir + "/ ") ;
807798 e . Handled = true ;
808799 } ;
809- addToIgnore . Items . Add ( byExtensionInSameFolder ) ;
800+ addToIgnore . Items . Add ( byParentFolder ) ;
801+
802+ if ( ! string . IsNullOrEmpty ( extension ) )
803+ {
804+ var byExtension = new MenuItem ( ) ;
805+ byExtension . Header = App . Text ( "WorkingCopy.AddToGitIgnore.Extension" , extension ) ;
806+ byExtension . Click += ( _ , e ) =>
807+ {
808+ Commands . GitIgnore . Add ( _repo . FullPath , $ "*{ extension } ") ;
809+ e . Handled = true ;
810+ } ;
811+ addToIgnore . Items . Add ( byExtension ) ;
812+
813+ var byExtensionInSameFolder = new MenuItem ( ) ;
814+ byExtensionInSameFolder . Header = App . Text ( "WorkingCopy.AddToGitIgnore.ExtensionInSameFolder" , extension ) ;
815+ byExtensionInSameFolder . IsVisible = ! isRooted ;
816+ byExtensionInSameFolder . Click += ( _ , e ) =>
817+ {
818+ var dir = Path . GetDirectoryName ( change . Path ) ! . Replace ( '\\ ' , '/' ) . TrimEnd ( '/' ) ;
819+ Commands . GitIgnore . Add ( _repo . FullPath , $ "{ dir } /*{ extension } ") ;
820+ e . Handled = true ;
821+ } ;
822+ addToIgnore . Items . Add ( byExtensionInSameFolder ) ;
823+ }
824+ }
825+
826+ menu . Items . Add ( addToIgnore ) ;
827+ hasExtra = true ;
828+ }
829+ else if ( ! string . IsNullOrEmpty ( selectedSingleFolder ) )
830+ {
831+ var addToIgnore = new MenuItem ( ) ;
832+ addToIgnore . Header = App . Text ( "WorkingCopy.AddToGitIgnore" ) ;
833+ addToIgnore . Icon = App . CreateMenuIcon ( "Icons.GitIgnore" ) ;
834+
835+ if ( ! string . IsNullOrEmpty ( selectedSingleFolder ) )
836+ {
837+ var ignoreFolder = new MenuItem ( ) ;
838+ ignoreFolder . Header = App . Text ( "WorkingCopy.AddToGitIgnore.InFolder" ) ;
839+ ignoreFolder . Click += ( _ , e ) =>
840+ {
841+ Commands . GitIgnore . Add ( _repo . FullPath , $ "{ selectedSingleFolder } /") ;
842+ e . Handled = true ;
843+ } ;
844+ addToIgnore . Items . Add ( ignoreFolder ) ;
810845 }
811846
812847 menu . Items . Add ( addToIgnore ) ;
@@ -1086,6 +1121,25 @@ public ContextMenu CreateContextMenuForUnstagedChanges()
10861121 menu . Items . Add ( discard ) ;
10871122 menu . Items . Add ( stash ) ;
10881123 menu . Items . Add ( patch ) ;
1124+
1125+ if ( ! string . IsNullOrEmpty ( selectedSingleFolder ) )
1126+ {
1127+ var ignoreFolder = new MenuItem ( ) ;
1128+ ignoreFolder . Header = App . Text ( "WorkingCopy.AddToGitIgnore.InFolder" ) ;
1129+ ignoreFolder . Click += ( _ , e ) =>
1130+ {
1131+ Commands . GitIgnore . Add ( _repo . FullPath , $ "{ selectedSingleFolder } /") ;
1132+ e . Handled = true ;
1133+ } ;
1134+
1135+ var addToIgnore = new MenuItem ( ) ;
1136+ addToIgnore . Header = App . Text ( "WorkingCopy.AddToGitIgnore" ) ;
1137+ addToIgnore . Icon = App . CreateMenuIcon ( "Icons.GitIgnore" ) ;
1138+ addToIgnore . Items . Add ( ignoreFolder ) ;
1139+
1140+ menu . Items . Add ( new MenuItem ( ) { Header = "-" } ) ;
1141+ menu . Items . Add ( addToIgnore ) ;
1142+ }
10891143 }
10901144
10911145 return menu ;
0 commit comments