Skip to content

Commit 3cc9bc7

Browse files
committed
Well, Undo *should* work. I'm not sure why it is bringing in arbitrary changes after I make a single change. The change isn't there (even in the files I'm working with), then I change something else, and the changes are there...
1 parent 678001f commit 3cc9bc7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

RetailCoder.VBE/UI/SourceControl/ChangesViewViewModel.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class ChangesViewViewModel : ViewModelBase, IControlViewModel
1212
public ChangesViewViewModel()
1313
{
1414
_commitCommand = new DelegateCommand(_ => Commit(), _ => !string.IsNullOrEmpty(CommitMessage) && IncludedChanges != null && IncludedChanges.Any());
15+
16+
_undoChangesToolbarButtonCommand =
17+
new DelegateCommand(fileStatusEntry => UndoChanges((IFileStatusEntry) fileStatusEntry));
1518
}
1619

1720
private string _commitMessage;
@@ -114,6 +117,22 @@ public ObservableCollection<IFileStatusEntry> UntrackedFiles
114117
}
115118
}
116119

120+
private void UndoChanges(IFileStatusEntry fileStatusEntry)
121+
{
122+
try
123+
{
124+
var localLocation = Provider.CurrentRepository.LocalLocation.EndsWith("\\")
125+
? Provider.CurrentRepository.LocalLocation
126+
: Provider.CurrentRepository.LocalLocation + "\\";
127+
128+
Provider.Undo(localLocation + fileStatusEntry.FilePath);
129+
}
130+
catch (SourceControlException ex)
131+
{
132+
RaiseErrorEvent(ex.Message, ex.InnerException.Message);
133+
}
134+
}
135+
117136
private void Commit()
118137
{
119138
var changes = IncludedChanges.Select(c => c.FilePath).ToList();
@@ -155,6 +174,12 @@ public ICommand CommitCommand
155174
}
156175
}
157176

177+
private ICommand _undoChangesToolbarButtonCommand;
178+
public ICommand UndoChangesToolbarButtonCommand
179+
{
180+
get { return _undoChangesToolbarButtonCommand; }
181+
}
182+
158183
public event EventHandler<ErrorEventArgs> ErrorThrown;
159184
private void RaiseErrorEvent(string message, string innerMessage)
160185
{

Rubberduck.SourceControl/SourceControlProviderBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public virtual void Undo(string filePath)
107107

108108
//GetFileNameWithoutExtension returns empty string if it's not a file
109109
//https://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension%28v=vs.110%29.aspx
110-
if (componentName != String.Empty)
110+
if (componentName != string.Empty)
111111
{
112112
var component = Project.VBComponents.Item(componentName);
113113
Project.VBComponents.RemoveSafely(component);

0 commit comments

Comments
 (0)