Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial implementation of diff panel.

  • Loading branch information...
commit 63bbd3a0b7f2b987b0d8aa832238e33d62206041 1 parent fc3b790
@kaisellgren authored
View
7 Git-GUI.csproj
@@ -189,6 +189,9 @@
<Compile Include="UserControls\CommitPanel.xaml.cs">
<DependentUpon>CommitPanel.xaml</DependentUpon>
</Compile>
+ <Compile Include="UserControls\DiffPanel.xaml.cs">
+ <DependentUpon>DiffPanel.xaml</DependentUpon>
+ </Compile>
<Compile Include="UserControls\Panel.xaml.cs">
<DependentUpon>Panel.xaml</DependentUpon>
</Compile>
@@ -325,6 +328,10 @@
<Page Include="UserControls\CommitPanel.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
+ <Page Include="UserControls\DiffPanel.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="UserControls\LeftToolbar.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
View
4 Styles/Panel.xaml
@@ -18,9 +18,11 @@
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="White" />
<Setter Property="FontWeight" Value="SemiBold" />
+ <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
+
<Setter Property="Effect">
<Setter.Value>
- <DropShadowEffect ShadowDepth="1" BlurRadius="1" Color="Black" Opacity="0.5" RenderingBias="Quality" />
+ <DropShadowEffect ShadowDepth="1" BlurRadius="0" Color="Black" Opacity="0.4" RenderingBias="Quality" />
</Setter.Value>
</Setter>
</Style>
View
11 UserControls/DiffPanel.xaml
@@ -0,0 +1,11 @@
+<UserControl x:Class="GG.UserControls.DiffPanel"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ mc:Ignorable="d"
+ d:DesignHeight="300" d:DesignWidth="300">
+ <Grid Background="White">
+ <TextBlock Margin="4" Text="{Binding StatusItemDiff}" />
+ </Grid>
+</UserControl>
View
16 UserControls/DiffPanel.xaml.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Windows.Controls;
+
+namespace GG.UserControls
+{
+ /// <summary>
+ /// Interaction logic for DiffPanel.xaml
+ /// </summary>
+ public partial class DiffPanel : UserControl
+ {
+ public DiffPanel()
+ {
+ InitializeComponent();
+ }
+ }
+}
View
57 UserControls/Panel.xaml
@@ -2,39 +2,42 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:GG.UserControls"
+ xmlns:userControls="clr-namespace:GG.UserControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Template>
<ControlTemplate>
- <StackPanel>
- <DockPanel Style="{DynamicResource PanelHeaderStyle}">
- <ContentPresenter DockPanel.Dock="Left" Style="{DynamicResource PanelHeaderTitleStyle}" Content="{TemplateBinding local:Panel.Header}" />
- <WrapPanel DockPanel.Dock="Right" HorizontalAlignment="Right">
- <ComboBox ToolTip="Copy a previous commit message. The entire message will be copied."
- ItemsSource="{Binding RecentCommitMessages}"
- DisplayMemberPath="CroppedMessage"
- Name="RecentCommitMessages"
- SelectionChanged="OnRecentCommitMessagesSelectionChanged"
- Width="150" Margin="0,4,4,4">
- </ComboBox>
- <Button Margin="0,3,3,3" Style="{StaticResource GreenButtonStyle}"
- Command="{Binding CommitCommand}" CommandParameter="{Binding Text, ElementName=CommitMessageTextBox}">
- <WrapPanel>
- <Image Source="../Resources/Icons/RepositoryWrite.png" Width="16" Margin="0,0,4,0" />
- <TextBlock>Commit</TextBlock>
- </WrapPanel>
- </Button>
- </WrapPanel>
- </DockPanel>
- <Grid>
- <StackPanel Margin="4">
- <TextBox Name="CommitMessageTextBox" ToolTip="Enter your commit message." Height="64"></TextBox>
- </StackPanel>
- </Grid>
- </StackPanel>
+ <DockPanel>
+ <StackPanel DockPanel.Dock="Top">
+ <DockPanel Style="{DynamicResource PanelHeaderStyle}">
+ <ContentPresenter DockPanel.Dock="Left" Style="{DynamicResource PanelHeaderTitleStyle}" Content="{TemplateBinding userControls:Panel.Header}" />
+ <WrapPanel DockPanel.Dock="Right" HorizontalAlignment="Right">
+ <ComboBox ToolTip="Copy a previous commit message. The entire message will be copied."
+ ItemsSource="{Binding RecentCommitMessages}"
+ DisplayMemberPath="CroppedMessage"
+ Name="RecentCommitMessages"
+ SelectionChanged="OnRecentCommitMessagesSelectionChanged"
+ Width="150" Margin="0,4,4,4">
+ </ComboBox>
+ <Button Margin="0,3,3,3" Style="{StaticResource GreenButtonStyle}"
+ Command="{Binding CommitCommand}" CommandParameter="{Binding Text, ElementName=CommitMessageTextBox}">
+ <WrapPanel>
+ <Image Source="../Resources/Icons/RepositoryWrite.png" Width="16" Margin="0,0,4,0" />
+ <TextBlock>Commit</TextBlock>
+ </WrapPanel>
+ </Button>
+ </WrapPanel>
+ </DockPanel>
+ <Grid>
+ <StackPanel Margin="4">
+ <TextBox Name="CommitMessageTextBox" ToolTip="Enter your commit message." Height="64"></TextBox>
+ </StackPanel>
+ </Grid>
+ </StackPanel>
+ <userControls:DiffPanel DockPanel.Dock="Bottom" />
+ </DockPanel>
</ControlTemplate>
</UserControl.Template>
</UserControl>
View
1  UserControls/StatusGrid.xaml
@@ -26,6 +26,7 @@
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling"
ContextMenu="{StaticResource statusGridContextMenu}"
+ SelectionChanged="StatusGridElement_SelectionChanged"
Tag="{Binding}"
x:Name="StatusGridElement">
<DataGrid.InputBindings>
View
11 UserControls/StatusGrid.xaml.cs
@@ -11,6 +11,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using GG.Libraries;
namespace GG.UserControls
{
@@ -23,5 +24,15 @@ public StatusGrid()
{
InitializeComponent();
}
+
+ private void StatusGridElement_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ // Retrieve repository view model.
+ var repositoryTabs = UIHelper.FindChild<TabControl>(Application.Current.MainWindow, "RepositoryTabs");
+ var repositoryViewModel = repositoryTabs.SelectedItem as RepositoryViewModel;
+
+ // Tell repository view model to update status item diff.
+ repositoryViewModel.UpdateStatusItemDiff(StatusGridElement.SelectedItems);
+ }
}
}
View
3  ViewModels/BaseViewModel.cs
@@ -3,6 +3,9 @@
namespace GG.ViewModels
{
+ /// <summary>
+ /// A base view model that implements INotifyPropertyChanged.
+ /// </summary>
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
View
42 ViewModels/RepositoryViewModel.cs
@@ -21,6 +21,8 @@ namespace GG
{
public class RepositoryViewModel : BaseViewModel
{
+ #region Properties and fields.
+
public string Name { get; set; }
public string RepositoryFullPath { get; set; }
public bool NotOpened { get; set; }
@@ -45,12 +47,29 @@ public class RepositoryViewModel : BaseViewModel
public int RecentCommitMessageCount { get; set; }
/// <summary>
+ /// Stores the diff text for the diff panel.
+ /// </summary>
+ private string _StatusItemDiff;
+
+ public string StatusItemDiff
+ {
+ get { return _StatusItemDiff; }
+ set
+ {
+ _StatusItemDiff = value;
+ RaisePropertyChanged("StatusItemDiff");
+ }
+ }
+
+ /// <summary>
/// The delegate used for reloading the status grid items upon filesystem changes.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
delegate void ReloadStatusDelegate(object sender, FileSystemEventArgs e);
+ #endregion
+
public RepositoryViewModel()
{
// Initialize empty collections.
@@ -84,6 +103,9 @@ public RepositoryViewModel()
StageUnstageCommand = new DelegateCommand(StageUnstage);
DeleteFileCommand = new DelegateCommand(DeleteFile);
CommitCommand = new DelegateCommand(CommitChanges, CommitChanges_CanExecute);
+
+ // Diff panel.
+ StatusItemDiff = "";
}
/// <summary>
@@ -537,6 +559,26 @@ private void LoadRecentCommitMessages()
#endregion
/// <summary>
+ /// Updates the diff panel text.
+ /// </summary>
+ /// <param name="items"></param>
+ public void UpdateStatusItemDiff(IList collection)
+ {
+ var diff = "a";
+ var items = collection.Cast<StatusItem>();
+
+ using (var repo = new LibGit2Sharp.Repository(RepositoryFullPath))
+ {
+ foreach (StatusItem item in items)
+ {
+ diff += repo.Diff.Compare(repo.Head.Tip.Tree, LibGit2Sharp.DiffTarget.Index).Patch;
+ }
+ }
+
+ StatusItemDiff = diff;
+ }
+
+ /// <summary>
/// Sets this repository as the active tab on the tab control.
/// </summary>
public void SetThisRepositoryAsTheActiveTab()
Please sign in to comment.
Something went wrong with that request. Please try again.