Skip to content

Commit 7855e3c

Browse files
committed
Correctly clear SC view when tracked project is closed
1 parent d8aefb5 commit 7855e3c

File tree

9 files changed

+103
-38
lines changed

9 files changed

+103
-38
lines changed

RetailCoder.VBE/UI/SourceControl/BranchesViewViewModel.cs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Windows.Input;
54
using NLog;
65
using Rubberduck.SourceControl;
76
using Rubberduck.UI.Command;
@@ -60,6 +59,22 @@ public void RefreshView()
6059
DestinationBranch = CurrentBranch;
6160
}
6261

62+
public void ResetView()
63+
{
64+
Logger.Trace("Resetting view");
65+
66+
_provider = null;
67+
_currentBranch = string.Empty;
68+
SourceBranch = string.Empty;
69+
DestinationBranch = CurrentBranch;
70+
71+
OnPropertyChanged("LocalBranches");
72+
OnPropertyChanged("PublishedBranches");
73+
OnPropertyChanged("UnpublishedBranches");
74+
OnPropertyChanged("Branches");
75+
OnPropertyChanged("CurrentBranch");
76+
}
77+
6378
public SourceControlTab Tab { get { return SourceControlTab.Branches; } }
6479

6580
public IEnumerable<string> Branches
@@ -115,9 +130,12 @@ public string CurrentBranch
115130

116131
CreateBranchSource = value;
117132

133+
if (Provider == null) { return; }
134+
118135
try
119136
{
120-
OnLoadingComponentsStarted();
137+
Provider.NotifyExternalFileChanges = false;
138+
Provider.HandleVbeSinkEvents = false;
121139
Provider.Checkout(_currentBranch);
122140
}
123141
catch (SourceControlException ex)
@@ -130,7 +148,8 @@ public string CurrentBranch
130148
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
131149
throw;
132150
}
133-
OnLoadingComponentsCompleted();
151+
Provider.NotifyExternalFileChanges = true;
152+
Provider.HandleVbeSinkEvents = true;
134153
}
135154
}
136155
}
@@ -330,7 +349,8 @@ private void MergeBranchOk()
330349
{
331350
Logger.Trace("Merging branch {0} into branch {1}", SourceBranch, DestinationBranch);
332351

333-
OnLoadingComponentsStarted();
352+
Provider.NotifyExternalFileChanges = false;
353+
Provider.HandleVbeSinkEvents = false;
334354

335355
try
336356
{
@@ -339,19 +359,24 @@ private void MergeBranchOk()
339359
catch (SourceControlException ex)
340360
{
341361
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
342-
OnLoadingComponentsCompleted();
362+
Provider.NotifyExternalFileChanges = true;
363+
Provider.HandleVbeSinkEvents = true;
343364
return;
344365
}
345366
catch
346367
{
347368
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
348369
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
370+
Provider.NotifyExternalFileChanges = true;
371+
Provider.HandleVbeSinkEvents = true;
349372
throw;
350373
}
351374

352375
DisplayMergeBranchesGrid = false;
353376
RaiseErrorEvent(RubberduckUI.SourceControl_MergeStatus, string.Format(RubberduckUI.SourceControl_SuccessfulMerge, SourceBranch, DestinationBranch), NotificationType.Info);
354-
OnLoadingComponentsCompleted();
377+
378+
Provider.NotifyExternalFileChanges = true;
379+
Provider.HandleVbeSinkEvents = true;
355380
}
356381

357382
private void MergeBranchCancel()
@@ -380,8 +405,7 @@ private void DeleteBranch(bool isBranchPublished)
380405

381406
RefreshView();
382407
}
383-
384-
408+
385409
private bool CanDeleteBranch(bool isBranchPublished)
386410
{
387411
return isBranchPublished
@@ -515,25 +539,5 @@ private void RaiseErrorEvent(string message, string innerMessage, NotificationTy
515539
handler(this, new ErrorEventArgs(message, innerMessage, notificationType));
516540
}
517541
}
518-
519-
public event EventHandler<EventArgs> LoadingComponentsStarted;
520-
private void OnLoadingComponentsStarted()
521-
{
522-
var handler = LoadingComponentsStarted;
523-
if (handler != null)
524-
{
525-
handler(this, EventArgs.Empty);
526-
}
527-
}
528-
529-
public event EventHandler<EventArgs> LoadingComponentsCompleted;
530-
private void OnLoadingComponentsCompleted()
531-
{
532-
var handler = LoadingComponentsCompleted;
533-
if (handler != null)
534-
{
535-
handler(this, EventArgs.Empty);
536-
}
537-
}
538542
}
539543
}

RetailCoder.VBE/UI/SourceControl/ChangesViewViewModel.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.ObjectModel;
33
using System.Linq;
4-
using System.Windows.Input;
54
using NLog;
65
using Rubberduck.SourceControl;
76
using Rubberduck.UI.Command;
@@ -74,6 +73,19 @@ public void RefreshView()
7473
Provider.Status().Where(stat => stat.FileStatus.HasFlag(FileStatus.Untracked)));
7574
}
7675

76+
public void ResetView()
77+
{
78+
Logger.Trace("Resetting view");
79+
80+
_provider.BranchChanged -= Provider_BranchChanged;
81+
_provider = null;
82+
83+
OnPropertyChanged("CurrentBranch");
84+
85+
IncludedChanges = new ObservableCollection<IFileStatusEntry>();
86+
UntrackedFiles = new ObservableCollection<IFileStatusEntry>();
87+
}
88+
7789
public SourceControlTab Tab { get { return SourceControlTab.Changes; } }
7890

7991
private void Provider_BranchChanged(object sender, EventArgs e)

