@@ -12,16 +12,28 @@ namespace SourceGit.Models
1212{
1313 public class ExternalTool
1414 {
15+ public class LaunchOption
16+ {
17+ public string Title { get ; set ; }
18+ public string Args { get ; set ; }
19+
20+ public LaunchOption ( string title , string args )
21+ {
22+ Title = title ;
23+ Args = args ;
24+ }
25+ }
26+
1527 public string Name { get ; }
1628 public string ExecFile { get ; }
1729 public Bitmap IconImage { get ; }
1830
19- public ExternalTool ( string name , string icon , string execFile , Func < string , string > execArgsGenerator = null , Func < string , List < string > > subOptionsFinder = null )
31+ public ExternalTool ( string name , string icon , string execFile , Func < string , List < LaunchOption > > optionsGenerator = null )
2032 {
2133 Name = name ;
2234 ExecFile = execFile ;
23- _execArgsGenerator = execArgsGenerator ?? ( path => path . Quoted ( ) ) ;
24- _subOptionsFinder = subOptionsFinder ;
35+
36+ _optionsGenerator = optionsGenerator ;
2537
2638 try
2739 {
@@ -35,30 +47,25 @@ public ExternalTool(string name, string icon, string execFile, Func<string, stri
3547 }
3648 }
3749
38- public void Open ( string path )
50+ public List < LaunchOption > MakeLaunchOptions ( string repo )
3951 {
40- // The executable file may be removed after the tool list is loaded (once time on startup).
41- if ( ! File . Exists ( ExecFile ) )
42- return ;
43-
44- Process . Start ( new ProcessStartInfo ( )
45- {
46- FileName = ExecFile ,
47- Arguments = _execArgsGenerator . Invoke ( path ) ,
48- UseShellExecute = false ,
49- } ) ;
52+ return _optionsGenerator ? . Invoke ( repo ) ;
5053 }
5154
52- public List < string > FindSubOptions ( string path )
55+ public void Launch ( string args )
5356 {
54- if ( _subOptionsFinder == null )
55- return null ;
56-
57- return _subOptionsFinder . Invoke ( path ) ;
57+ if ( File . Exists ( ExecFile ) )
58+ {
59+ Process . Start ( new ProcessStartInfo ( )
60+ {
61+ FileName = ExecFile ,
62+ Arguments = args ,
63+ UseShellExecute = false ,
64+ } ) ;
65+ }
5866 }
5967
60- private Func < string , string > _execArgsGenerator = null ;
61- private Func < string , List < string > > _subOptionsFinder = null ;
68+ private Func < string , List < LaunchOption > > _optionsGenerator = null ;
6269 }
6370
6471 public class VisualStudioInstance
@@ -140,20 +147,20 @@ public ExternalToolsFinder()
140147 _customization ??= new ExternalToolCustomization ( ) ;
141148 }
142149
143- public void TryAdd ( string name , string icon , Func < string > finder , Func < string , string > execArgsGenerator = null , Func < string , List < string > > subOptionsFinder = null )
150+ public void TryAdd ( string name , string icon , Func < string > finder , Func < string , List < ExternalTool . LaunchOption > > optionsGenerator = null )
144151 {
145152 if ( _customization . Excludes . Contains ( name ) )
146153 return ;
147154
148155 if ( _customization . Tools . TryGetValue ( name , out var customPath ) && File . Exists ( customPath ) )
149156 {
150- Tools . Add ( new ExternalTool ( name , icon , customPath , execArgsGenerator , subOptionsFinder ) ) ;
157+ Tools . Add ( new ExternalTool ( name , icon , customPath , optionsGenerator ) ) ;
151158 }
152159 else
153160 {
154161 var path = finder ( ) ;
155162 if ( ! string . IsNullOrEmpty ( path ) && File . Exists ( path ) )
156- Tools . Add ( new ExternalTool ( name , icon , path , execArgsGenerator , subOptionsFinder ) ) ;
163+ Tools . Add ( new ExternalTool ( name , icon , path , optionsGenerator ) ) ;
157164 }
158165 }
159166
0 commit comments