5
5
using ASCompletion . Completion ;
6
6
using ASCompletion . Context ;
7
7
using ASCompletion . Model ;
8
- using CodeRefactor . Controls ;
9
8
using CodeRefactor . Provider ;
10
9
using PluginCore ;
11
10
using PluginCore . Controls ;
@@ -23,18 +22,14 @@ namespace CodeRefactor.Commands
23
22
/// </summary>
24
23
public class Rename : RefactorCommand < IDictionary < String , List < SearchMatch > > >
25
24
{
26
- private String newName ;
27
25
private Boolean outputResults ;
28
26
private FindAllReferences findAllReferencesCommand ;
29
27
private Move renamePackage ;
30
-
31
28
private String oldFileName ;
32
29
private String newFileName ;
33
30
34
- public String NewName
35
- {
36
- get { return this . newName ; }
37
- }
31
+ public string TargetName { get ; }
32
+ public string NewName { get ; }
38
33
39
34
/// <summary>
40
35
/// A new Rename refactoring command.
@@ -102,19 +97,21 @@ public Rename(ASResult target, Boolean outputResults, String newName, Boolean ig
102
97
string path = Path . Combine ( aPath . Path , package ) ;
103
98
if ( aPath . IsValid && Directory . Exists ( path ) )
104
99
{
105
- this . newName = string . IsNullOrEmpty ( newName ) ? GetNewName ( Path . GetFileName ( path ) ) : newName ;
106
- if ( string . IsNullOrEmpty ( this . newName ) ) return ;
107
- renamePackage = new Move ( new Dictionary < string , string > { { path , this . newName } } , true , true ) ;
100
+ TargetName = Path . GetFileName ( path ) ;
101
+ this . NewName = string . IsNullOrEmpty ( newName ) ? GetNewName ( TargetName ) : newName ;
102
+ if ( string . IsNullOrEmpty ( this . NewName ) ) return ;
103
+ renamePackage = new Move ( new Dictionary < string , string > { { path , this . NewName } } , true , true ) ;
108
104
return ;
109
105
}
110
106
}
111
107
}
112
108
return ;
113
109
}
114
110
115
- this . newName = ! string . IsNullOrEmpty ( newName ) ? newName : GetNewName ( RefactoringHelper . GetRefactorTargetName ( target ) ) ;
111
+ TargetName = RefactoringHelper . GetRefactorTargetName ( target ) ;
112
+ this . NewName = ! string . IsNullOrEmpty ( newName ) ? newName : GetNewName ( TargetName ) ;
116
113
117
- if ( string . IsNullOrEmpty ( this . newName ) ) return ;
114
+ if ( string . IsNullOrEmpty ( this . NewName ) ) return ;
118
115
119
116
// create a FindAllReferences refactor to get all the changes we need to make
120
117
// we'll also let it output the results, at least until we implement a way of outputting the renamed results later
@@ -133,7 +130,7 @@ protected override void ExecutionImplementation()
133
130
if ( renamePackage != null )
134
131
{
135
132
renamePackage . RegisterDocumentHelper ( AssociatedDocumentHelper ) ;
136
- renamePackage . OnRefactorComplete += ( o , args ) => FireOnRefactorComplete ( ) ;
133
+ renamePackage . OnRefactorComplete += OnRenamePackageComplete ;
137
134
renamePackage . Execute ( ) ;
138
135
}
139
136
else
@@ -160,13 +157,19 @@ protected override void ExecutionImplementation()
160
157
/// </summary>
161
158
public override Boolean IsValid ( )
162
159
{
163
- return renamePackage != null ? renamePackage . IsValid ( ) : ! string . IsNullOrEmpty ( this . newName ) ;
160
+ return renamePackage != null ? renamePackage . IsValid ( ) : ! string . IsNullOrEmpty ( this . NewName ) ;
164
161
}
165
162
166
163
#endregion
167
164
168
165
#region Private Helper Methods
169
166
167
+ void OnRenamePackageComplete ( object sender , RefactorCompleteEventArgs < IDictionary < string , List < SearchMatch > > > args )
168
+ {
169
+ Results = args . Results ;
170
+ FireOnRefactorComplete ( ) ;
171
+ }
172
+
170
173
private bool ValidateTargets ( )
171
174
{
172
175
ASResult target = findAllReferencesCommand . CurrentTarget ;
@@ -192,19 +195,8 @@ private bool ValidateTargets()
192
195
if ( ! isEnum && ! isClass && ! isGlobalFunction && ! isGlobalNamespace )
193
196
return true ;
194
197
195
- FileModel inFile ;
196
- String originName ;
197
-
198
- if ( isEnum || isClass )
199
- {
200
- inFile = target . Type . InFile ;
201
- originName = target . Type . Name ;
202
- }
203
- else
204
- {
205
- inFile = target . Member . InFile ;
206
- originName = target . Member . Name ;
207
- }
198
+ var member = isEnum || isClass ? target . Type : target . Member ;
199
+ FileModel inFile = member . InFile ;
208
200
209
201
// Is this possible? should return false? I'm inclined to think so
210
202
if ( inFile == null ) return true ;
@@ -213,7 +205,7 @@ private bool ValidateTargets()
213
205
String oldName = Path . GetFileNameWithoutExtension ( oldFileName ) ;
214
206
215
207
// Private classes and similars
216
- if ( string . IsNullOrEmpty ( oldName ) || ! oldName . Equals ( originName ) )
208
+ if ( string . IsNullOrEmpty ( oldName ) || ! oldName . Equals ( member . Name ) )
217
209
return true ;
218
210
219
211
String fullPath = Path . GetFullPath ( inFile . FileName ) ;
@@ -243,7 +235,7 @@ private void OnFindAllReferencesCompleted(Object sender, RefactorCompleteEventAr
243
235
var doc = AssociatedDocumentHelper . LoadDocument ( entry . Key ) ;
244
236
var sci = doc . SciControl ;
245
237
// replace matches in the current file with the new name
246
- RefactoringHelper . ReplaceMatches ( entry . Value , sci , this . newName ) ;
238
+ RefactoringHelper . ReplaceMatches ( entry . Value , sci , this . NewName ) ;
247
239
//Uncomment if we want to keep modified files
248
240
//if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(entry.Key);
249
241
doc . Save ( ) ;
@@ -290,7 +282,6 @@ private void RenameFile(IDictionary<string, List<SearchMatch>> results)
290
282
project . SetDocumentClass ( newFileName , true ) ;
291
283
project . Save ( ) ;
292
284
}
293
-
294
285
}
295
286
296
287
if ( results . ContainsKey ( oldFileName ) )
@@ -303,7 +294,7 @@ private void RenameFile(IDictionary<string, List<SearchMatch>> results)
303
294
}
304
295
305
296
/// <summary>
306
- ///
297
+ /// Outputs the results to the TraceManager
307
298
/// </summary>
308
299
private void ReportResults ( )
309
300
{
0 commit comments