Skip to content

Commit bb2bb9e

Browse files
committed
Fix bug with not loading a changed module.
1 parent d71dcaf commit bb2bb9e

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

RetailCoder.VBE/UI/SourceControl/SourceControlViewViewModel.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,29 @@ public void SetTab(SourceControlTab tab)
105105

106106
public void AddComponent(VBComponent component)
107107
{
108-
if (Provider == null) { return; }
108+
if (Provider == null || !Provider.NotifyVBAChanges) { return; }
109109

110-
//_fileSystemWatcher.EnableRaisingEvents = false;
111110
var fileStatus = Provider.Status().SingleOrDefault(stat => stat.FilePath.Split('.')[0] == component.Name);
112111
if (fileStatus != null)
113112
{
114113
Provider.AddFile(fileStatus.FilePath);
115114
}
116-
//_fileSystemWatcher.EnableRaisingEvents = true;
117115
}
118116

119117
public void RemoveComponent(VBComponent component)
120118
{
121-
if (Provider == null) { return; }
119+
if (Provider == null || !Provider.NotifyVBAChanges) { return; }
122120

123-
//_fileSystemWatcher.EnableRaisingEvents = false;
124121
var fileStatus = Provider.Status().SingleOrDefault(stat => stat.FilePath.Split('.')[0] == component.Name);
125122
if (fileStatus != null)
126123
{
127124
Provider.RemoveFile(fileStatus.FilePath, true);
128125
}
129-
//_fileSystemWatcher.EnableRaisingEvents = true;
130126
}
131127

132128
public void RenameComponent(VBComponent component, string oldName)
133129
{
134-
if (Provider == null) { return; }
130+
if (Provider == null || !Provider.NotifyVBAChanges) { return; }
135131

136132
var fileStatus = Provider.LastKnownStatus().SingleOrDefault(stat => stat.FilePath.Split('.')[0] == oldName);
137133
if (fileStatus != null)
@@ -205,6 +201,7 @@ private void _fileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
205201
if (_messageBox.Show("file changed", RubberduckUI.SourceControlPanel_Caption,
206202
MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.OK)
207203
{
204+
Provider.ReloadComponent(e.Name);
208205
UiDispatcher.InvokeAsync(Refresh);
209206
}
210207
}

Rubberduck.SourceControl/ISourceControlProvider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface ISourceControlProvider
1212
IList<ICommit> UnsyncedLocalCommits { get; }
1313
IList<ICommit> UnsyncedRemoteCommits { get; }
1414
bool NotifyExternalFileChanges { get; }
15+
bool NotifyVBAChanges { get; }
1516

1617
event EventHandler<EventArgs> BranchChanged;
1718

@@ -164,5 +165,11 @@ public interface ISourceControlProvider
164165
/// </summary>
165166
/// <returns>Collection of statuses.</returns>
166167
IEnumerable<IFileStatusEntry> LastKnownStatus();
168+
169+
/// <summary>
170+
/// Reloads the component into the VBE
171+
/// </summary>
172+
/// <param name="fileName"></param>
173+
void ReloadComponent(string fileName);
167174
}
168175
}

Rubberduck.SourceControl/SourceControlProviderBase.cs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Rubberduck.SourceControl
1212
public abstract class SourceControlProviderBase : ISourceControlProvider
1313
{
1414
private readonly ICodePaneWrapperFactory _wrapperFactory;
15-
protected VBProject Project;
15+
protected readonly VBProject Project;
1616

1717
protected SourceControlProviderBase(VBProject project)
1818
{
@@ -32,6 +32,7 @@ protected SourceControlProviderBase(VBProject project, IRepository repository, I
3232
public abstract IList<ICommit> UnsyncedLocalCommits { get; }
3333
public abstract IList<ICommit> UnsyncedRemoteCommits { get; }
3434
public bool NotifyExternalFileChanges { get; protected set; }
35+
public bool NotifyVBAChanges { get; protected set; }
3536
public abstract IRepository Clone(string remotePathOrUrl, string workingDirectory);
3637
public abstract void Push();
3738
public abstract void Fetch(string remoteName);
@@ -116,9 +117,12 @@ public virtual void Undo(string filePath)
116117

117118
if (File.Exists(filePath))
118119
{
119-
var component = Project.VBComponents.Item(componentName);
120+
var component = Project.VBComponents.OfType<VBComponent>().FirstOrDefault(f => f.Name == filePath.Split('.')[0]);
121+
122+
NotifyVBAChanges = false;
120123
Project.VBComponents.RemoveSafely(component);
121124
Project.VBComponents.ImportSourceFile(filePath);
125+
NotifyVBAChanges = true;
122126
}
123127
}
124128

@@ -142,11 +146,52 @@ protected string GetProjectNameFromDirectory(string directory)
142146
.LastOrDefault(c => c != "git");
143147
}
144148

149+
public void ReloadComponent(string filePath)
150+
{
151+
NotifyVBAChanges = false;
152+
153+
var codePane = Project.VBE.ActiveCodePane;
154+
155+
if (codePane != null)
156+
{
157+
var codePaneWrapper = _wrapperFactory.Create(codePane);
158+
var selection = new QualifiedSelection(new QualifiedModuleName(codePaneWrapper.CodeModule.Parent),
159+
codePaneWrapper.Selection);
160+
string name = null;
161+
if (selection.QualifiedName.Component != null)
162+
{
163+
name = selection.QualifiedName.Component.Name;
164+
}
165+
166+
var component = Project.VBComponents.OfType<VBComponent>().FirstOrDefault(f => f.Name == filePath.Split('.')[0]);
167+
Project.VBComponents.RemoveSafely(component);
168+
169+
var directory = CurrentRepository.LocalLocation;
170+
directory += directory.EndsWith("\\") ? string.Empty : "\\";
171+
Project.VBComponents.Import(directory + filePath);
172+
173+
Project.VBE.SetSelection(selection.QualifiedName.Project, selection.Selection, name, _wrapperFactory);
174+
}
175+
else
176+
{
177+
var component = Project.VBComponents.OfType<VBComponent>().FirstOrDefault(f => f.Name == filePath.Split('.')[0]);
178+
Project.VBComponents.RemoveSafely(component);
179+
180+
var directory = CurrentRepository.LocalLocation;
181+
directory += directory.EndsWith("\\") ? string.Empty : "\\";
182+
Project.VBComponents.Import(directory + filePath);
183+
}
184+
185+
NotifyVBAChanges = true;
186+
}
187+
145188
private void Refresh()
146189
{
147190
//Because refreshing removes all components, we need to store the current selection,
148191
// so we can correctly reset it once the files are imported from the repository.
149192

193+
NotifyVBAChanges = false;
194+
150195
var codePane = Project.VBE.ActiveCodePane;
151196

152197
if (codePane != null)
@@ -170,6 +215,8 @@ private void Refresh()
170215
Project.RemoveAllComponents();
171216
Project.ImportSourceFiles(CurrentRepository.LocalLocation);
172217
}
218+
219+
NotifyVBAChanges = true;
173220
}
174221
}
175222
}

0 commit comments

Comments
 (0)