Skip to content

Commit

Permalink
Enabled selecting repository
Browse files Browse the repository at this point in the history
  • Loading branch information
haacked committed Mar 6, 2012
1 parent ce89569 commit 806d7ab
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 33 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added Lib/Microsoft.Windows.Shell.dll
Binary file not shown.
Binary file added Lib/Microsoft.WindowsAPICodePack.Shell.dll
Binary file not shown.
Binary file added Lib/Microsoft.WindowsAPICodePack.dll
Binary file not shown.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions SeeGitApp/Extensions/WindowsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.WindowsAPICodePack.Dialogs;

namespace SeeGit
{
public static class WindowsExtensions
{
public static string BrowseForFolder(string startingPath)
{
var cfd = new CommonOpenFileDialog
{
DefaultFileName = startingPath,
IsFolderPicker = true,
};

if (cfd.ShowDialog() != CommonFileDialogResult.Ok) return null;

var ret = cfd.FileName;
return ret;
}
}
}
5 changes: 3 additions & 2 deletions SeeGitApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
<Label VerticalAlignment="Center" VerticalContentAlignment="Center" Foreground="White" FontSize="10"
FontFamily="Verdana" FontWeight="Bold" Margin="0,0,0,0" Content="Repository Path:" />
<Label VerticalAlignment="Center" VerticalContentAlignment="Center" Foreground="White" FontSize="10"
FontFamily="Verdana" FontWeight="Bold" Margin="0,0,0,0" Content="c:\dev\git\Test" />
</StackPanel>
FontFamily="Verdana" FontWeight="Bold" Margin="0,0,0,0" Content="{Binding Path=RepositoryPath}" />
<Button Background="Gray" Foreground="White" HorizontalAlignment="Right" Margin="10 2 0 2" Padding="3" Click="OnChooseRepository">Browse For a Repository...</Button>
</StackPanel>
</StackPanel>

<zoom:ZoomControl Grid.Row="1" Zoom="0.2" ZoomBoxOpacity="0.5" Background="#ff656565">
Expand Down
62 changes: 55 additions & 7 deletions SeeGitApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,52 @@ namespace SeeGit
{
public partial class MainWindow : Window
{
private readonly FileSystemWatcher _watcher;
private readonly MainWindowViewModel _viewModel;
private FileSystemWatcher _watcher;
private MainWindowViewModel _viewModel;
private string _gitRepositoryPath;

public MainWindow()
{
const string gitRepositoryPath = @"C:\dev\git\Test";
InitializeComponent();
}

private void OnChooseRepository(object sender, RoutedEventArgs args)
{
DisposeWatcher();

var graphBuilder = new RepositoryGraphBuilder(gitRepositoryPath);
DataContext = _viewModel = new MainWindowViewModel(graphBuilder);
_gitRepositoryPath = WindowsExtensions.BrowseForFolder(@"c:\dev\git");

SetupGraphBuilder();

string gitDirectory = Path.Combine(_gitRepositoryPath, ".git");
if (Directory.Exists(gitDirectory))
{
SetupGitRepositoryWatcher(gitDirectory);
}
else
{
_watcher = new FileSystemWatcher(_gitRepositoryPath)
{
IncludeSubdirectories = true,
EnableRaisingEvents = true,
NotifyFilter =
NotifyFilters.CreationTime | NotifyFilters.DirectoryName

};

_watcher.Changed += (o, e) =>
{
if (!Directory.Exists(gitDirectory)) return;
DisposeWatcher();
Dispatcher.Invoke(new Action(SetupGraphBuilder));
SetupGitRepositoryWatcher(gitDirectory);
};
}
}

_watcher = new FileSystemWatcher(Path.Combine(gitRepositoryPath, ".git"))
private void SetupGitRepositoryWatcher(string gitDirectory)
{
_watcher = new FileSystemWatcher(gitDirectory)
{
IncludeSubdirectories = true,
EnableRaisingEvents = true,
Expand All @@ -29,8 +64,21 @@ public MainWindow()
var vm = _viewModel;
Dispatcher.Invoke(new Action(vm.Refresh), null);
};
}

InitializeComponent();
private void SetupGraphBuilder()
{
var graphBuilder = new RepositoryGraphBuilder(_gitRepositoryPath);
DataContext = _viewModel = new MainWindowViewModel(graphBuilder, _gitRepositoryPath);
}

private void DisposeWatcher()
{
var oldWatcher = _watcher;
if (oldWatcher != null)
{
oldWatcher.Dispose();
}
}
}
}
9 changes: 2 additions & 7 deletions SeeGitApp/Models/IRepositoryGraphBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SeeGit
namespace SeeGit
{
public interface IRepositoryGraphBuilder
{
RepositoryGraph Graph();
}
}
}
15 changes: 14 additions & 1 deletion SeeGitApp/Models/RepositoryGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@ public class RepositoryGraphBuilder : IRepositoryGraphBuilder
public RepositoryGraphBuilder(string gitRepositoryPath)
{
GitRepositoryPath = gitRepositoryPath;
_repository = new Repository(GitRepositoryPath);
try
{
_repository = new Repository(GitRepositoryPath);
}
catch (LibGit2Exception)
{
}
}

