Skip to content

Commit f9709dc

Browse files
committed
add option page
1 parent c3de80b commit f9709dc

11 files changed

+724
-53
lines changed

BasicSccProvider.cs

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ namespace GitScc
2828
// 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
2929
[MsVsShell.ProvideMenuResource(1000, 1)]
3030
// Register a sample options page visible as Tools/Options/SourceControl/SampleOptionsPage when the provider is active
31-
//[MsVsShell.ProvideOptionPageAttribute(typeof(SccProviderOptions), "Source Control", "Sample Options Page Basic Provider", 106, 107, false)]
32-
//[ProvideToolsOptionsPageVisibility("Source Control", "Sample Options Page Basic Provider", "ADC98052-0000-41D1-A6C3-704E6C1A3DE2")]
31+
[MsVsShell.ProvideOptionPageAttribute(typeof(SccProviderOptions), "Source Control", "Git Source Control Provider Options", 106, 107, false)]
32+
[ProvideToolsOptionsPageVisibility("Source Control", "Git Source Control Provider Options", "C4128D99-0000-41D1-A6C3-704E6C1A3DE2")]
33+
3334
// Register a sample tool window visible only when the provider is active
3435
//[MsVsShell.ProvideToolWindow(typeof(SccProviderToolWindow))]
3536
//[MsVsShell.ProvideToolWindowVisibility(typeof(SccProviderToolWindow), "ADC98052-0000-41D1-A6C3-704E6C1A3DE2")]
@@ -59,8 +60,6 @@ protected override void Initialize()
5960
Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Entering Initialize() of: {0}", this.ToString()));
6061
base.Initialize();
6162

62-
LoadConfig();
63-
6463
// Proffer the source control service implemented by the provider
6564
sccService = new SccProviderService(this);
6665
((IServiceContainer)this).AddService(typeof(SccProviderService), sccService, true);
@@ -100,41 +99,15 @@ protected override void Initialize()
10099
rscp.RegisterSourceControlProvider(GuidList.guidSccProvider);
101100
}
102101

103-
private void LoadConfig()
104-
{
105-
if (string.IsNullOrEmpty(gitBashPath))
106-
{
107-
gitBashPath = TryFindFile(new string[]{
108-
@"C:\Program Files\Git\bin\sh.exe",
109-
@"C:\Program Files (x86)\Git\bin\sh.exe",
110-
});
111-
}
112-
if (string.IsNullOrEmpty(gitExtensionPath))
113-
{
114-
gitExtensionPath = TryFindFile(new string[]{
115-
@"C:\Program Files\GitExtensions\GitExtensions.exe",
116-
@"C:\Program Files (x86)\GitExtensions\GitExtensions.exe",
117-
});
118-
}
119-
if (string.IsNullOrEmpty(difftoolPath)) difftoolPath = "diffmerge.exe";
120-
}
121-
122-
private string TryFindFile(string[] paths)
123-
{
124-
foreach (var path in paths)
125-
{
126-
if (File.Exists(path)) return path;
127-
}
128-
return null;
129-
}
130-
131-
string gitBashPath, gitExtensionPath, difftoolPath;
102+
#endregion
132103

104+
#region menu commands
133105
void menu_BeforeQueryStatus_GitExtension(object sender, EventArgs e)
134106
{
135107
OleMenuCommand menu = sender as OleMenuCommand;
136108
if (menu != null)
137109
{
110+
var gitExtensionPath = GitSccOptions.Current.GitExtensionPath;
138111
menu.Enabled = !string.IsNullOrEmpty(gitExtensionPath) && File.Exists(gitExtensionPath);
139112
}
140113
}
@@ -144,6 +117,7 @@ void menu_BeforeQueryStatus_GitBash(object sender, EventArgs e)
144117
OleMenuCommand menu = sender as OleMenuCommand;
145118
if (menu != null)
146119
{
120+
var gitBashPath = GitSccOptions.Current.GitBashPath;
147121
menu.Enabled = !string.IsNullOrEmpty(gitBashPath) && File.Exists(gitBashPath);
148122
}
149123
}
@@ -164,8 +138,6 @@ protected override void Dispose(bool disposing)
164138
base.Dispose(disposing);
165139
}
166140

