-
Notifications
You must be signed in to change notification settings - Fork 107
/
BasicSccProvider.cs
600 lines (500 loc) · 26.8 KB
/
BasicSccProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.ComponentModel.Design;
using Microsoft.Win32;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio;
using MsVsShell = Microsoft.VisualStudio.Shell;
using ErrorHandler = Microsoft.VisualStudio.ErrorHandler;
using Microsoft.VisualStudio.Shell;
using System.IO;
using System.Collections.Generic;
using GitScc.UI;
using System.Reflection;
namespace GitScc
{
/////////////////////////////////////////////////////////////////////////////
// BasicSccProvider
[MsVsShell.ProvideLoadKey("Standard", "0.1", "Git Source Control Provider", "[email protected]", 15261)]
[MsVsShell.DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\10.0Exp")]
// Register the package to have information displayed in Help/About dialog box
[MsVsShell.InstalledProductRegistration("#100", "#101", "1.0.0.0", IconResourceID = CommandId.iiconProductIcon)]
// Declare that resources for the package are to be found in the managed assembly resources, and not in a satellite dll
[MsVsShell.PackageRegistration(UseManagedResourcesOnly = true)]
// Register the resource ID of the CTMENU section (generated from compiling the VSCT file), so the IDE will know how to merge this package's menus with the rest of the IDE when "devenv /setup" is run
// The menu resource ID needs to match the ResourceName number defined in the csproj project file in the VSCTCompile section
// Everytime the version number changes VS will automatically update the menus on startup; if the version doesn't change, you will need to run manually "devenv /setup /rootsuffix:Exp" to see VSCT changes reflected in IDE
[MsVsShell.ProvideMenuResource(1000, 1)]
// Register a sample options page visible as Tools/Options/SourceControl/SampleOptionsPage when the provider is active
[MsVsShell.ProvideOptionPageAttribute(typeof(SccProviderOptions), "Source Control", "Git Source Control Provider Options", 106, 107, false)]
[ProvideToolsOptionsPageVisibility("Source Control", "Git Source Control Provider Options", "C4128D99-0000-41D1-A6C3-704E6C1A3DE2")]
// Register a sample tool window visible only when the provider is active
[MsVsShell.ProvideToolWindow(typeof(PendingChangesToolWindow), Style = VsDockStyle.Tabbed, Orientation = ToolWindowOrientation.Bottom)]
[MsVsShell.ProvideToolWindowVisibility(typeof(PendingChangesToolWindow), "C4128D99-0000-41D1-A6C3-704E6C1A3DE2")]
//[MsVsShell.ProvideToolWindow(typeof(HistoryToolWindow), Style = VsDockStyle.Tabbed, Orientation = ToolWindowOrientation.Bottom)]
//[MsVsShell.ProvideToolWindowVisibility(typeof(HistoryToolWindow), "C4128D99-0000-41D1-A6C3-704E6C1A3DE2")]
//Register the source control provider's service (implementing IVsScciProvider interface)
[MsVsShell.ProvideService(typeof(SccProviderService), ServiceName = "Git Source Control Service")]
// Register the source control provider to be visible in Tools/Options/SourceControl/Plugin dropdown selector
[ProvideSourceControlProvider("Git Source Control Provider", "#100")]
// Pre-load the package when the command UI context is asserted (the provider will be automatically loaded after restarting the shell if it was active last time the shell was shutdown)
[MsVsShell.ProvideAutoLoad("C4128D99-0000-41D1-A6C3-704E6C1A3DE2")]
//[ProvideAutoLoad(UIContextGuids.SolutionExists)]
// Declare the package guid
[Guid("C4128D99-2000-41D1-A6C3-704E6C1A3DE2")]
public class BasicSccProvider : MsVsShell.Package, IOleCommandTarget
{
private SccOnIdleEvent _OnIdleEvent = new SccOnIdleEvent();
private List<GitFileStatusTracker> projects;
private SccProviderService sccService = null;
public BasicSccProvider()
{
_SccProvider = this;
Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Entering constructor for: {0}", this.ToString()));
GitBash.GitExePath = GitSccOptions.Current.GitBashPath;
GitBash.UseUTF8FileNames = !GitSccOptions.Current.NotUseUTF8FileNames;
}
/////////////////////////////////////////////////////////////////////////////
// BasicSccProvider Package Implementation
#region Package Members
protected override void Initialize()
{
Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();
projects = new List<GitFileStatusTracker>();
sccService = new SccProviderService(this, projects);
((IServiceContainer)this).AddService(typeof(SccProviderService), sccService, true);
// Add our command handlers for menu (commands must exist in the .vsct file)
MsVsShell.OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as MsVsShell.OleMenuCommandService;
if (mcs != null)
{
CommandID cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandRefresh);
var menu = new MenuCommand(new EventHandler(OnRefreshCommand), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandGitBash);
menu = new MenuCommand(new EventHandler(OnGitBashCommand), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandGitExtension);
menu = new MenuCommand(new EventHandler(OnGitExtensionCommand), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandCompare);
menu = new MenuCommand(new EventHandler(OnCompareCommand), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandUndo);
menu = new MenuCommand(new EventHandler(OnUndoCommand), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandInit);
menu = new MenuCommand(new EventHandler(OnInitCommand), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandEditIgnore);
menu = new MenuCommand(new EventHandler(OnEditIgnore), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandGitTortoise);
menu = new MenuCommand(new EventHandler(OnTortoiseGitCommand), cmd);
mcs.AddCommand(menu);
for (int i = 0; i < GitToolCommands.GitExtCommands.Count; i++)
{
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdGitExtCommand1 + i);
var mc = new MenuCommand(new EventHandler(OnGitExtCommandExec), cmd);
mcs.AddCommand(mc);
}
for (int i = 0; i < GitToolCommands.GitTorCommands.Count; i++)
{
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdGitTorCommand1 + i);
var mc = new MenuCommand(new EventHandler(OnGitTorCommandExec), cmd);
mcs.AddCommand(mc);
}
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandPendingChanges);
menu = new MenuCommand(new EventHandler(ShowPendingChangesWindow), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandHistory);
menu = new MenuCommand(new EventHandler(ShowHistoryWindow), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdPendingChangesCommitToBranch);
menu = new MenuCommand(new EventHandler(OnSwitchBranchCommand), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdPendingChangesCommit);
menu = new MenuCommand(new EventHandler(OnCommitCommand), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdPendingChangesAmend);
menu = new MenuCommand(new EventHandler(OnAmendCommitCommand), cmd);
mcs.AddCommand(menu);
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdPendingChangesSettings);
menu = new MenuCommand(new EventHandler(OnSettings), cmd);
mcs.AddCommand(menu);
}
// Register the provider with the source control manager
// If the package is to become active, this will also callback on OnActiveStateChange and the menu commands will be enabled
IVsRegisterScciProvider rscp = (IVsRegisterScciProvider)GetService(typeof(IVsRegisterScciProvider));
rscp.RegisterSourceControlProvider(GuidList.guidSccProvider);
_OnIdleEvent.RegisterForIdleTimeCallbacks(GetGlobalService(typeof(SOleComponentManager)) as IOleComponentManager);
_OnIdleEvent.OnIdleEvent += new OnIdleEvent(sccService.UpdateNodesGlyphs);
}
protected override void Dispose(bool disposing)
{
Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Entering Dispose() of: {0}", this.ToString()));
_OnIdleEvent.OnIdleEvent -= new OnIdleEvent(sccService.UpdateNodesGlyphs);
_OnIdleEvent.UnRegisterForIdleTimeCallbacks();
sccService.Dispose();
base.Dispose(disposing);
}
#endregion
#region menu commands
int IOleCommandTarget.QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
{
Debug.Assert(cCmds == 1, "Multiple commands");
Debug.Assert(prgCmds != null, "NULL argument");
if ((prgCmds == null)) return VSConstants.E_INVALIDARG;
// Filter out commands that are not defined by this package
if (guidCmdGroup != GuidList.guidSccProviderCmdSet)
{
return (int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED);
}
OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED;
// All source control commands needs to be hidden and disabled when the provider is not active
if (!sccService.Active)
{
cmdf = cmdf | OLECMDF.OLECMDF_INVISIBLE;
cmdf = cmdf & ~(OLECMDF.OLECMDF_ENABLED);
prgCmds[0].cmdf = (uint)cmdf;
return VSConstants.S_OK;
}
// Process our Commands
switch (prgCmds[0].cmdID)
{
case CommandId.imnuGitSourceControlMenu:
OLECMDTEXT cmdtxtStructure = (OLECMDTEXT)Marshal.PtrToStructure(pCmdText, typeof(OLECMDTEXT));
if (cmdtxtStructure.cmdtextf == (uint)OLECMDTEXTF.OLECMDTEXTF_NAME)
{
var branchName = sccService.CurrentBranchName;
string menuText = string.IsNullOrEmpty(branchName) ?
"Git" : "Git (" + branchName + ")";
SetOleCmdText(pCmdText, menuText);
}
break;
case CommandId.icmdSccCommandGitBash:
if (GitBash.Exists)
{
cmdf |= OLECMDF.OLECMDF_ENABLED;
}
break;
case CommandId.icmdSccCommandGitExtension:
var gitExtensionPath = GitSccOptions.Current.GitExtensionPath;
if (!string.IsNullOrEmpty(gitExtensionPath) && File.Exists(gitExtensionPath) && GitSccOptions.Current.NotExpandGitExtensions)
{
cmdf |= OLECMDF.OLECMDF_ENABLED;
}
else
cmdf |= OLECMDF.OLECMDF_INVISIBLE;
break;
case CommandId.icmdSccCommandGitTortoise:
var tortoiseGitPath = GitSccOptions.Current.TortoiseGitPath;
if (!string.IsNullOrEmpty(tortoiseGitPath) && File.Exists(tortoiseGitPath) && GitSccOptions.Current.NotExpandTortoiseGit)
{
cmdf |= OLECMDF.OLECMDF_ENABLED;
}
else
cmdf |= OLECMDF.OLECMDF_INVISIBLE;
break;
case CommandId.icmdSccCommandUndo:
case CommandId.icmdSccCommandCompare:
if (GitBash.Exists && sccService.CanCompareSelectedFile) cmdf |= OLECMDF.OLECMDF_ENABLED;
break;
case CommandId.icmdSccCommandEditIgnore:
if (sccService.IsSolutionGitControlled) cmdf |= OLECMDF.OLECMDF_ENABLED;
break;
case CommandId.icmdSccCommandHistory:
case CommandId.icmdSccCommandPendingChanges:
case CommandId.icmdPendingChangesAmend:
case CommandId.icmdPendingChangesCommit:
case CommandId.icmdPendingChangesCommitToBranch:
if (GitBash.Exists && sccService.IsSolutionGitControlled) cmdf |= OLECMDF.OLECMDF_ENABLED;
break;
case CommandId.icmdSccCommandRefresh:
//if (sccService.IsSolutionGitControlled)
cmdf |= OLECMDF.OLECMDF_ENABLED;
break;
case CommandId.icmdSccCommandInit:
if (!sccService.IsSolutionGitControlled)
cmdf |= OLECMDF.OLECMDF_ENABLED;
else
cmdf |= OLECMDF.OLECMDF_INVISIBLE;
break;
case CommandId.icmdPendingChangesSettings:
cmdf |= OLECMDF.OLECMDF_ENABLED;
break;
default:
var gitExtPath = GitSccOptions.Current.GitExtensionPath;
var torGitPath = GitSccOptions.Current.TortoiseGitPath;
if (prgCmds[0].cmdID >= CommandId.icmdGitExtCommand1 &&
prgCmds[0].cmdID < CommandId.icmdGitExtCommand1 + GitToolCommands.GitExtCommands.Count &&
!string.IsNullOrEmpty(gitExtPath) && File.Exists(gitExtPath) && !GitSccOptions.Current.NotExpandGitExtensions)
{
int idx = (int)prgCmds[0].cmdID - CommandId.icmdGitExtCommand1;
SetOleCmdText(pCmdText, GitToolCommands.GitExtCommands[idx].Name);
cmdf |= OLECMDF.OLECMDF_ENABLED;
break;
}
else if (prgCmds[0].cmdID >= CommandId.icmdGitTorCommand1 &&
prgCmds[0].cmdID < CommandId.icmdGitTorCommand1 + GitToolCommands.GitTorCommands.Count &&
!string.IsNullOrEmpty(torGitPath) && File.Exists(torGitPath) && !GitSccOptions.Current.NotExpandTortoiseGit)
{
int idx = (int)prgCmds[0].cmdID - CommandId.icmdGitTorCommand1;
SetOleCmdText(pCmdText, GitToolCommands.GitTorCommands[idx].Name);
cmdf |= OLECMDF.OLECMDF_ENABLED;
break;
}
else
return (int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED);
}
prgCmds[0].cmdf = (uint) (cmdf);
return VSConstants.S_OK;
}
public void SetOleCmdText(IntPtr pCmdText, string text)
{
OLECMDTEXT CmdText = (OLECMDTEXT)Marshal.PtrToStructure(pCmdText, typeof(OLECMDTEXT));
char[] buffer = text.ToCharArray();
IntPtr pText = (IntPtr)((long)pCmdText + (long)Marshal.OffsetOf(typeof(OLECMDTEXT), "rgwz"));
IntPtr pCwActual = (IntPtr)((long)pCmdText + (long)Marshal.OffsetOf(typeof(OLECMDTEXT), "cwActual"));
// The max chars we copy is our string, or one less than the buffer size,
// since we need a null at the end.
int maxChars = (int)Math.Min(CmdText.cwBuf - 1, buffer.Length);
Marshal.Copy(buffer, 0, pText, maxChars);
// append a null
Marshal.WriteInt16((IntPtr)((long)pText + (long)maxChars * 2), (Int16)0);
// write out the length + null char
Marshal.WriteInt32(pCwActual, maxChars + 1);
}
private void OnRefreshCommand(object sender, EventArgs e)
{
// explicit user refresh
sccService.Refresh();
}
private void OnCompareCommand(object sender, EventArgs e)
{
sccService.CompareSelectedFile();
}
private void OnUndoCommand(object sender, EventArgs e)
{
sccService.UndoSelectedFile();
}
private void OnGitBashCommand(object sender, EventArgs e)
{
var gitBashPath = GitSccOptions.Current.GitBashPath;
gitBashPath = gitBashPath.Replace("git.exe", "sh.exe");
RunDetatched("cmd.exe", string.Format("/c \"{0}\" --login -i", gitBashPath));
}
private void OnEditIgnore(object sender, EventArgs e)
{
sccService.EditIgnore();
}
private void OnGitExtensionCommand(object sender, EventArgs e)
{
var gitExtensionPath = GitSccOptions.Current.GitExtensionPath;
RunDetatched(gitExtensionPath, "");
}
internal void RunDiffCommand(string file1, string file2)
{
if (GitSccOptions.Current.UseVsDiff)
{
var diffService = (IVsDifferenceService)GetService(typeof(SVsDifferenceService));
if (diffService != null)
{
diffService.OpenComparisonWindow(file1, file2);
return;
}
}
var difftoolPath = GitSccOptions.Current.DifftoolPath;
if (string.IsNullOrWhiteSpace(difftoolPath)) difftoolPath = "diffmerge.exe";
try
{
RunCommand(difftoolPath, "\"" + file1 + "\" \"" + file2 + "\"");
}
catch (FileNotFoundException ex)
{
throw new FileNotFoundException(string.Format("Diff tool '{0}' is not available.", difftoolPath), difftoolPath, ex);
}
}
private void OnInitCommand(object sender, EventArgs e)
{
sccService.InitRepo();
}
private void OnTortoiseGitCommand(object sender, EventArgs e)
{
var tortoiseGitPath = GitSccOptions.Current.TortoiseGitPath;
RunDetatched(tortoiseGitPath, "/command:log");
}
private string GetTargetPath(GitToolCommand command)
{
var workingDirectory = sccService.CurrentGitWorkingDirectory;
if (command.Scope == CommandScope.Project) return workingDirectory;
var fileName = sccService.GetSelectFileName();
if (fileName == sccService.GetSolutionFileName()) return workingDirectory;
return fileName;
}
private void OnGitTorCommandExec(object sender, EventArgs e)
{
var menuCommand = sender as MenuCommand;
if (null != menuCommand)
{
int idx = menuCommand.CommandID.ID - CommandId.icmdGitTorCommand1;
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture,
"Run GitTor Command {0}", GitToolCommands.GitTorCommands[idx].Command));
var cmd = GitToolCommands.GitTorCommands[idx];
var targetPath = GetTargetPath(cmd);
var tortoiseGitPath = GitSccOptions.Current.TortoiseGitPath;
RunDetatched(tortoiseGitPath, cmd.Command + " /path:\"" + targetPath + "\"");
}
}
private void OnGitExtCommandExec(object sender, EventArgs e)
{
var menuCommand = sender as MenuCommand;
if (null != menuCommand)
{
int idx = menuCommand.CommandID.ID - CommandId.icmdGitExtCommand1;
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture,
"Run GitExt Command {0}", GitToolCommands.GitExtCommands[idx].Command));
var gitExtensionPath = GitSccOptions.Current.GitExtensionPath;
RunDetatched(gitExtensionPath, GitToolCommands.GitExtCommands[idx].Command);
}
}
private void ShowPendingChangesWindow(object sender, EventArgs e)
{
ShowToolWindow(typeof(PendingChangesToolWindow));
}
private void ShowHistoryWindow(object sender, EventArgs e)
{
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
path = Path.Combine(path, "Dragon.pkg");
var tmpPath = Path.Combine(Path.GetTempPath(), "Dragon.exe");
var needCopy = !File.Exists(tmpPath);
if(!needCopy)
{
var date1 = File.GetLastWriteTimeUtc(path);
var date2 = File.GetLastWriteTimeUtc(tmpPath);
needCopy = (date1>date2);
}
if (needCopy)
{
try
{
File.Copy(path, tmpPath, true);
}
catch // try copy file silently
{
}
}
if (File.Exists(tmpPath) && sccService.CurrentTracker != null)
{
Process.Start(tmpPath, "\"" + sccService.CurrentTracker.GitWorkingDirectory + "\"");
}
}
private void ShowToolWindow(Type type)
{
ToolWindowPane window = this.FindToolWindow(type, 0, true);
IVsWindowFrame windowFrame = null;
if (window != null && window.Frame != null)
{
windowFrame = (IVsWindowFrame)window.Frame;
}
if (windowFrame != null)
{
ErrorHandler.ThrowOnFailure(windowFrame.Show());
}
}
private void OnSwitchBranchCommand(object sender, EventArgs e)
{
if (sccService.CurrentTracker == null || sccService.CurrentTracker.Repository == null) return;
var branchPicker = new BranchPicker(
sccService.CurrentTracker.Repository,
sccService.CurrentTracker.RepositoryGraph.Refs);
branchPicker.Show();
}
private void OnCommitCommand(object sender, EventArgs e)
{
GetToolWindowPane<PendingChangesToolWindow>().OnCommitCommand();
}
private void OnAmendCommitCommand(object sender, EventArgs e)
{
GetToolWindowPane<PendingChangesToolWindow>().OnAmendCommitCommand();
}
private void OnSettings(object sender, EventArgs e)
{
GetToolWindowPane<PendingChangesToolWindow>().OnSettings();
}
#endregion
// This function is called by the IVsSccProvider service implementation when the active state of the provider changes
// The package needs to show or hide the scc-specific commands
public virtual void OnActiveStateChange()
{
}
public new Object GetService(Type serviceType)
{
return base.GetService(serviceType);
}
static BasicSccProvider _SccProvider = null;
public static T GetServiceEx<T>()
{
if(_SccProvider == null) return default(T);
return (T)_SccProvider.GetService(typeof(T));
}
#region Run Command
internal void RunCommand(string cmd, string args)
{
var pinfo = new ProcessStartInfo(cmd)
{
Arguments = args,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = sccService.CurrentGitWorkingDirectory ??
Path.GetDirectoryName(sccService.GetSolutionFileName())
};
Process.Start(pinfo);
//using (var process = Process.Start(pinfo))
//{
// string output = process.StandardOutput.ReadToEnd();
// string error = process.StandardError.ReadToEnd();
// process.WaitForExit();
// if (!string.IsNullOrEmpty(error))
// throw new Exception(error);
// return output;
//}
}
internal void RunDetatched(string cmd, string arguments)
{
using (Process process = new Process())
{
process.StartInfo.UseShellExecute = true;
process.StartInfo.ErrorDialog = false;
process.StartInfo.RedirectStandardOutput = false;
process.StartInfo.RedirectStandardInput = false;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.FileName = cmd;
process.StartInfo.Arguments = arguments;
process.StartInfo.WorkingDirectory = sccService.CurrentGitWorkingDirectory ??
Path.GetDirectoryName(sccService.GetSolutionFileName());
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.StartInfo.LoadUserProfile = true;
process.Start();
}
}
#endregion
//internal void OnSccStatusChanged()
//{
// var pendingChangesToolWindow = GetToolWindowPane<PendingChangesToolWindow>();
// if (pendingChangesToolWindow != null)
// {
// pendingChangesToolWindow.Refresh(sccService.CurrentTracker);
// }
//}
private T GetToolWindowPane<T>() where T : ToolWindowPane
{
return (T)this.FindToolWindow(typeof(T), 0, true);
}
}
}