1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Collections . ObjectModel ;
3
4
using System . Linq ;
4
5
using System . Windows . Input ;
5
6
using Rubberduck . SourceControl ;
6
7
using Rubberduck . UI . Command ;
8
+ // ReSharper disable ExplicitCallerInfoArgument
7
9
8
10
namespace Rubberduck . UI . SourceControl
9
11
{
@@ -13,8 +15,9 @@ public ChangesViewViewModel()
13
15
{
14
16
_commitCommand = new DelegateCommand ( _ => Commit ( ) , _ => ! string . IsNullOrEmpty ( CommitMessage ) && IncludedChanges != null && IncludedChanges . Any ( ) ) ;
15
17
16
- _undoChangesToolbarButtonCommand =
17
- new DelegateCommand ( fileStatusEntry => UndoChanges ( ( IFileStatusEntry ) fileStatusEntry ) ) ;
18
+ _includeChangesToolbarButtonCommand = new DelegateCommand ( fileStatusEntry => IncludeChanges ( ( IFileStatusEntry ) fileStatusEntry ) ) ;
19
+ _excludeChangesToolbarButtonCommand = new DelegateCommand ( fileStatusEntry => ExcludeChanges ( ( IFileStatusEntry ) fileStatusEntry ) ) ;
20
+ _undoChangesToolbarButtonCommand = new DelegateCommand ( fileStatusEntry => UndoChanges ( ( IFileStatusEntry ) fileStatusEntry ) ) ;
18
21
}
19
22
20
23
private string _commitMessage ;
@@ -46,74 +49,62 @@ public ISourceControlProvider Provider
46
49
47
50
public void RefreshView ( )
48
51
{
49
- CurrentBranch = Provider . CurrentBranch . Name ;
50
-
51
- var fileStats = Provider . Status ( ) . ToList ( ) ;
52
-
53
- IncludedChanges = new ObservableCollection < IFileStatusEntry > ( fileStats . Where ( stat => stat . FileStatus . HasFlag ( FileStatus . Modified ) ) ) ;
54
- UntrackedFiles = new ObservableCollection < IFileStatusEntry > ( fileStats . Where ( stat => stat . FileStatus . HasFlag ( FileStatus . Untracked ) ) ) ;
52
+ OnPropertyChanged ( "CurrentBranch" ) ;
53
+ OnPropertyChanged ( "IncludedChanges" ) ;
54
+ OnPropertyChanged ( "ExcludedChanges" ) ;
55
+ OnPropertyChanged ( "UntrackedFiles" ) ;
55
56
}
56
57
57
58
private void Provider_BranchChanged ( object sender , EventArgs e )
58
59
{
59
- CurrentBranch = Provider . CurrentBranch . Name ;
60
+ OnPropertyChanged ( " CurrentBranch" ) ;
60
61
}
61
62
62
- private string _currentBranch ;
63
63
public string CurrentBranch
64
64
{
65
- get { return _currentBranch ; }
66
- set
67
- {
68
- if ( _currentBranch != value )
69
- {
70
- _currentBranch = value ;
71
- OnPropertyChanged ( ) ;
72
- }
73
- }
65
+ get { return Provider == null ? string . Empty : Provider . CurrentBranch . Name ; }
74
66
}
75
67
76
68
public CommitAction CommitAction { get ; set ; }
77
69
78
- private ObservableCollection < IFileStatusEntry > _includedChanges ;
79
- public ObservableCollection < IFileStatusEntry > IncludedChanges
70
+ public IEnumerable < IFileStatusEntry > IncludedChanges
80
71
{
81
- get { return _includedChanges ; }
82
- set
72
+ get
83
73
{
84
- if ( _includedChanges != value )
85
- {
86
- _includedChanges = value ;
87
- OnPropertyChanged ( ) ;
88
- }
74
+ return Provider == null
75
+ ? new ObservableCollection < IFileStatusEntry > ( )
76
+ : new ObservableCollection < IFileStatusEntry > (
77
+ Provider . Status ( )
78
+ . Where (
79
+ stat =>
80
+ stat . FileStatus . HasFlag ( FileStatus . Modified ) ||
81
+ stat . FileStatus . HasFlag ( FileStatus . Added ) ) ) ;
89
82
}
90
83
}
91
84
92
- private ObservableCollection < IFileStatusEntry > _excludedChanges ;
93
- public ObservableCollection < IFileStatusEntry > ExcludedChanges
85
+ public IEnumerable < IFileStatusEntry > ExcludedChanges
94
86
{
95
- get { return _excludedChanges ; }
96
- set
87
+ get
97
88
{
98
- if ( _excludedChanges != value )
99
- {
100
- _excludedChanges = value ;
101
- OnPropertyChanged ( ) ;
102
- }
89
+ return Provider == null
90
+ ? new ObservableCollection < IFileStatusEntry > ( )
91
+ : new ObservableCollection < IFileStatusEntry > (
92
+ Provider . Status ( )
93
+ . Where (
94
+ stat =>
95
+ stat . FileStatus . HasFlag ( FileStatus . Ignored ) &&
96
+ stat . FileStatus . HasFlag ( FileStatus . Modified ) ) ) ;
103
97
}
104
98
}
105
99
106
- private ObservableCollection < IFileStatusEntry > _untrackedFiles ;
107
- public ObservableCollection < IFileStatusEntry > UntrackedFiles
100
+ public IEnumerable < IFileStatusEntry > UntrackedFiles
108
101
{
109
- get { return _untrackedFiles ; }
110
- set
102
+ get
111
103
{
112
- if ( _untrackedFiles != value )
113
- {
114
- _untrackedFiles = value ;
115
- OnPropertyChanged ( ) ;
116
- }
104
+ return Provider == null
105
+ ? new ObservableCollection < IFileStatusEntry > ( )
106
+ : new ObservableCollection < IFileStatusEntry > (
107
+ Provider . Status ( ) . Where ( stat => stat . FileStatus . HasFlag ( FileStatus . Untracked ) ) ) ;
117
108
}
118
109
}
119
110
@@ -126,6 +117,8 @@ private void UndoChanges(IFileStatusEntry fileStatusEntry)
126
117
: Provider . CurrentRepository . LocalLocation + "\\ " ;
127
118
128
119
Provider . Undo ( localLocation + fileStatusEntry . FilePath ) ;
120
+
121
+ RefreshView ( ) ;
129
122
}
130
123
catch ( SourceControlException ex )
131
124
{
@@ -156,6 +149,8 @@ private void Commit()
156
149
{
157
150
Provider . Push ( ) ;
158
151
}
152
+
153
+ RefreshView ( ) ;
159
154
}
160
155
catch ( SourceControlException ex )
161
156
{
@@ -164,22 +159,45 @@ private void Commit()
164
159
165
160
CommitMessage = string . Empty ;
166
161
}
162
+
163
+ private void IncludeChanges ( IFileStatusEntry fileStatusEntry )
164
+ {
165
+ Provider . AddFile ( fileStatusEntry . FilePath ) ;
166
+
167
+ RefreshView ( ) ;
168
+ }
169
+
170
+ private void ExcludeChanges ( IFileStatusEntry fileStatusEntry )
171
+ {
172
+ Provider . ExcludeFile ( fileStatusEntry . FilePath ) ;
173
+
174
+ RefreshView ( ) ;
175
+ }
167
176
168
177
private readonly ICommand _commitCommand ;
169
178
public ICommand CommitCommand
170
179
{
171
- get
172
- {
173
- return _commitCommand ;
174
- }
180
+ get { return _commitCommand ; }
175
181
}
176
182
177
- private ICommand _undoChangesToolbarButtonCommand ;
183
+ private readonly ICommand _undoChangesToolbarButtonCommand ;
178
184
public ICommand UndoChangesToolbarButtonCommand
179
185
{
180
186
get { return _undoChangesToolbarButtonCommand ; }
181
187
}
182
188
189
+ private readonly ICommand _excludeChangesToolbarButtonCommand ;
190
+ public ICommand ExcludeChangesToolbarButtonCommand
191
+ {
192
+ get { return _excludeChangesToolbarButtonCommand ; }
193
+ }
194
+
195
+ private readonly ICommand _includeChangesToolbarButtonCommand ;
196
+ public ICommand IncludeChangesToolbarButtonCommand
197
+ {
198
+ get { return _includeChangesToolbarButtonCommand ; }
199
+ }
200
+
183
201
public event EventHandler < ErrorEventArgs > ErrorThrown ;
184
202
private void RaiseErrorEvent ( string message , string innerMessage )
185
203
{
0 commit comments