@@ -133,6 +133,12 @@ public List<string> RevisionFileSearchSuggestion
133133 private set => SetProperty ( ref _revisionFileSearchSuggestion , value ) ;
134134 }
135135
136+ public bool CanOpenRevisionFileWithDefaultEditor
137+ {
138+ get => _canOpenRevisionFileWithDefaultEditor ;
139+ private set => SetProperty ( ref _canOpenRevisionFileWithDefaultEditor , value ) ;
140+ }
141+
136142 public CommitDetail ( Repository repo )
137143 {
138144 _repo = repo ;
@@ -197,6 +203,7 @@ public void ViewRevisionFile(Models.Object file)
197203 {
198204 ViewRevisionFilePath = string . Empty ;
199205 ViewRevisionFileContent = null ;
206+ CanOpenRevisionFileWithDefaultEditor = false ;
200207 return ;
201208 }
202209
@@ -205,6 +212,7 @@ public void ViewRevisionFile(Models.Object file)
205212 switch ( file . Type )
206213 {
207214 case Models . ObjectType . Blob :
215+ CanOpenRevisionFileWithDefaultEditor = true ;
208216 Task . Run ( ( ) =>
209217 {
210218 var isBinary = new Commands . IsBinary ( _repo . FullPath , _commit . SHA , file . Path ) . Result ( ) ;
@@ -252,6 +260,7 @@ public void ViewRevisionFile(Models.Object file)
252260 } ) ;
253261 break ;
254262 case Models . ObjectType . Commit :
263+ CanOpenRevisionFileWithDefaultEditor = false ;
255264 Task . Run ( ( ) =>
256265 {
257266 var submoduleRoot = Path . Combine ( _repo . FullPath , file . Path ) . Replace ( '\\ ' , '/' ) . Trim ( '/' ) ;
@@ -267,11 +276,26 @@ public void ViewRevisionFile(Models.Object file)
267276 } ) ;
268277 break ;
269278 default :
279+ CanOpenRevisionFileWithDefaultEditor = false ;
270280 ViewRevisionFileContent = null ;
271281 break ;
272282 }
273283 }
274284
285+ public Task OpenRevisionFileWithDefaultEditor ( string file )
286+ {
287+ return Task . Run ( ( ) =>
288+ {
289+ var fullPath = Native . OS . GetAbsPath ( _repo . FullPath , file ) ;
290+ var fileName = Path . GetFileNameWithoutExtension ( fullPath ) ?? "" ;
291+ var fileExt = Path . GetExtension ( fullPath ) ?? "" ;
292+ var tmpFile = Path . Combine ( Path . GetTempPath ( ) , $ "{ fileName } ~{ _commit . SHA . Substring ( 0 , 10 ) } { fileExt } ") ;
293+
294+ Commands . SaveRevisionFile . Run ( _repo . FullPath , _commit . SHA , file , tmpFile ) ;
295+ Native . OS . OpenWithDefaultEditor ( tmpFile ) ;
296+ } ) ;
297+ }
298+
275299 public ContextMenu CreateChangeContextMenu ( Models . Change change )
276300 {
277301 var diffWithMerger = new MenuItem ( ) ;
@@ -421,13 +445,10 @@ public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
421445 var openWith = new MenuItem ( ) ;
422446 openWith . Header = App . Text ( "OpenWith" ) ;
423447 openWith . Icon = App . CreateMenuIcon ( "Icons.OpenWith" ) ;
448+ openWith . IsEnabled = file . Type == Models . ObjectType . Blob ;
424449 openWith . Click += async ( _ , ev ) =>
425450 {
426- var fileName = Path . GetFileNameWithoutExtension ( fullPath ) ?? "" ;
427- var fileExt = Path . GetExtension ( fullPath ) ?? "" ;
428- var tmpFile = Path . Combine ( Path . GetTempPath ( ) , $ "{ fileName } ~{ _commit . SHA . Substring ( 0 , 10 ) } { fileExt } ") ;
429- await Task . Run ( ( ) => Commands . SaveRevisionFile . Run ( _repo . FullPath , _commit . SHA , file . Path , tmpFile ) ) ;
430- Native . OS . OpenWithDefaultEditor ( tmpFile ) ;
451+ await OpenRevisionFileWithDefaultEditor ( file . Path ) ;
431452 ev . Handled = true ;
432453 } ;
433454
@@ -887,5 +908,6 @@ private Task ResetToParentRevision(Models.Change change)
887908 private List < string > _revisionFiles = null ;
888909 private string _revisionFileSearchFilter = string . Empty ;
889910 private List < string > _revisionFileSearchSuggestion = null ;
911+ private bool _canOpenRevisionFileWithDefaultEditor = false ;
890912 }
891913}
0 commit comments