-
Notifications
You must be signed in to change notification settings - Fork 107
/
PendingChangesToolWindow.cs
116 lines (95 loc) · 4.43 KB
/
PendingChangesToolWindow.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
using System;
using System.ComponentModel.Design;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio;
namespace GitScc
{
/// <summary>
/// Summary description for SccProviderToolWindow.
/// </summary>
[Guid("75EDECF4-68D8-4B7B-92A9-5915461DA6D9")]
public class PendingChangesToolWindow : ToolWindowWithEditor<PendingChangesView>
{
private SccProviderService sccProviderService;
public PendingChangesToolWindow()
{
// set the window title
this.Caption = Resources.ResourceManager.GetString("PendingChangesToolWindowCaption");
//// set the CommandID for the window ToolBar
base.ToolBar = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.imnuPendingChangesToolWindowToolbarMenu);
// set the icon for the frame
this.BitmapResourceID = CommandId.ibmpToolWindowsImages; // bitmap strip resource ID
this.BitmapIndex = CommandId.iconSccProviderToolWindow; // index in the bitmap strip
}
protected override void Initialize()
{
base.Initialize();
control = new PendingChangesView(this);
// This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
// we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
// the object returned by the Content property.
base.Content = control;
OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
//var cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdPendingChangesCommit);
//var 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);
var cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdPendingChangesRefresh);
var menu = new MenuCommand(new EventHandler(OnRefreshCommand), cmd);
mcs.AddCommand(menu);
//sccProviderService = BasicSccProvider.GetServiceEx<SccProviderService>();
//Refresh(sccProviderService.CurrentTracker, true); // refresh when the tool window becomes visible
}
public override void OnToolWindowCreated()
{
sccProviderService = BasicSccProvider.GetServiceEx<SccProviderService>();
Refresh(sccProviderService.CurrentTracker); // refresh when the tool window becomes visible
}
internal bool hasFileSaved()
{
var dte = BasicSccProvider.GetServiceEx<EnvDTE.DTE>();
return dte.ItemOperations.PromptToSave != EnvDTE.vsPromptResult.vsPromptResultCancelled;
}
internal void OnCommitCommand()
{
if (!hasFileSaved()) return;
control.Commit();
}
internal void OnAmendCommitCommand()
{
if (!hasFileSaved()) return;
control.AmendCommit();
}
private void OnRefreshCommand(object sender, EventArgs e)
{
hasFileSaved(); //just a reminder, refresh anyway
sccProviderService.Refresh();
}
internal void Refresh(GitFileStatusTracker tracker)
{
try
{
var repository = (tracker == null || !tracker.HasGitRepository) ? "" :
string.Format(" ({0})", tracker.CurrentBranch, tracker.GitWorkingDirectory);
this.Caption = Resources.ResourceManager.GetString("PendingChangesToolWindowCaption") + repository;
control.Refresh(tracker);
if (GitSccOptions.Current.DisableAutoRefresh)
{
this.Caption += " - [AUTO REFRESH DISABLED]";
}
}
catch (Exception ex)
{
Log.WriteLine("Pending Changes Tool Window Refresh: {0}", ex.ToString());
}
}
internal void OnSettings()
{
control.OnSettings();
}
}
}