Permalink
Browse files

commit diff view now notifies via event if selection has changed.

  • Loading branch information...
1 parent 4d06c9b commit 9c96b71563e624572c87763f7cf10cc390f03953 @henon committed Jan 30, 2010
Showing with 74 additions and 53 deletions.
  1. +1 −1 CommitDiffView.xaml
  2. +73 −52 CommitDiffView.xaml.cs
View
@@ -65,7 +65,7 @@
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
- <GridViewColumn Header="Path" DisplayMemberBinding="{Binding Path=Path}" Width="200"/>
+ <GridViewColumn Header="Path" DisplayMemberBinding="{Binding Path=Path}" Width="400"/>
<!--<GridViewColumn Header="Hash" DisplayMemberBinding="{Binding Path=ChangedObject.ShortHash}" />-->
</GridView.Columns>
</GridView>
View
@@ -36,68 +36,89 @@
*/
using System;
+using System.Linq;
using System.Windows;
+using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
namespace GitSharp.Demo
{
- /// <summary>
- /// Interaction logic for CommitDiffView.xaml
- /// </summary>
- public partial class CommitDiffView
- {
- public CommitDiffView()
- {
- InitializeComponent();
- }
+ /// <summary>
+ /// Interaction logic for CommitDiffView.xaml
+ /// </summary>
+ public partial class CommitDiffView
+ {
+ public CommitDiffView()
+ {
+ InitializeComponent();
+ m_treediff.SelectionChanged += OnSelectionChanged;
+ }
- public void Init(Commit c1, Commit c2)
- {
- if (c1==null)
- {
- m_treediff.ItemsSource = null;
- return;
- }
- //m_title.Content = "Differences between commits " + c1.ShortHash + " and " + c2.ShortHash;
- var changes=c1.CompareAgainst(c2);
- m_treediff.ItemsSource = changes;
- }
+ public event Action<Change> SelectionChanged;
- //private void onClose(object sender, RoutedEventArgs e)
- //{
- // //Closing application
- // this.Close();
- //}
- }
+ private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ FireSelectionChanged();
+ }
- public class ChangeColorConverter : IValueConverter
- {
- #region IValueConverter Members
+ private void FireSelectionChanged()
+ {
+ if (SelectionChanged != null)
+ SelectionChanged(m_treediff.SelectedValue as Change);
+ }
- public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- var change = value as Change;
- if (change == null)
- return Brushes.Black;
- switch (change.ChangeType)
- {
- case ChangeType.Added:
- return Brushes.Plum;
- case ChangeType.Deleted:
- return Brushes.Red;
- case ChangeType.Modified:
- return Brushes.RoyalBlue;
- default:
- return Brushes.Black;
- }
- }
+ public void Init(Commit c1, Commit c2)
+ {
+ if (c1 == null)
+ {
+ m_treediff.ItemsSource = null;
+ return;
+ }
+ //m_title.Content = "Differences between commits " + c1.ShortHash + " and " + c2.ShortHash;
+ var changes = c1.CompareAgainst(c2);
+ m_treediff.ItemsSource = changes;
+ if (changes.Count() > 0)
+ {
+ m_treediff.SelectedIndex = 0;
+ }
+ FireSelectionChanged();
+ }
- public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- throw new NotImplementedException();
- }
+ //private void onClose(object sender, RoutedEventArgs e)
+ //{
+ // //Closing application
+ // this.Close();
+ //}
+ }
- #endregion
- }
+ public class ChangeColorConverter : IValueConverter
+ {
+ #region IValueConverter Members
+
+ public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
+ {
+ var change = value as Change;
+ if (change == null)
+ return Brushes.Black;
+ switch (change.ChangeType)
+ {
+ case ChangeType.Added:
+ return Brushes.Plum;
+ case ChangeType.Deleted:
+ return Brushes.Red;
+ case ChangeType.Modified:
+ return Brushes.RoyalBlue;
+ default:
+ return Brushes.Black;
+ }
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+
+ #endregion
+ }
}

0 comments on commit 9c96b71

Please sign in to comment.