Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisellgren committed Apr 14, 2012
1 parent 020f5ac commit 2c239a4
Show file tree
Hide file tree
Showing 25 changed files with 520 additions and 154 deletions.
1 change: 1 addition & 0 deletions App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ResourceDictionary Source="Templates/AppTabItemTemplate.xaml"/>
<ResourceDictionary Source="Templates/AppTabNew.xaml"/>
<ResourceDictionary Source="Templates/AppTabNew.xaml"/>
<ResourceDictionary Source="Styles/NewTabButton.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
2 changes: 1 addition & 1 deletion AppTabDataTemplateSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override DataTemplate SelectTemplate(object item, DependencyObject contai
}
else
{
Repository repository = item as Repository;
RepositoryViewModel repository = item as RepositoryViewModel;

templateName = repository.NotOpened ? "AppTabNew" : "AppTabContentTemplate";
}
Expand Down
72 changes: 0 additions & 72 deletions ChangesetHistory.cs

This file was deleted.

26 changes: 17 additions & 9 deletions DesignData/SampleApplication.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<local:MainWindowViewModel xmlns:local="clr-namespace:GG">
<local:MainWindowViewModel.Repositories>
<local:Repository Name="Sample" FullPath="Z:/www/git1">
<local:Repository.Commits>
<local:Commit AuthorEmail="foo@email" AuthorName="Foo" Date="12.12.2012" Description="Foo" Hash="123" Source="asdasd" />
<local:Commit AuthorEmail="foo@email" AuthorName="Foo" Date="12.12.2012" Description="Foo 2" Hash="456" Source="asdasd" />
<local:Commit AuthorEmail="foo@email" AuthorName="Foo" Date="12.12.2012" Description="Foo 3 " Hash="789" Source="asdasd" />
</local:Repository.Commits>
</local:Repository>
</local:MainWindowViewModel.Repositories>
<local:MainWindowViewModel.RepositoryViewModels>
<local:RepositoryViewModel Name="Sample" FullPath="Z:/www/git1">
<local:RepositoryViewModel.Commits>
<local:Commit AuthorEmail="foo@email" AuthorName="Foo" Date="12.12.2012" FormattedDate="One minute ago" Description="Foo" Hash="123" Source="asdasd" />
<local:Commit AuthorEmail="foo@email" AuthorName="Foo" Date="12.12.2012" FormattedDate="5 minutes ago" Description="Foo 2" Hash="456" Source="asdasd" />
<local:Commit AuthorEmail="foo@email" AuthorName="Foo" Date="12.12.2012" FormattedDate="6 hours ago" Description="Foo 3 " Hash="789" Source="asdasd" />
</local:RepositoryViewModel.Commits>
</local:RepositoryViewModel>
<local:RepositoryViewModel Name="New Tab" NotOpened="True">
<local:RepositoryViewModel.Commits>
</local:RepositoryViewModel.Commits>
</local:RepositoryViewModel>
</local:MainWindowViewModel.RepositoryViewModels>

<local:MainWindowViewModel.RecentRepositories>
<local:RepositoryViewModel Name="Sample" FullPath="Z:/www/git1" />
</local:MainWindowViewModel.RecentRepositories>
</local:MainWindowViewModel>
25 changes: 22 additions & 3 deletions Git-GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AppTabDataTemplateSelector.cs" />
<Compile Include="Models\Repository.cs" />
<Compile Include="Libraries\DateUtil.cs" />
<Compile Include="Models\StatusItem.cs" />
<Compile Include="UserControls\CommitPanel.xaml.cs">
<DependentUpon>CommitPanel.xaml</DependentUpon>
</Compile>
<Compile Include="UserControls\StatusGrid.xaml.cs">
<DependentUpon>StatusGrid.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\BaseViewModel.cs" />
<Compile Include="ViewModels\RepositoryViewModel.cs" />
<Compile Include="UserControls\ChangesetHistory.xaml.cs">
<DependentUpon>ChangesetHistory.xaml</DependentUpon>
</Compile>
Expand All @@ -113,12 +122,14 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="ChangesetHistory.cs" />
<Compile Include="Models\Commit.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Styles\NewTabButton.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Templates\AppTabContentTemplate.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down Expand Up @@ -146,6 +157,9 @@
<Page Include="UserControls\ChangesetHistory.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControls\CommitPanel.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControls\LeftToolbar.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand All @@ -155,6 +169,9 @@
<Page Include="UserControls\NewTabPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControls\StatusGrid.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControls\TopToolbar.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down Expand Up @@ -239,7 +256,9 @@
<ItemGroup>
<Resource Include="Resources\Icons\Statistics.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Resource Include="Resources\NewTabBackground.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
51 changes: 51 additions & 0 deletions Libraries/DateUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;

