Skip to content

Commit 89b9639

Browse files
committed
Warn when documents do not exist (only when loading the repo/switching branches). Retry loading document-type components every time the repo is refreshed in case the component is added (we don't track document-type components by default).
1 parent c811561 commit 89b9639

File tree

10 files changed

+131
-44
lines changed

10 files changed

+131
-44
lines changed

RetailCoder.VBE/UI/SourceControl/BranchesViewViewModel.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public string CurrentBranch
140140
}
141141
catch (SourceControlException ex)
142142
{
143-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
143+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
144144
}
145145
catch
146146
{
@@ -324,7 +324,7 @@ private void CreateBranchOk()
324324
}
325325
catch (SourceControlException ex)
326326
{
327-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
327+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
328328
}
329329
catch
330330
{
@@ -358,7 +358,7 @@ private void MergeBranchOk()
358358
}
359359
catch (SourceControlException ex)
360360
{
361-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
361+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
362362
Provider.NotifyExternalFileChanges = true;
363363
Provider.HandleVbeSinkEvents = true;
364364
return;
@@ -394,7 +394,7 @@ private void DeleteBranch(bool isBranchPublished)
394394
}
395395
catch (SourceControlException ex)
396396
{
397-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
397+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
398398
}
399399
catch
400400
{
@@ -422,7 +422,7 @@ private void PublishBranch()
422422
}
423423
catch (SourceControlException ex)
424424
{
425-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
425+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
426426
}
427427
catch
428428
{
@@ -443,7 +443,7 @@ private void UnpublishBranch()
443443
}
444444
catch (SourceControlException ex)
445445
{
446-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
446+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
447447
}
448448
catch
449449
{
@@ -531,12 +531,21 @@ public CommandBase UnpublishBranchToolbarButtonCommand
531531
}
532532

533533
public event EventHandler<ErrorEventArgs> ErrorThrown;
534-
private void RaiseErrorEvent(string message, string innerMessage, NotificationType notificationType)
534+
private void RaiseErrorEvent(string message, Exception innerException, NotificationType notificationType)
535535
{
536536
var handler = ErrorThrown;
537537
if (handler != null)
538538
{
539-
handler(this, new ErrorEventArgs(message, innerMessage, notificationType));
539+
handler(this, new ErrorEventArgs(message, innerException, notificationType));
540+
}
541+
}
542+
543+
private void RaiseErrorEvent(string title, string message, NotificationType notificationType)
544+
{
545+
var handler = ErrorThrown;
546+
if (handler != null)
547+
{
548+
handler(this, new ErrorEventArgs(title, message, notificationType));
540549
}
541550
}
542551
}

RetailCoder.VBE/UI/SourceControl/ChangesViewViewModel.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private void UndoChanges(IFileStatusEntry fileStatusEntry)
158158
}
159159
catch (SourceControlException ex)
160160
{
161-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
161+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
162162
}
163163
catch
164164
{
@@ -213,7 +213,7 @@ private void Commit()
213213
}
214214
catch (SourceControlException ex)
215215
{
216-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
216+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
217217
}
218218
catch
219219
{
@@ -274,12 +274,21 @@ public CommandBase IncludeChangesToolbarButtonCommand
274274
}
275275

276276
public event EventHandler<ErrorEventArgs> ErrorThrown;
277-
private void RaiseErrorEvent(string message, string innerMessage, NotificationType notificationType)
277+
private void RaiseErrorEvent(string message, Exception innerException, NotificationType notificationType)
278278
{
279279
var handler = ErrorThrown;
280280
if (handler != null)
281281
{
282-
handler(this, new ErrorEventArgs(message, innerMessage, notificationType));
282+
handler(this, new ErrorEventArgs(message, innerException, notificationType));
283+
}
284+
}
285+
286+
private void RaiseErrorEvent(string title, string message, NotificationType notificationType)
287+
{
288+
var handler = ErrorThrown;
289+
if (handler != null)
290+
{
291+
handler(this, new ErrorEventArgs(title, message, notificationType));
283292
}
284293
}
285294
}

