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,20 @@ 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
+ this . NewName = string . IsNullOrEmpty ( newName ) ? GetNewName ( Path . GetFileName ( path ) ) : newName ;
101
+ if ( string . IsNullOrEmpty ( this . NewName ) ) return ;
102
+ renamePackage = new Move ( new Dictionary < string , string > { { path , this . NewName } } , true , true ) ;
108
103
return ;
109
104
}
110
105
}
111
106
}
112
107
return ;
113
108
}
114
109
115
- this . newName = ! string . IsNullOrEmpty ( newName ) ? newName : GetNewName ( RefactoringHelper . GetRefactorTargetName ( target ) ) ;
110
+ TargetName = RefactoringHelper . GetRefactorTargetName ( target ) ;
111
+ this . NewName = ! string . IsNullOrEmpty ( newName ) ? newName : GetNewName ( TargetName ) ;
116
112
117
- if ( string . IsNullOrEmpty ( this . newName ) ) return ;
113
+ if ( string . IsNullOrEmpty ( this . NewName ) ) return ;
118
114
119
115
// create a FindAllReferences refactor to get all the changes we need to make
120
116
// we'll also let it output the results, at least until we implement a way of outputting the renamed results later
@@ -159,7 +155,7 @@ protected override void ExecutionImplementation()
159
155
/// </summary>
160
156
public override Boolean IsValid ( )
161
157
{
162
- return renamePackage != null ? renamePackage . IsValid ( ) : ! string . IsNullOrEmpty ( this . newName ) ;
158
+ return renamePackage != null ? renamePackage . IsValid ( ) : ! string . IsNullOrEmpty ( this . NewName ) ;
163
159
}
164
160
165
161
#endregion
@@ -191,19 +187,8 @@ private bool ValidateTargets()
191
187
if ( ! isEnum && ! isClass && ! isGlobalFunction && ! isGlobalNamespace )
192
188
return true ;
193
189
194
- FileModel inFile ;
195
- String originName ;
196
-
197
- if ( isEnum || isClass )
198
- {
199
- inFile = target . Type . InFile ;
200
- originName = target . Type . Name ;
201
- }
202
- else
203
- {
204
- inFile = target . Member . InFile ;
205
- originName = target . Member . Name ;
206
- }
190
+ var member = isEnum || isClass ? target . Type : target . Member ;
191
+ FileModel inFile = member . InFile ;
207
192
208
193
// Is this possible? should return false? I'm inclined to think so
209
194
if ( inFile == null ) return true ;
@@ -212,7 +197,7 @@ private bool ValidateTargets()
212
197
String oldName = Path . GetFileNameWithoutExtension ( oldFileName ) ;
213
198
214
199
// Private classes and similars
215
- if ( string . IsNullOrEmpty ( oldName ) || ! oldName . Equals ( originName ) )
200
+ if ( string . IsNullOrEmpty ( oldName ) || ! oldName . Equals ( member . Name ) )
216
201
return true ;
217
202
218
203
String fullPath = Path . GetFullPath ( inFile . FileName ) ;
@@ -242,7 +227,7 @@ private void OnFindAllReferencesCompleted(Object sender, RefactorCompleteEventAr
242
227
var doc = AssociatedDocumentHelper . LoadDocument ( entry . Key ) ;
243
228
var sci = doc . SciControl ;
244
229
// replace matches in the current file with the new name
245
- RefactoringHelper . ReplaceMatches ( entry . Value , sci , this . newName ) ;
230
+ RefactoringHelper . ReplaceMatches ( entry . Value , sci , this . NewName ) ;
246
231
//Uncomment if we want to keep modified files
247
232
//if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(entry.Key);
248
233
doc . Save ( ) ;
@@ -289,7 +274,6 @@ private void RenameFile(IDictionary<string, List<SearchMatch>> results)
289
274
project . SetDocumentClass ( newFileName , true ) ;
290
275
project . Save ( ) ;
291
276
}
292
-
293
277
}
294
278
295
279
if ( results . ContainsKey ( oldFileName ) )
@@ -302,7 +286,7 @@ private void RenameFile(IDictionary<string, List<SearchMatch>> results)
302
286
}
303
287
304
288
/// <summary>
305
- ///
289
+ /// Outputs the results to the TraceManager
306
290
/// </summary>
307
291
private void ReportResults ( )
308
292
{
0 commit comments