Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitSharp.Demo now remembers the last open repository (in user's appli…
…cation settings)
- Loading branch information
Showing
8 changed files
with
229 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
This how to adresses the problem of changing the indentation white space settings | ||
on a per solution basis. The community choice for GitSharp was TABS so if you need | ||
spaces in other solutions then check this out. | ||
|
||
Short Summary: | ||
========== | ||
|
||
1) Your solutions need to have a solution item called Indentation.vssettings (see GitSharp | ||
solution's which sets *only* the indentation whitespace to tabs) | ||
2) You need to paste the following script at the end of your EnvironmentEvents makro that | ||
automatically loads Indentation.vssettings if it exists: | ||
|
||
''''''''''''' | ||
Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened | ||
Dim item As ProjectItem = DTE.Solution.FindProjectItem("Indentation.vssettings") | ||
If Not item Is Nothing Then | ||
Dim name = item.FileNames(1) | ||
DTE.ExecuteCommand("Tools.ImportandExportSettings", "/import:""" & name & """") | ||
End If | ||
End Sub | ||
''''''''''''' | ||
|
||
Long Explanantion: | ||
============ | ||
|
||
(partially copied from http://geekswithblogs.net/sdorman/archive/2007/04/25/111981.aspx) | ||
|
||
1) If you have multiple solutions with different white space settings you'll want to set the | ||
regarding setting (i.e. UseTabs) automatically. Add Indentation.vssettings to every of your | ||
solutions that is having conflicting settings and edit it to your needs. For example: GitSharp's | ||
Indentation.vssettings is only touching "InsertTabs" and nothing else. | ||
|
||
Note: As long as you don't add the following makro it won't affect your settings in any way. | ||
|
||
2) However, if you want to load the correct settings automatically when a new solution is loaded | ||
then follow the receipe: | ||
|
||
1. Launch the Macros IDE (Alt+F11) | ||
2. In the "Project Explorer" toolwindow, double-click on "MyMacros" to expand it | ||
3. Double-click on "EnvironmentEvents" to show the source code | ||
4. Add this code just above the "End Module" statement at the end of the file: | ||
|
||
''''''''''''' | ||
Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened | ||
Dim item As ProjectItem = DTE.Solution.FindProjectItem("VsEditorFormatting.vssettings") | ||
If Not item Is Nothing Then | ||
Dim name = item.FileNames(1) | ||
DTE.ExecuteCommand("Tools.ImportandExportSettings", "/import:""" & name & """") | ||
End If | ||
End Sub | ||
''''''''''''' | ||
|
||
What this does is hook up a handler for the "Solution.Opened" event. When it fires, the code looks for | ||
your "VsEditorFormatting.vssettings" file in the solution and, if it's found, it imports that file. | ||
|
||
5. Close the Macros IDE | ||
6. Close Visual Studio (you will get prompted to save "MyMacros") | ||
|
||
Now, every time you open a solution containing a "VsEditorFormatting.vssettings" file, it will be automatically | ||
imported for you. You will can need to share this macro with your co-workers so that they can take | ||
advantage of it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<UserSettings> | ||
<ApplicationIdentity version="9.0"/> | ||
<ToolsOptions> | ||
<ToolsOptionsCategory name="TextEditor" RegisteredName="TextEditor"> | ||
<ToolsOptionsSubCategory name="CSharp" RegisteredName="CSharp" PackageName="Text Management Package"> | ||
<!--<PropertyValue name="TabSize">4</PropertyValue> | ||
<PropertyValue name="AutoListMembers">false</PropertyValue> | ||
<PropertyValue name="IndentStyle">2</PropertyValue> | ||
<PropertyValue name="HideAdvancedMembers">true</PropertyValue> | ||
<PropertyValue name="ShowNavigationBar">true</PropertyValue> | ||
<PropertyValue name="VirtualSpace">false</PropertyValue>--> | ||
<PropertyValue name="InsertTabs">true</PropertyValue> | ||
<!--<PropertyValue name="WordWrapGlyphs">true</PropertyValue> | ||
<PropertyValue name="EnableLeftClickForURLs">true</PropertyValue> | ||
<PropertyValue name="ShowLineNumbers">true</PropertyValue> | ||
<PropertyValue name="WordWrap">false</PropertyValue> | ||
<PropertyValue name="IndentSize">4</PropertyValue> | ||
<PropertyValue name="CutCopyBlankLines">true</PropertyValue> | ||
<PropertyValue name="AutoListParams">false</PropertyValue>--> | ||
</ToolsOptionsSubCategory> | ||
</ToolsOptionsCategory> | ||
</ToolsOptions> | ||
</UserSettings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright (C) 2010, Henon <meinrad.recheis@gmail.com> | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or | ||
* without modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* - Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* | ||
* - Neither the name of the project nor the | ||
* names of its contributors may be used to endorse or promote | ||
* products derived from this software without specific prior | ||
* written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | ||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Security; | ||
using System.Text; | ||
|
||
namespace GitSharp.Demo | ||
{ | ||
public static class UserSettings | ||
{ | ||
public static string UserSettingsDirectory | ||
{ | ||
get | ||
{ | ||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "GitSharp.Demo"); | ||
} | ||
} | ||
|
||
public static string GetString(string setting) | ||
{ | ||
try | ||
{ | ||
var filename = Path.Combine(UserSettingsDirectory, setting); | ||
if (!new DirectoryInfo(UserSettingsDirectory).Exists || !new FileInfo(filename).Exists) | ||
return null; | ||
return File.ReadAllText(filename); | ||
} | ||
catch (IOException) { } | ||
catch (UnauthorizedAccessException) { } | ||
catch (SecurityException) { } | ||
return null; | ||
} | ||
|
||
public static void SetValue(string setting, string value) | ||
{ | ||
try | ||
{ | ||
var filename = Path.Combine(UserSettingsDirectory, setting); | ||
if (!new DirectoryInfo(UserSettingsDirectory).Exists) | ||
Directory.CreateDirectory(UserSettingsDirectory); | ||
if (value == null) | ||
File.Delete(filename); | ||
else | ||
File.WriteAllText(filename, value); | ||
} | ||
catch (IOException) { } | ||
catch (UnauthorizedAccessException) { } | ||
catch (SecurityException) { } | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
|
||
namespace Test | ||
{ | ||
using GitSharp.Demo; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class UserSettingsTest | ||
{ | ||
[Test] | ||
public void ReadWrite() | ||
{ | ||
Assert.IsNull(UserSettings.GetString("not a valid setting")); | ||
UserSettings.SetValue("test", "hello world!"); | ||
Assert.AreEqual("hello world!", UserSettings.GetString("test")); | ||
UserSettings.SetValue("test", null); | ||
Assert.IsNull(UserSettings.GetString("test")); | ||
} | ||
} | ||
} | ||
#endif |
Binary file not shown.