9
9
10
10
namespace SourceGit . ViewModels
11
11
{
12
- public class FileHistoriesRevisionFile ( string path , object content )
12
+ public class FileHistoriesRevisionFile ( string path , object content = null , bool canOpenWithDefaultEditor = false )
13
13
{
14
14
public string Path { get ; set ; } = path ;
15
15
public object Content { get ; set ; } = content ;
16
+ public bool CanOpenWithDefaultEditor { get ; set ; } = canOpenWithDefaultEditor ;
16
17
}
17
18
18
19
public class FileHistoriesSingleRevision : ObservableObject
@@ -49,6 +50,23 @@ public Task<bool> ResetToSelectedRevision()
49
50
return Task . Run ( ( ) => new Commands . Checkout ( _repo . FullPath ) . FileWithRevision ( _file , $ "{ _revision . SHA } ") ) ;
50
51
}
51
52
53
+ public Task OpenWithDefaultEditor ( )
54
+ {
55
+ if ( _viewContent is not FileHistoriesRevisionFile { CanOpenWithDefaultEditor : true } )
56
+ return null ;
57
+
58
+ return Task . Run ( ( ) =>
59
+ {
60
+ var fullPath = Native . OS . GetAbsPath ( _repo . FullPath , _file ) ;
61
+ var fileName = Path . GetFileNameWithoutExtension ( fullPath ) ?? "" ;
62
+ var fileExt = Path . GetExtension ( fullPath ) ?? "" ;
63
+ var tmpFile = Path . Combine ( Path . GetTempPath ( ) , $ "{ fileName } ~{ _revision . SHA . Substring ( 0 , 10 ) } { fileExt } ") ;
64
+
65
+ Commands . SaveRevisionFile . Run ( _repo . FullPath , _revision . SHA , _file , tmpFile ) ;
66
+ Native . OS . OpenWithDefaultEditor ( tmpFile ) ;
67
+ } ) ;
68
+ }
69
+
52
70
private void RefreshViewContent ( )
53
71
{
54
72
if ( _isDiffMode )
@@ -62,7 +80,7 @@ private void SetViewContentAsRevisionFile()
62
80
var objs = new Commands . QueryRevisionObjects ( _repo . FullPath , _revision . SHA , _file ) . Result ( ) ;
63
81
if ( objs . Count == 0 )
64
82
{
65
- ViewContent = new FileHistoriesRevisionFile ( _file , null ) ;
83
+ ViewContent = new FileHistoriesRevisionFile ( _file ) ;
66
84
return ;
67
85
}
68
86
@@ -80,13 +98,13 @@ private void SetViewContentAsRevisionFile()
80
98
{
81
99
var source = ImageSource . FromRevision ( _repo . FullPath , _revision . SHA , _file , imgDecoder ) ;
82
100
var image = new Models . RevisionImageFile ( _file , source . Bitmap , source . Size ) ;
83
- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , image ) ) ;
101
+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , image , true ) ) ;
84
102
}
85
103
else
86
104
{
87
105
var size = new Commands . QueryFileSize ( _repo . FullPath , _file , _revision . SHA ) . Result ( ) ;
88
106
var binaryFile = new Models . RevisionBinaryFile ( ) { Size = size } ;
89
- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , binaryFile ) ) ;
107
+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , binaryFile , true ) ) ;
90
108
}
91
109
92
110
return ;
@@ -101,18 +119,18 @@ private void SetViewContentAsRevisionFile()
101
119
if ( imgDecoder != Models . ImageDecoder . None )
102
120
{
103
121
var combined = new RevisionLFSImage ( _repo . FullPath , _file , lfs , imgDecoder ) ;
104
- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , combined ) ) ;
122
+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , combined , true ) ) ;
105
123
}
106
124
else
107
125
{
108
126
var rlfs = new Models . RevisionLFSObject ( ) { Object = lfs } ;
109
- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , rlfs ) ) ;
127
+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , rlfs , true ) ) ;
110
128
}
111
129
}
112
130
else
113
131
{
114
132
var txt = new Models . RevisionTextFile ( ) { FileName = obj . Path , Content = content } ;
115
- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , txt ) ) ;
133
+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , txt , true ) ) ;
116
134
}
117
135
} ) ;
118
136
break ;
@@ -132,7 +150,7 @@ private void SetViewContentAsRevisionFile()
132
150
} ) ;
133
151
break ;
134
152
default :
135
- ViewContent = new FileHistoriesRevisionFile ( _file , null ) ;
153
+ ViewContent = new FileHistoriesRevisionFile ( _file ) ;
136
154
break ;
137
155
}
138
156
}
0 commit comments