Skip to content

Commit 6128069

Browse files
committed
New features, some broken.
1 parent 3cc9bc7 commit 6128069

File tree

7 files changed

+106
-55
lines changed

7 files changed

+106
-55
lines changed

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,4 +1398,7 @@ All our stargazers, likers & followers, for the warm fuzzies
13981398
<data name="SourceControl_UndoChangesButton" xml:space="preserve">
13991399
<value>Undo</value>
14001400
</data>
1401+
<data name="SourceControl_Delete" xml:space="preserve">
1402+
<value>Delete</value>
1403+
</data>
14011404
</root>

RetailCoder.VBE/UI/SourceControl/ChangesView.xaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<UserControl x:Class="Rubberduck.UI.SourceControl.ChangesView"
1+
<TabItem x:Class="Rubberduck.UI.SourceControl.ChangesView"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -8,9 +8,10 @@
88
xmlns:converters="clr-namespace:Rubberduck.UI.SourceControl.Converters"
99
xmlns:converters1="clr-namespace:Rubberduck.UI.Settings.Converters"
1010
mc:Ignorable="d"
11+
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControl_Changes}"
1112
d:DesignHeight="500" d:DesignWidth="300"
1213
d:DataContext="{d:DesignInstance {x:Type sourceControl:ChangesViewViewModel}, IsDesignTimeCreatable=False}">
13-
<UserControl.Resources>
14+
<TabItem.Resources>
1415
<BitmapImage x:Key="CheckImage" UriSource="../../Resources/tick.png" />
1516
<BitmapImage x:Key="DeleteImage" UriSource="../../Resources/cross-script.png" />
1617
<BitmapImage x:Key="UndoImage" UriSource="../../Resources/arrow-circle-left.png" />
@@ -74,7 +75,7 @@
7475
<Setter Property="ColumnHeaderHeight" Value="22" />
7576
<Setter Property="BorderThickness" Value="0" />
7677
</Style>
77-
</UserControl.Resources>
78+
</TabItem.Resources>
7879
<Grid>
7980
<ScrollViewer VerticalScrollBarVisibility="Auto">
8081
<StackPanel Margin="5">
@@ -249,4 +250,4 @@
249250
</StackPanel>
250251
</ScrollViewer>
251252
</Grid>
252-
</UserControl>
253+
</TabItem>

RetailCoder.VBE/UI/SourceControl/ChangesViewViewModel.cs

Lines changed: 69 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Collections.ObjectModel;
34
using System.Linq;
45
using System.Windows.Input;
56
using Rubberduck.SourceControl;
67
using Rubberduck.UI.Command;
8+
// ReSharper disable ExplicitCallerInfoArgument
79

810
namespace Rubberduck.UI.SourceControl
911
{
@@ -13,8 +15,9 @@ public ChangesViewViewModel()
1315
{
1416
_commitCommand = new DelegateCommand(_ => Commit(), _ => !string.IsNullOrEmpty(CommitMessage) && IncludedChanges != null && IncludedChanges.Any());
1517

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));
1821
}
1922

2023
private string _commitMessage;
@@ -46,74 +49,62 @@ public ISourceControlProvider Provider
4649

4750
public void RefreshView()
4851
{
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");
5556
}
5657

5758
private void Provider_BranchChanged(object sender, EventArgs e)
5859
{
59-
CurrentBranch = Provider.CurrentBranch.Name;
60+
OnPropertyChanged("CurrentBranch");
6061
}
6162

62-
private string _currentBranch;
6363
public string CurrentBranch
6464
{
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; }
7466
}
7567

7668
public CommitAction CommitAction { get; set; }
7769

78-
private ObservableCollection<IFileStatusEntry> _includedChanges;
79-
public ObservableCollection<IFileStatusEntry> IncludedChanges
70+
public IEnumerable<IFileStatusEntry> IncludedChanges
8071
{
81-
get { return _includedChanges; }
82-
set
72+
get
8373
{
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)));
8982
}
9083
}
9184

92-
private ObservableCollection<IFileStatusEntry> _excludedChanges;
93-
public ObservableCollection<IFileStatusEntry> ExcludedChanges
85+
public IEnumerable<IFileStatusEntry> ExcludedChanges
9486
{
95-
get { return _excludedChanges; }
96-
set
87+
get
9788
{
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)));
10397
}
10498
}
10599

106-
private ObservableCollection<IFileStatusEntry> _untrackedFiles;
107-
public ObservableCollection<IFileStatusEntry> UntrackedFiles
100+
public IEnumerable<IFileStatusEntry> UntrackedFiles
108101
{
109-
get { return _untrackedFiles; }
110-
set
102+
get
111103
{
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)));
117108
}
118109
}
119110

@@ -126,6 +117,8 @@ private void UndoChanges(IFileStatusEntry fileStatusEntry)
126117
: Provider.CurrentRepository.LocalLocation + "\\";
127118

128119
Provider.Undo(localLocation + fileStatusEntry.FilePath);
120+
121+
RefreshView();
129122
}
130123
catch (SourceControlException ex)
131124
{
@@ -156,6 +149,8 @@ private void Commit()
156149
{
157150
Provider.Push();
158151
}
152+
153+
RefreshView();
159154
}
160155
catch (SourceControlException ex)
161156
{
@@ -164,22 +159,45 @@ private void Commit()
164159

165160
CommitMessage = string.Empty;
166161
}
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+
}
167176

168177
private readonly ICommand _commitCommand;
169178
public ICommand CommitCommand
170179
{
171-
get
172-
{
173-
return _commitCommand;
174-
}
180+
get { return _commitCommand; }
175181
}
176182

177-
private ICommand _undoChangesToolbarButtonCommand;
183+
private readonly ICommand _undoChangesToolbarButtonCommand;
178184
public ICommand UndoChangesToolbarButtonCommand
179185
{
180186
get { return _undoChangesToolbarButtonCommand; }
181187
}
182188

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+
183201
public event EventHandler<ErrorEventArgs> ErrorThrown;
184202
private void RaiseErrorEvent(string message, string innerMessage)
185203
{

Rubberduck.SourceControl/GitProvider.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,19 @@ public override void AddFile(string filePath)
436436
}
437437
}
438438

439+
public override void ExcludeFile(string filePath)
440+
{
441+
try
442+
{
443+
// https://github.com/libgit2/libgit2sharp/wiki/Git-add
444+
_repo.Unstage(filePath);
445+
}
446+
catch (LibGit2SharpException ex)
447+
{
448+
throw new SourceControlException(string.Format("Failed to stage file {0}", filePath), ex);
449+
}
450+
}
451+
439452
/// <summary>
440453
/// Removes file from staging area, but leaves the file in the working directory.
441454
/// </summary>

Rubberduck.SourceControl/ISourceControlProvider.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ public interface ISourceControlProvider
108108
/// <param name="filePath"></param>
109109
void AddFile(string filePath);
110110

111+
/// <summary>
112+
/// Exclude a file from tracking.
113+
/// </summary>
114+
/// <param name="filePath">The name of the file to exclude</param>
115+
void ExcludeFile(string filePath);
116+
111117
/// <summary>
112118
/// Removes file from tracking.
113119
/// </summary>

Rubberduck.SourceControl/SourceControlProviderBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected SourceControlProviderBase(VBProject project, IRepository repository, I
4242
public abstract void Commit(string message);
4343
public abstract void Publish(string branch);
4444
public abstract void Unpublish(string branch);
45+
public abstract void ExcludeFile(string filePath);
4546

4647
public virtual void CreateBranch(string sourceBranch, string branch)
4748
{

0 commit comments

Comments
 (0)