@@ -5,7 +5,8 @@ import 'dart:async';
5
5
6
6
import 'package:logging/logging.dart' ;
7
7
8
- import '../analysis/analysis_server_lib.dart' show SourceChange, SourceFileEdit;
8
+ import '../analysis/analysis_server_lib.dart'
9
+ show SourceChange, SourceEdit, SourceFileEdit;
9
10
import '../analysis_server.dart' ;
10
11
import '../atom.dart' ;
11
12
import '../atom_utils.dart' ;
@@ -19,7 +20,8 @@ class RefactoringHelper implements Disposable {
19
20
Disposables _commands = new Disposables ();
20
21
21
22
RefactoringHelper () {
22
- _commands.add (atom.commands.add ('atom-text-editor' , 'dartlang:refactor-rename' , (e) {
23
+ _commands.add (atom.commands.add ('atom-text-editor' ,
24
+ 'dartlang:refactor-rename' , (e) {
23
25
_handleRenameRefactor (e.editor);
24
26
}));
25
27
}
@@ -90,20 +92,55 @@ class RefactoringHelper implements Disposable {
90
92
SourceChange change = result.change;
91
93
List <SourceFileEdit > sourceFileEdits = change.edits;
92
94
95
+ // Remove any 'potential' edits. The analysis server sends over things
96
+ // like edits to package: files.
97
+ sourceFileEdits.forEach ((SourceFileEdit fileEdit) {
98
+ fileEdit.edits.removeWhere ((SourceEdit edit) => edit.id != null );
99
+ });
100
+ sourceFileEdits.removeWhere ((SourceFileEdit fileEdit) => fileEdit.edits.isEmpty);
101
+
93
102
// We want to confirm this refactoring with users if it's going to
94
103
// rename across files.
104
+ var apply = () {
105
+ _apply (sourceFileEdits, oldName, newName).then ((_) {
106
+ // Ensure the original file is selected.
107
+ atom.workspace.open (path);
108
+ });
109
+ };
110
+
95
111
if (sourceFileEdits.length > 1 ) {
96
- String fileSummary = sourceFileEdits.map ((edit) => edit.file).join ('\n ' );
97
- var val = atom.confirm ('Confirm rename in ${sourceFileEdits .length } files?' ,
98
- detailedMessage: fileSummary,
99
- buttons: ['Rename' , 'Cancel' ]);
100
- if (val != 0 ) return ;
112
+ var project = projectManager.getProjectFor (path);
113
+ String projectPrefix = project == null ? '' : project.path;
114
+
115
+ Iterable <String > paths = sourceFileEdits.map ((edit) {
116
+ String filePath = edit.file;
117
+ if (filePath.startsWith (projectPrefix)) {
118
+ return project.name + filePath.substring (projectPrefix.length);
119
+ } else {
120
+ return filePath;
121
+ }
122
+ });
123
+ String fileSummary = (paths.toList ()..sort ()).join ('\n ' );
124
+ Notification notification;
125
+
126
+ var userConfirmed = () {
127
+ notification.dismiss ();
128
+ apply ();
129
+ };
130
+
131
+ var userCancelled = () => notification.dismiss ();
132
+
133
+ notification = atom.notifications.addInfo (
134
+ 'Confirm rename in ${sourceFileEdits .length } files?' ,
135
+ detail: fileSummary,
136
+ dismissable: true ,
137
+ buttons: [
138
+ new NotificationButton ('Rename' , userConfirmed),
139
+ new NotificationButton ('Cancel' , userCancelled)
140
+ ]);
141
+ } else {
142
+ apply ();
101
143
}
102
-
103
- _apply (sourceFileEdits, oldName, newName).then ((_) {
104
- // Ensure the original file is selected.
105
- atom.workspace.open (path);
106
- });
107
144
}
108
145
}
109
146
});
0 commit comments