@@ -12,7 +12,7 @@ namespace Rubberduck.SourceControl
12
12
public abstract class SourceControlProviderBase : ISourceControlProvider
13
13
{
14
14
private readonly ICodePaneWrapperFactory _wrapperFactory ;
15
- protected VBProject Project ;
15
+ protected readonly VBProject Project ;
16
16
17
17
protected SourceControlProviderBase ( VBProject project )
18
18
{
@@ -32,6 +32,7 @@ protected SourceControlProviderBase(VBProject project, IRepository repository, I
32
32
public abstract IList < ICommit > UnsyncedLocalCommits { get ; }
33
33
public abstract IList < ICommit > UnsyncedRemoteCommits { get ; }
34
34
public bool NotifyExternalFileChanges { get ; protected set ; }
35
+ public bool NotifyVBAChanges { get ; protected set ; }
35
36
public abstract IRepository Clone ( string remotePathOrUrl , string workingDirectory ) ;
36
37
public abstract void Push ( ) ;
37
38
public abstract void Fetch ( string remoteName ) ;
@@ -116,9 +117,12 @@ public virtual void Undo(string filePath)
116
117
117
118
if ( File . Exists ( filePath ) )
118
119
{
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 ;
120
123
Project . VBComponents . RemoveSafely ( component ) ;
121
124
Project . VBComponents . ImportSourceFile ( filePath ) ;
125
+ NotifyVBAChanges = true ;
122
126
}
123
127
}
124
128
@@ -142,11 +146,52 @@ protected string GetProjectNameFromDirectory(string directory)
142
146
. LastOrDefault ( c => c != "git" ) ;
143
147
}
144
148
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
+
145
188
private void Refresh ( )
146
189
{
147
190
//Because refreshing removes all components, we need to store the current selection,
148
191
// so we can correctly reset it once the files are imported from the repository.
149
192
193
+ NotifyVBAChanges = false ;
194
+
150
195
var codePane = Project . VBE . ActiveCodePane ;
151
196
152
197
if ( codePane != null )
@@ -170,6 +215,8 @@ private void Refresh()
170
215
Project . RemoveAllComponents ( ) ;
171
216
Project . ImportSourceFiles ( CurrentRepository . LocalLocation ) ;
172
217
}
218
+
219
+ NotifyVBAChanges = true ;
173
220
}
174
221
}
175
222
}
0 commit comments