RetailCoder.VBE/UI/SourceControl/IControlViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ public interface IControlViewModel
2525
event EventHandler<ErrorEventArgs> ErrorThrown;
2626

2727
void RefreshView();
28+
void ResetView();
2829
}
2930
}

RetailCoder.VBE/UI/SourceControl/SettingsView.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
<ColumnDefinition />
3030
<ColumnDefinition Width="40" />
3131
</Grid.ColumnDefinitions>
32-
<TextBox Margin="5,0,0,0"
32+
<TextBox Margin="5,0,0,5"
3333
Padding="2"
3434
Text="{Binding DefaultRepositoryLocation, Mode=TwoWay}" />
3535
<Button Content="&#8230;"
36-
Margin="5,0"
36+
Margin="5,0,0,5"
3737
Grid.Column="1"
3838
FontSize="15"
3939
Command="{Binding ShowDefaultRepoFolderPickerCommand}" />

RetailCoder.VBE/UI/SourceControl/SettingsViewViewModel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Diagnostics;
33
using System.IO;
44
using System.Windows.Forms;
5-
using System.Windows.Input;
65
using NLog;
76
using Rubberduck.UI.Command;
87
using Rubberduck.SourceControl;
@@ -45,7 +44,12 @@ public SettingsViewViewModel(
4544
}
4645

4746
public ISourceControlProvider Provider { get; set; }
48-
public void RefreshView() {} // nothing to refresh here
47+
public void RefreshView() { } // nothing to refresh here
48+
49+
public void ResetView()
50+
{
51+
Provider = null;
52+
}
4953

5054
public SourceControlTab Tab { get { return SourceControlTab.Settings; } }
5155

RetailCoder.VBE/UI/SourceControl/SourceControlViewViewModel.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public SourceControlViewViewModel(
9393
_sinks.ComponentAdded += ComponentAdded;
9494
_sinks.ComponentRemoved += ComponentRemoved;
9595
_sinks.ComponentRenamed += ComponentRenamed;
96+
_sinks.ProjectRemoved += ProjectRemoved;
9697

9798
TabItems = new ObservableCollection<IControlView>
9899
{
@@ -177,6 +178,38 @@ private void ComponentRenamed(object sender, IComponentRenamedEventArgs e)
177178
}
178179
}
179180

181+
private void ProjectRemoved(object sender, IProjectEventArgs e)
182+
{
183+
if (Provider == null || !Provider.HandleVbeSinkEvents)
184+
{
185+
return;
186+
}
187+
188+
if (e.ProjectId != Provider.CurrentRepository.Id)
189+
{
190+
return;
191+
}
192+
193+
ResetView();
194+
}
195+
196+
private void ResetView()
197+
{
198+
Logger.Trace("Resetting view");
199+
200+
_provider = null;
201+
OnPropertyChanged("RepoDoesNotHaveRemoteLocation");
202+
Status = RubberduckUI.Offline;
203+
204+
UiDispatcher.InvokeAsync(() =>
205+
{
206+
foreach (var tab in _tabItems)
207+
{
208+
tab.ViewModel.ResetView();
209+
}
210+
});
211+
}
212+
180213
private static readonly IDictionary<NotificationType, BitmapImage> IconMappings =
181214
new Dictionary<NotificationType, BitmapImage>
182215
{

RetailCoder.VBE/UI/SourceControl/UnsyncedCommitsViewViewModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.ObjectModel;
3-
using System.Windows.Input;
43
using NLog;
54
using Rubberduck.SourceControl;
65
using Rubberduck.UI.Command;
@@ -44,6 +43,18 @@ public void RefreshView()
4443
OutgoingCommits = new ObservableCollection<ICommit>(Provider.UnsyncedLocalCommits);
4544
}
4645

46+
public void ResetView()
47+
{
48+
Logger.Trace("Resetting view");
49+
50+
_provider.BranchChanged -= Provider_BranchChanged;
51+
_provider = null;
52+
CurrentBranch = string.Empty;
53+
54+
IncomingCommits = new ObservableCollection<ICommit>();
55+
OutgoingCommits = new ObservableCollection<ICommit>();
56+
}
57+
4758
public SourceControlTab Tab { get { return SourceControlTab.UnsyncedCommits; } }
4859

4960
private void Provider_BranchChanged(object sender, EventArgs e)

Rubberduck.SourceControl/ISourceControlProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public interface ISourceControlProvider
1111
IEnumerable<IBranch> Branches { get; }
1212
IList<ICommit> UnsyncedLocalCommits { get; }
1313
IList<ICommit> UnsyncedRemoteCommits { get; }
14-
bool NotifyExternalFileChanges { get; }
15-
bool HandleVbeSinkEvents { get; }
14+
bool NotifyExternalFileChanges { get; set; }
15+
bool HandleVbeSinkEvents { get; set; }
1616

1717
event EventHandler<EventArgs> BranchChanged;
1818

Rubberduck.SourceControl/SourceControlProviderBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ protected SourceControlProviderBase(VBProject project, IRepository repository, I
3131
public abstract IEnumerable<IBranch> Branches { get; }
3232
public abstract IList<ICommit> UnsyncedLocalCommits { get; }
3333
public abstract IList<ICommit> UnsyncedRemoteCommits { get; }
34-
public bool NotifyExternalFileChanges { get; protected set; }
35-
public bool HandleVbeSinkEvents { get; protected set; }
34+
public bool NotifyExternalFileChanges { get; set; }
35+
public bool HandleVbeSinkEvents { get; set; }
3636
public abstract IRepository Clone(string remotePathOrUrl, string workingDirectory, SecureCredentials credentials = null);
3737
public abstract void Push();
3838
public abstract void Fetch(string remoteName);

0 commit comments

Comments
 (0)