public string GitRepositoryPath { get; private set; }

public RepositoryGraph Graph()
{
if (_repository == null) return new RepositoryGraph();

var commits =
_repository.Commits.QueryBy(new Filter {SortBy = GitSortOptions.Topological | GitSortOptions.Time});

if (!commits.Any())
{
_graph.Clear();
return _graph;
}
AddCommitsToGraph(commits.First(), null);

foreach (var branch in _repository.Branches.Where(branch => branch.Commits.Any()))
Expand Down
28 changes: 15 additions & 13 deletions SeeGitApp/SeeGitApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,36 @@
<ItemGroup>
<Reference Include="GraphSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\GraphSharp.dll</HintPath>
<HintPath>..\Lib\GraphSharp.dll</HintPath>
</Reference>
<Reference Include="GraphSharp.Contracts, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\GraphSharp.Contracts.dll</HintPath>
<HintPath>..\Lib\GraphSharp.Contracts.dll</HintPath>
</Reference>
<Reference Include="GraphSharp.Controls, Version=1.0.4115.29430, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\GraphSharp.Controls.dll</HintPath>
<HintPath>..\Lib\GraphSharp.Controls.dll</HintPath>
</Reference>
<Reference Include="LibGit2Sharp">
<HintPath>..\packages\LibGit2Sharp.0.8\lib\net35\LibGit2Sharp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=736440c9b414ea16, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\Microsoft.Contracts.dll</HintPath>
<HintPath>..\Lib\Microsoft.Contracts.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Expression.Interactions" />
<Reference Include="Microsoft.Windows.Shell">
<HintPath>..\Lib\Microsoft.Windows.Shell.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAPICodePack">
<HintPath>..\Lib\Microsoft.WindowsAPICodePack.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAPICodePack.Shell">
<HintPath>..\Lib\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
</Reference>
<Reference Include="QuickGraph, Version=3.2.40122.0, Culture=neutral, PublicKeyToken=f3fb40175eec2af3, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\QuickGraph.dll</HintPath>
<HintPath>..\Lib\QuickGraph.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -88,6 +97,7 @@
</ApplicationDefinition>
<Compile Include="Extensions\CaAdornerBehavior.cs" />
<Compile Include="Extensions\ModelExtensions.cs" />
<Compile Include="Extensions\WindowsExtensions.cs" />
<Compile Include="Models\IRepositoryGraphBuilder.cs" />
<Compile Include="Models\RepositoryGraphBuilder.cs" />
<Compile Include="Models\RepositoryGraphLayout.cs" />
Expand Down Expand Up @@ -142,14 +152,6 @@
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Content Include="Lib\GraphSharp.Contracts.dll" />
<Content Include="Lib\GraphSharp.Controls.dll" />
<Content Include="Lib\GraphSharp.dll" />
<Content Include="Lib\Microsoft.Contracts.dll" />
<Content Include="Lib\QuickGraph.dll" />
<Content Include="Lib\WPFExtensions.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
2 changes: 1 addition & 1 deletion SeeGitApp/ViewModels/DesignTimeMainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SeeGit
{
public class DesignTimeMainWindowViewModel : MainWindowViewModel
{
public DesignTimeMainWindowViewModel() : base(new DesignTimeGraphBuilder())
public DesignTimeMainWindowViewModel() : base(new DesignTimeGraphBuilder(), @"c:\dev\git\fake")
{
}
}
Expand Down
7 changes: 5 additions & 2 deletions SeeGitApp/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ public class MainWindowViewModel : INotifyPropertyChanged
private RepositoryGraph _graph;
private readonly IRepositoryGraphBuilder _graphBuilder;

public MainWindowViewModel(IRepositoryGraphBuilder graphBuilder)
public MainWindowViewModel(IRepositoryGraphBuilder graphBuilder, string repositoryPath)
{
_graphBuilder = graphBuilder;
RepositoryPath = repositoryPath;
Graph = _graphBuilder.Graph();
LayoutAlgorithmType = "EfficientSugiyama";
LayoutAlgorithmType = "Tree";
// Tree, LinLog, KK, ISOM, EfficientSugiyama, FR, CompoundFDP, BoundedFR, Circular
}

Expand All @@ -28,6 +29,8 @@ public RepositoryGraph Graph
}
}

public string RepositoryPath { get; private set;}

public void Refresh()
{
Graph = _graphBuilder.Graph();
Expand Down

0 comments on commit 806d7ab

Please sign in to comment.