RetailCoder.VBE/UI/SourceControl/IControlViewModel.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,34 @@
33

44
namespace Rubberduck.UI.SourceControl
55
{
6+
using System.Linq;
7+
68
public class ErrorEventArgs
79
{
8-
public readonly string Message;
10+
public readonly string Title;
911
public readonly string InnerMessage;
1012
public readonly NotificationType NotificationType;
1113

12-
public ErrorEventArgs(string message, string innerMessage, NotificationType notificationType)
14+
public ErrorEventArgs(string title, Exception innerException, NotificationType notificationType)
15+
{
16+
Title = title;
17+
InnerMessage = GetInnerExceptionMessage(innerException);
18+
NotificationType = notificationType;
19+
}
20+
21+
public ErrorEventArgs(string title, string message, NotificationType notificationType)
1322
{
14-
Message = message;
15-
InnerMessage = innerMessage;
23+
Title = title;
24+
InnerMessage = message;
1625
NotificationType = notificationType;
1726
}
27+
28+
private string GetInnerExceptionMessage(Exception ex)
29+
{
30+
return ex is AggregateException
31+
? string.Join(Environment.NewLine, ((AggregateException) ex).InnerExceptions.Select(s => s.Message))
32+
: ex.Message;
33+
}
1834
}
1935

2036
public interface IControlViewModel

RetailCoder.VBE/UI/SourceControl/SettingsViewViewModel.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,21 @@ public CommandBase ShowGitAttributesCommand
241241
}
242242

243243
public event EventHandler<ErrorEventArgs> ErrorThrown;
244-
private void RaiseErrorEvent(string message, string innerMessage, NotificationType notificationType)
244+
private void RaiseErrorEvent(string message, Exception innerException, NotificationType notificationType)
245245
{
246246
var handler = ErrorThrown;
247247
if (handler != null)
248248
{
249-
handler(this, new ErrorEventArgs(message, innerMessage, notificationType));
249+
handler(this, new ErrorEventArgs(message, innerException, notificationType));
250+
}
251+
}
252+
253+
private void RaiseErrorEvent(string title, string message, NotificationType notificationType)
254+
{
255+
var handler = ErrorThrown;
256+
if (handler != null)
257+
{
258+
handler(this, new ErrorEventArgs(title, message, notificationType));
250259
}
251260
}
252261

RetailCoder.VBE/UI/SourceControl/SourceControlViewViewModel.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,9 @@ private void ViewModel_ErrorThrown(object sender, ErrorEventArgs e)
586586
}
587587
else
588588
{
589-
Logger.Trace("Displaying {0} with title '{1}' and message '{2}'", e.NotificationType, e.Message, e.InnerMessage);
589+
Logger.Trace("Displaying {0} with title '{1}' and message '{2}'", e.NotificationType, e.Title, e.InnerMessage);
590590

591-
ErrorTitle = e.Message;
591+
ErrorTitle = e.Title;
592592
ErrorMessage = e.InnerMessage;
593593

594594
IconMappings.TryGetValue(e.NotificationType, out _errorIcon);
@@ -643,7 +643,7 @@ private void InitRepo()
643643
catch (SourceControlException ex)
644644
{
645645
ViewModel_ErrorThrown(this,
646-
new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
646+
new ErrorEventArgs(ex.Message, ex.InnerException, NotificationType.Error));
647647
}
648648
catch
649649
{
@@ -722,7 +722,7 @@ private void OpenRepo()
722722
catch (SourceControlException ex)
723723
{
724724
_sinks.IsEnabled = true;
725-
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
725+
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException, NotificationType.Error));
726726
return;
727727
}
728728
catch
@@ -769,7 +769,7 @@ private void CloneRepo(SecureCredentials credentials = null)
769769
_isCloning = false;
770770
}
771771