namespace GG.Libraries
{
public class DateUtil
{
/// <summary>
/// Converts a DateTime object into a relative time string.
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static string GetRelativeDate(DateTime dt)
{
var ts = new TimeSpan(DateTime.UtcNow.Ticks - dt.Ticks);
double delta = Math.Abs(ts.TotalSeconds);

const int SECOND = 1;
const int MINUTE = 60 * SECOND;
const int HOUR = 60 * MINUTE;
const int DAY = 24 * HOUR;
const int MONTH = 30 * DAY;

if (delta < 2 * MINUTE)
{
return "One minute ago";
}

if (delta < 45 * MINUTE)
{
return ts.Minutes + " minutes ago";
}

if (delta < 90 * MINUTE)
{
return "An hour ago";
}

if (delta < 48 * HOUR)
{
return ts.Hours + " hours ago";
}

if (delta < 7 * DAY)
{
return ts.Days + " days ago";
}

return dt.ToShortDateString() + ' ' + dt.ToShortTimeString();
}
}
}
5 changes: 2 additions & 3 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
xmlns:local="clr-namespace:GG"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
Title="Git-GUI" Icon="Resources/Icons/Git-GUI.png" WindowState="Maximized" Style="{StaticResource WindowGlassStyle}">
Title="Git-GUI" Icon="Resources/Icons/Git-GUI.png" WindowState="Normal" Style="{StaticResource WindowGlassStyle}" Loaded="OnLoad">

<DockPanel Margin="0,-24,0,0" d:DataContext="{d:DesignData Source=./DesignData/SampleApplication.xaml}">
<TabControl x:Name="RepositoryTabs"
d:LayoutOverrides="Margin"
shell:WindowChrome.IsHitTestVisibleInChrome="True"
Background="#e9e9e9"
Padding="0"
SelectedIndex="0"
ItemsSource="{Binding Repositories}"
ItemsSource="{Binding RepositoryViewModels}"
ItemTemplate="{StaticResource AppTabItemTemplate}"
ContentTemplateSelector="{DynamicResource AppTabContentTemplateSelector}" />
</DockPanel>
Expand Down
6 changes: 6 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ public MainWindow()
{
InitializeComponent();
}

void OnLoad(object sender, RoutedEventArgs e)
{
MainWindowViewModel vm = this.DataContext as MainWindowViewModel;
vm.Load();
}
}
}
10 changes: 2 additions & 8 deletions Models/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GG.Libraries;

namespace GG
{
Expand All @@ -19,15 +20,8 @@ public string FormattedDate
{
get
{
return this.Date.ToString("d.M.yyyy H:m:s");
return DateUtil.GetRelativeDate(Date);
}
}

public Commit() { }
}

public class CommitCollection : List<Commit>
{
public CommitCollection() { }
}
}
19 changes: 0 additions & 19 deletions Models/Repository.cs

This file was deleted.

17 changes: 17 additions & 0 deletions Models/StatusItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GG.Libraries;

namespace GG
{
public class StatusItem
{
public string Status { set; get; }
public string Filename { set; get; }
public string Type { set; get; }
public string Size { set; get; }
}
}
Binary file added Resources/NewTabBackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion Styles/DataGrid.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,19 @@
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border Padding="{TemplateBinding Padding}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<ContentPresenter x:Name="CellContent" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RenderOptions.ClearTypeHint="Enabled" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="CellContent" Property="TextOptions.TextFormattingMode" Value="Display" />
<Setter TargetName="CellContent" Property="RenderOptions.ClearTypeHint" Value="Enabled" />
<Setter TargetName="CellContent" Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="2" BlurRadius="2" Color="Black" RenderingBias="Quality" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Expand Down
Loading

0 comments on commit 2c239a4

Please sign in to comment.