forked from yysun/Git-Source-Control-Provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PendingChangesView.xaml.cs
129 lines (106 loc) · 4.32 KB
/
PendingChangesView.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
namespace GitScc
{
/// <summary>
/// Interaction logic for PendingChangesView.xaml
/// </summary>
public partial class PendingChangesView : UserControl
{
private GitFileStatusTracker tracker;
public PendingChangesView()
{
InitializeComponent();
}
private string sortMemberPath = "FileName";
private ListSortDirection sortDirection = ListSortDirection.Ascending;
private void dataGrid1_Sorting(object sender, DataGridSortingEventArgs e)
{
sortMemberPath = e.Column.SortMemberPath;
sortDirection = e.Column.SortDirection != ListSortDirection.Ascending ?
ListSortDirection.Ascending : ListSortDirection.Descending;
}
internal void Refresh(GitFileStatusTracker tracker)
{
this.tracker = tracker;
this.dataGrid1.ItemsSource = tracker.ChangedFiles;
ICollectionView view = CollectionViewSource.GetDefaultView(this.dataGrid1.ItemsSource);
view.SortDescriptions.Clear();
view.SortDescriptions.Add(new SortDescription(sortMemberPath, sortDirection));
view.Refresh();
}
private void checkBoxStaged_Click(object sender, RoutedEventArgs e)
{
if (this.dataGrid1.SelectedCells.Count == 0) return;
var selectedItem = this.dataGrid1.SelectedCells[0].Item as GitFile;
if (selectedItem == null) return;
var fileName = selectedItem.FileName;
var checkBox = sender as CheckBox;
if (checkBox.IsChecked == false)
{
tracker.UnStageFile(fileName);
}
else
{
tracker.StageFile(fileName);
}
}
private void checkBoxAllStaged_Click(object sender, RoutedEventArgs e)
{
}
private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.dataGrid1.SelectedCells.Count == 0) return;
var selectedItem = this.dataGrid1.SelectedCells[0].Item as GitFile;
if (selectedItem == null) return;
var fileName = selectedItem.FileName;
this.textBoxDiff.Document.Blocks.Clear();
var content = tracker.DiffFile(fileName);
foreach (var line in content.Split('\n'))
{
TextRange range = new TextRange(this.textBoxDiff.Document.ContentEnd, this.textBoxDiff.Document.ContentEnd);
range.Text = line.Replace("\r", "") + "\r";
if (line.StartsWith("+"))
{
range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Color.FromArgb(128, 166, 255, 166)));
}
else if (line.StartsWith("-"))
{
range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Color.FromArgb(128, 255, 166, 166)));
}
else
{
range.ApplyPropertyValue(TextElement.BackgroundProperty, null);
}
//this.textBoxDiff.AppendText(line);
}
}
internal void Commit()
{
TextRange textRange = new TextRange(
this.textBoxComments.Document.ContentStart,
this.textBoxComments.Document.ContentEnd);
var comments = textRange.Text;
if (string.IsNullOrWhiteSpace(comments))
{
MessageBox.Show("Please enter comments for the commit.", "Commit",
MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
tracker.Commit(comments);
this.textBoxComments.Document.Blocks.Clear();
}
}
}