@@ -133,6 +133,12 @@ public List<string> RevisionFileSearchSuggestion
133
133
private set => SetProperty ( ref _revisionFileSearchSuggestion , value ) ;
134
134
}
135
135
136
+ public bool CanOpenRevisionFileWithDefaultEditor
137
+ {
138
+ get => _canOpenRevisionFileWithDefaultEditor ;
139
+ private set => SetProperty ( ref _canOpenRevisionFileWithDefaultEditor , value ) ;
140
+ }
141
+
136
142
public CommitDetail ( Repository repo )
137
143
{
138
144
_repo = repo ;
@@ -197,6 +203,7 @@ public void ViewRevisionFile(Models.Object file)
197
203
{
198
204
ViewRevisionFilePath = string . Empty ;
199
205
ViewRevisionFileContent = null ;
206
+ CanOpenRevisionFileWithDefaultEditor = false ;
200
207
return ;
201
208
}
202
209
@@ -205,6 +212,7 @@ public void ViewRevisionFile(Models.Object file)
205
212
switch ( file . Type )
206
213
{
207
214
case Models . ObjectType . Blob :
215
+ CanOpenRevisionFileWithDefaultEditor = true ;
208
216
Task . Run ( ( ) =>
209
217
{
210
218
var isBinary = new Commands . IsBinary ( _repo . FullPath , _commit . SHA , file . Path ) . Result ( ) ;
@@ -252,6 +260,7 @@ public void ViewRevisionFile(Models.Object file)
252
260
} ) ;
253
261
break ;
254
262
case Models . ObjectType . Commit :
263
+ CanOpenRevisionFileWithDefaultEditor = false ;
255
264
Task . Run ( ( ) =>
256
265
{
257
266
var submoduleRoot = Path . Combine ( _repo . FullPath , file . Path ) . Replace ( '\\ ' , '/' ) . Trim ( '/' ) ;
@@ -267,11 +276,26 @@ public void ViewRevisionFile(Models.Object file)
267
276
} ) ;
268
277
break ;
269
278
default :
279
+ CanOpenRevisionFileWithDefaultEditor = false ;
270
280
ViewRevisionFileContent = null ;
271
281
break ;
272
282
}
273
283
}
274
284
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
+
275
299
public ContextMenu CreateChangeContextMenu ( Models . Change change )
276
300
{
277
301
var diffWithMerger = new MenuItem ( ) ;
@@ -421,13 +445,10 @@ public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
421
445
var openWith = new MenuItem ( ) ;
422
446
openWith . Header = App . Text ( "OpenWith" ) ;
423
447
openWith . Icon = App . CreateMenuIcon ( "Icons.OpenWith" ) ;
448
+ openWith . IsEnabled = file . Type == Models . ObjectType . Blob ;
424
449
openWith . Click += async ( _ , ev ) =>
425
450
{
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 ) ;
431
452
ev . Handled = true ;
432
453
} ;
433
454
@@ -887,5 +908,6 @@ private Task ResetToParentRevision(Models.Change change)
887
908
private List < string > _revisionFiles = null ;
888
909
private string _revisionFileSearchFilter = string . Empty ;
889
910
private List < string > _revisionFileSearchSuggestion = null ;
911
+ private bool _canOpenRevisionFileWithDefaultEditor = false ;
890
912
}
891
913
}
0 commit comments