772-
ViewModel_ErrorThrown(this, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
772+
ViewModel_ErrorThrown(this, new ErrorEventArgs(ex.Message, ex.InnerException, NotificationType.Error));
773773
return;
774774
}
775775
catch
@@ -805,7 +805,7 @@ private void PublishRepo()
805805
}
806806
catch (SourceControlException ex)
807807
{
808-
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
808+
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException, NotificationType.Error));
809809
}
810810
catch
811811
{
@@ -876,7 +876,7 @@ private void OpenRepoAssignedToProject()
876876
}
877877
catch (SourceControlException ex)
878878
{
879-
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
879+
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException, NotificationType.Error));
880880
Status = RubberduckUI.Offline;
881881

882882
_config.Repositories.Remove(_config.Repositories.FirstOrDefault(repo => repo.Id == _vbe.ActiveVBProject.HelpFile));

RetailCoder.VBE/UI/SourceControl/UnsyncedCommitsViewViewModel.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private void FetchCommits()
115115
}
116116
catch (SourceControlException ex)
117117
{
118-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
118+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
119119
}
120120
catch
121121
{
@@ -136,7 +136,7 @@ private void PullCommits()
136136
}
137137
catch (SourceControlException ex)
138138
{
139-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
139+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
140140
}
141141
catch
142142
{
@@ -157,7 +157,7 @@ private void PushCommits()
157157
}
158158
catch (SourceControlException ex)
159159
{
160-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
160+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
161161
}
162162
catch
163163
{
@@ -179,7 +179,7 @@ private void SyncCommits()
179179
}
180180
catch (SourceControlException ex)
181181
{
182-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
182+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
183183
}
184184
catch
185185
{
@@ -226,12 +226,21 @@ public CommandBase SyncCommitsCommand
226226
}
227227

228228
public event EventHandler<ErrorEventArgs> ErrorThrown;
229-
private void RaiseErrorEvent(string message, string innerMessage, NotificationType notificationType)
229+
private void RaiseErrorEvent(string message, Exception innerException, NotificationType notificationType)
230230
{
231231
var handler = ErrorThrown;
232232
if (handler != null)
233233
{
234-
handler(this, new ErrorEventArgs(message, innerMessage, notificationType));
234+
handler(this, new ErrorEventArgs(message, innerException, notificationType));
235+
}
236+
}
237+
238+
private void RaiseErrorEvent(string title, string message, NotificationType notificationType)
239+
{
240+
var handler = ErrorThrown;
241+
if (handler != null)
242+
{
243+
handler(this, new ErrorEventArgs(title, message, notificationType));
235244
}
236245
}
237246
}

Rubberduck.SourceControl/SourceControlProviderBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ public virtual void Checkout(string branch)
120120

121121
public virtual void Undo(string filePath)
122122
{
123-
var componentName = Path.GetFileNameWithoutExtension(filePath);
124-
125123
if (File.Exists(filePath))
126124
{
127125
var component = Project.VBComponents.OfType<VBComponent>().FirstOrDefault(f => f.Name == filePath.Split('.')[0]);
@@ -142,6 +140,7 @@ public virtual IEnumerable<IFileStatusEntry> Status()
142140
{
143141
NotifyExternalFileChanges = false;
144142
Project.ExportSourceFiles(CurrentRepository.LocalLocation);
143+
Project.ImportDocumentTypeSourceFiles(CurrentRepository.LocalLocation);
145144
NotifyExternalFileChanges = true;
146145
return null;
147146
}

Rubberduck.VBEEditor/Extensions/VBComponentsExtensions.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ public static void ImportSourceFile(this VBComponents components, string filePat
4747
var codeLines = codeString.Split(new []{Environment.NewLine}, StringSplitOptions.None);
4848
if (ext == VBComponentExtensions.DocClassExtension)
4949
{
50-
try
51-
{
52-
var component = components.Item(name);
53-
component.CodeModule.Clear();
54-
component.CodeModule.AddFromString(codeString);
55-
}
56-
catch (IndexOutOfRangeException) { } // component doesn't exist
50+
var component = components.Item(name);
51+
component.CodeModule.Clear();
52+
component.CodeModule.AddFromString(codeString);
5753
}
5854
else if (ext == VBComponentExtensions.FormExtension)
5955
{

0 commit comments

Comments
 (0)