Browse files

GitSharp.Demo now remembers the last open repository (in user's appli…

…cation settings)
  • Loading branch information...
1 parent 788effc commit f74c869d9b5d0555ec2a99812f9ab6d0ac7542ca @henon committed Jan 29, 2010
Showing with 229 additions and 11 deletions.
  1. +16 −10 Browser.xaml
  2. +5 −1 Browser.xaml.cs
  3. +5 −0 GitSharp.Demo.csproj
  4. +6 −0 GitSharp.Demo.sln
  5. +61 −0 Indentation.txt
  6. +23 −0 Indentation.vssettings
  7. +113 −0 UserSettings.cs
  8. BIN depend/nunit.framework.dll
View
26 Browser.xaml
@@ -73,23 +73,29 @@
</DataTemplate>-->
</Window.Resources>
<DockPanel>
- <StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
-
- <Menu DockPanel.Dock="Top">
+ <!--menu-->
+ <Menu DockPanel.Dock="Top">
<MenuItem Header="File" >
- <MenuItem Header="Open repository..." Click="OnSelectRepository"/>
+ <MenuItem Header="Open repository ..." Click="OnSelectRepository"/>
<Separator />
- <MenuItem Header="Close" Click="OnMenuClose" />
+ <MenuItem Header="Exit" Click="OnMenuClose" />
</MenuItem>
<MenuItem Header="Edit" >
<MenuItem Header="Repository configuration..." Click="OnOpenRepositoryConfiguration"/>
</MenuItem>
</Menu>
- <Label Margin="20,0,5,0">Repository Path</Label>
+ <!--status bar-->
+ <DockPanel DockPanel.Dock="Bottom" LastChildFill="False" Background="LightGray">
+ <Label Margin="0,0,5,0" Content="Repository:">
+ <Label.ContextMenu>
+ <ContextMenu>
+ <MenuItem Header="Select repository path" Click="OnSelectRepository"/>
+ </ContextMenu>
+ </Label.ContextMenu>
+ </Label>
<TextBox Name="m_url_textbox" MinWidth="100">.</TextBox>
<Button Click="OnLoadRepository" Margin="5,0,0,0">Reload</Button>
- <!--<Label Margin="10,0,0,0">Select a commit. Differences to the previous commit are highlited in red.</Label>-->
- </StackPanel>
+ </DockPanel>
<DockPanel >
<!--commit history graph-->
<DockPanel Width="400">
@@ -122,7 +128,7 @@
<Demo:CommitSummaryView x:Name="m_commit_view"/>
</DockPanel>
<Controls:DockPanelSplitter DockPanel.Dock="Top" Height="4"/>
- <!--commits-->
+ <!--commits-->
<DockPanel DockPanel.Dock="Top">
<Label DockPanel.Dock="Top" Name="m_commit_title" Style="{StaticResource HeaderLabelStyle}">Changes by this commit</Label>
<!--<TextBlock DockPanel.Dock="Top" >(Select two commits to compare them via right click menu)</TextBlock>-->
@@ -148,7 +154,7 @@
<Demo:CommitDiffView x:Name="m_commit_diff"/>
</DockPanel>
<!--<GridSplitter Width="2" Grid.Column="1" ResizeBehavior="PreviousAndNext"/>-->
-
+
</DockPanel>
<!--<GridSplitter Grid.Row="1" ResizeBehavior="PreviousAndNext" ResizeDirection="Rows" Height="6" Background="White"/>-->
<Controls:DockPanelSplitter DockPanel.Dock="Top" Height="4"/>
View
6 Browser.xaml.cs
@@ -50,6 +50,7 @@ namespace GitSharp.Demo
public partial class Browser
{
+ public const string CURRENT_REPOSITORY = "repository";
public Browser()
{
InitializeComponent();
@@ -59,7 +60,8 @@ public Browser()
m_tree.SelectedItemChanged += (o, args) => SelectObject(m_tree.SelectedValue as AbstractObject);
//m_config_tree.SelectedItemChanged += (o, args) => SelectConfiguration(m_config_tree.SelectedItem);
m_history_graph.CommitClicked += SelectCommit;
- Loaded += (o, args) => Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => LoadRepository(m_url_textbox.Text)));
+ m_url_textbox.Text = UserSettings.GetString(CURRENT_REPOSITORY);
+ Loaded += (o, args) => Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => LoadRepository(m_url_textbox.Text)));
}
Configuration configurationWindow = new Configuration();
@@ -82,6 +84,7 @@ private void LoadRepository(string url)
}
var repo = new Repository(git_url);
m_url_textbox.Text = git_url;
+ UserSettings.SetValue(CURRENT_REPOSITORY, git_url);
var head = repo.Head.Target as Commit;
Debug.Assert(head != null);
m_repository = repo;
@@ -166,6 +169,7 @@ private void SelectTag(Tag tag)
private void OnSelectRepository(object sender, RoutedEventArgs e)
{
var dlg = new System.Windows.Forms.FolderBrowserDialog();
+ dlg.SelectedPath = Path.GetDirectoryName(UserSettings.GetString(CURRENT_REPOSITORY));
//dlg.CheckPathExists = true;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
View
5 GitSharp.Demo.csproj
@@ -41,6 +41,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>depend\GitSharp.Core.dll</HintPath>
</Reference>
+ <Reference Include="nunit.framework, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>depend\nunit.framework.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -136,6 +140,7 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
+ <Compile Include="UserSettings.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
View
6 GitSharp.Demo.sln
@@ -3,6 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp.Demo", "GitSharp.Demo.csproj", "{4B53BA11-1ADE-44E7-AC0F-7748D5701C25}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B96C19CB-9C72-48A9-8FB9-27DBA6147BDE}"
+ ProjectSection(SolutionItems) = preProject
+ Indentation.txt = Indentation.txt
+ Indentation.vssettings = Indentation.vssettings
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
View
61 Indentation.txt
@@ -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.
View
23 Indentation.vssettings
@@ -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>
View
113 UserSettings.cs
@@ -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
View
BIN depend/nunit.framework.dll
Binary file not shown.

0 comments on commit f74c869

Please sign in to comment.