167-
#endregion
168-
169141
private void OnRefreshCommand(object sender, EventArgs e)
170142
{
171143
sccService.Refresh();
@@ -183,19 +155,24 @@ private void OnUndoCommand(object sender, EventArgs e)
183155

184156
private void OnGitBashCommand(object sender, EventArgs e)
185157
{
158+
var gitBashPath = GitSccOptions.Current.GitBashPath;
186159
RunDetatched("cmd.exe", string.Format("/c \"{0}\" --login -i", gitBashPath));
187160
}
188161

189162
private void OnGitExtensionCommand(object sender, EventArgs e)
190163
{
191-
RunCommand(gitExtensionPath, "");
164+
var gitExtensionPath = GitSccOptions.Current.GitExtensionPath;
165+
RunDetatched(gitExtensionPath, "");
192166
}
193167

194168
internal void RunDiffCommand(string file1, string file2)
195169
{
170+
var difftoolPath = GitSccOptions.Current.DifftoolPath;
196171
RunCommand(difftoolPath, "\"" + file1 + "\" \"" + file2 + "\"");
197172
}
198173

174+
#endregion
175+
199176
// This function is called by the IVsSccProvider service implementation when the active state of the provider changes
200177
// The package needs to show or hide the scc-specific commands
201178
public virtual void OnActiveStateChange()

BasicSccProvider.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,24 @@
6363
</ItemGroup>
6464
<ItemGroup>
6565
<Compile Include="GitFileStatusTracker.cs" />
66+
<Compile Include="GitSccOptions.cs" />
6667
<Compile Include="Properties\AssemblyInfo.cs" />
6768
<Compile Include="BasicSccProvider.cs" />
6869
<Compile Include="CommandId.cs" />
6970
<Compile Include="Guids.cs" />
7071
<Compile Include="ProvideSourceControlProvider.cs" />
72+
<Compile Include="ProvideToolsOptionsPageVisibility.cs" />
7173
<Compile Include="Resources.Designer.cs">
7274
<AutoGen>True</AutoGen>
7375
<DesignTime>True</DesignTime>
7476
<DependentUpon>Resources.resx</DependentUpon>
7577
</Compile>
78+
<Compile Include="SccProviderOptions.cs">
79+
<SubType>Component</SubType>
80+
</Compile>
81+
<Compile Include="SccProviderOptionsControl.cs">
82+
<SubType>UserControl</SubType>
83+
</Compile>
7684
<Compile Include="SccProviderService.cs" />
7785
<Compile Include="GitFileStatus.cs" />
7886
</ItemGroup>
@@ -83,6 +91,9 @@
8391
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
8492
<MergeWithCTO>true</MergeWithCTO>
8593
</EmbeddedResource>
94+
<EmbeddedResource Include="SccProviderOptionsControl.resx">
95+
<DependentUpon>SccProviderOptionsControl.cs</DependentUpon>
96+
</EmbeddedResource>
8697
</ItemGroup>
8798
<ItemGroup>
8899
<Content Include="License.txt">

GitSccOptions.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.IO;
6+
using System.Xml.Serialization;
7+
8+
namespace GitScc
9+
{
10+
[Serializable]
11+
public class GitSccOptions
12+
{
13+
private static string configFileName = Path.Combine(
14+
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
15+
"gitscc.config");
16+
17+
public string GitBashPath { get; set; }
18+
public string GitExtensionPath { get; set; }
19+
public string DifftoolPath { get; set; }
20+
21+
private static GitSccOptions gitSccOptions;
22+
23+
public static GitSccOptions Current
24+
{
25+
get
26+
{
27+
if (gitSccOptions == null)
28+
{
29+
gitSccOptions = LoadFromConfig();
30+
}
31+
return gitSccOptions;
32+
}
33+
}
34+
35+
private GitSccOptions()
36+
{
37+
38+
}
39+
40+
internal static GitSccOptions LoadFromConfig()
41+
{
42+
GitSccOptions options = null;
43+
44+
45+
if (File.Exists(configFileName))
46+
{
47+
try
48+
{
49+
XmlSerializer serializer = new XmlSerializer(typeof(GitSccOptions));
50+
using (TextReader tr = new StreamReader(configFileName))
51+
{
52+
options = (GitSccOptions)serializer.Deserialize(tr);
53+
}
54+
}
55+
catch
56+
{
57+
}
58+
}
59+
60+
if(options == null) options = new GitSccOptions();
61+
62+
options.Init();
63+
64+
return options;
65+
}
66+
67+
private void Init()
68+
{
69+
if (string.IsNullOrEmpty(GitBashPath))
70+
{
71+
GitBashPath = TryFindFile(new string[]{
72+
@"C:\Program Files\Git\bin\sh.exe",
73+
@"C:\Program Files (x86)\Git\bin\sh.exe",
74+
});
75+
}
76+
if (string.IsNullOrEmpty(GitExtensionPath))
77+
{
78+
GitExtensionPath = TryFindFile(new string[]{
79+
@"C:\Program Files\GitExtensions\GitExtensions.exe",
80+
@"C:\Program Files (x86)\GitExtensions\GitExtensions.exe",
81+
});
82+
}
83+
84+
if (string.IsNullOrEmpty(DifftoolPath)) DifftoolPath = "diffmerge.exe";
85+
}
86+
87+
internal void SaveConfig()
88+
{
89+
try
90+
{
91+
XmlSerializer x = new XmlSerializer(typeof(GitSccOptions));
92+
using (TextWriter tw = new StreamWriter(configFileName))
93+
{
94+
x.Serialize(tw, this);
95+
}
96+
}
97+
catch { }
98+
}
99+
100+
private string TryFindFile(string[] paths)
101+
{
102+
foreach (var path in paths)
103+
{
104+
if (File.Exists(path)) return path;
105+
}
106+
return null;
107+
}
108+
}
109+
}

PkgCmd.vsct

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3-
<!--
4-
***************************************************************************
5-
Copyright (c) Microsoft Corporation. All rights reserved.
6-
This code is licensed under the Visual Studio SDK license terms.
7-
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
8-
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
9-
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
10-
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
11-
***************************************************************************
12-
-->
133
<!-- Definition of the command and menus used by this sample -->
144
<Extern href="stdidcmd.h"/>
155
<Extern href="vsshlids.h"/>
@@ -73,7 +63,7 @@
7363
<CommandFlag>DynamicVisibility</CommandFlag>
7464
<CommandFlag>DefaultInvisible</CommandFlag>
7565
<Strings>
76-
<ButtonText>Git Extension ...</ButtonText>
66+
<ButtonText>Git Extensions ...</ButtonText>
7767
</Strings>
7868
</Button>
7969

ProvideToolsOptionsPageVisibility.cs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/***************************************************************************
2+
3+
Copyright (c) Microsoft Corporation. All rights reserved.
4+
This code is licensed under the Visual Studio SDK license terms.
5+
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
6+
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
7+
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
8+
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
9+
10+
***************************************************************************/
11+
12+
using System;
13+
using System.Globalization;
14+
using MsVsShell = Microsoft.VisualStudio.Shell;
15+
16+
namespace GitScc
17+
{
18+
/// <summary>
19+
/// This attribute registers the visibility of a Tools/Options property page.
20+
/// While Microsoft.VisualStudio.Shell allow registering a tools options page
21+
/// using the ProvideOptionPageAttribute attribute, currently there is no better way
22+
/// of declaring the options page visibility, so a custom attribute needs to be used.
23+
/// </summary>
24+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
25+
public sealed class ProvideToolsOptionsPageVisibility : MsVsShell.RegistrationAttribute
26+
{
27+
private string _categoryName = null;
28+
private string _pageName = null;
29+
private Guid _commandUIGuid;
30+
31+
/// <summary>
32+
/// </summary>
33+
public ProvideToolsOptionsPageVisibility(string categoryName, string pageName, string commandUIGuid)
34+
{
35+
_categoryName = categoryName;
36+
_pageName = pageName;
37+
_commandUIGuid = new Guid(commandUIGuid);
38+
}
39+
40+
/// <summary>
41+
/// The programmatic name for this category (non localized).
42+
/// </summary>
43+
public string CategoryName
44+
{
45+
get { return _categoryName; }
46+
}
47+
48+
/// <summary>
49+
/// The programmatic name for this page (non localized).
50+
/// </summary>
51+
public string PageName
52+
{
53+
get { return _pageName; }
54+
}
55+
56+
/// <summary>
57+
/// Get the command UI guid controlling the visibility of the page.
58+
/// </summary>
59+
public Guid CommandUIGuid
60+
{
61+
get { return _commandUIGuid; }
62+
}
63+
64+
private string RegistryPath
65+
{
66+
get { return string.Format(CultureInfo.InvariantCulture, "ToolsOptionsPages\\{0}\\{1}\\VisibilityCmdUIContexts", CategoryName, PageName); }
67+
}
68+
69+
/// <summary>
70+
/// Called to register this attribute with the given context. The context
71+
/// contains the location where the registration inforomation should be placed.
72+
/// It also contains other information such as the type being registered and path information.
73+
/// </summary>
74+
public override void Register(RegistrationContext context)
75+
{
76+
// Write to the context's log what we are about to do
77+
context.Log.WriteLine(String.Format(CultureInfo.CurrentCulture, "Opt.Page Visibility:\t{0}\\{1}, {2}\n", CategoryName, PageName, CommandUIGuid.ToString("B")));
78+
79+
// Create the visibility key.
80+
using (Key childKey = context.CreateKey(RegistryPath))
81+
{
82+
// Set the value for the command UI guid.
83+
childKey.SetValue(CommandUIGuid.ToString("B"), 1);
84+
}
85+
}
86+
87+
/// <summary>
88+
/// Unregister this visibility entry.
89+
/// </summary>
90+
public override void Unregister(RegistrationContext context)
91+
{
92+
context.RemoveValue(RegistryPath, CommandUIGuid.ToString("B"));
93+
}
94+
}
95+
}

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ How to use
2121
* Select Source Control in the tree view.
2222
* Select Git Source Control Provider from the drop down list, and click OK.
2323
* Open your solution controlled by Git to see the file's status.
24+
* Right click within solution explorer and select "Git" to use git releated fuctions.
2425

25-
Right click within solution explorer items and select "Git" to use git releated fuctions.
26-
27-
![context menu](http://gitscc.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=123883)
26+
![context menu](http://gitscc.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=124585)
2827

2928
What's coming
3029
-----------------

0 commit comments

Comments
 (0)