Skip to content
This repository was archived by the owner on Mar 16, 2020. It is now read-only.

Commit 2255cb7

Browse files
committed
Merge pull request #353 from dart-atom/ddc_rename_confirm
improved the confirm dialog for the rename refactoring
2 parents 3b203e6 + 42c35e6 commit 2255cb7

File tree

5 files changed

+291
-124
lines changed

5 files changed

+291
-124
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# dartlang plugin changelog
22

3+
## unreleased
4+
- filtered 'potential' edits from rename refactorings
5+
- improved the confirm dialog for the rename refactoring confirmation
6+
37
## 0.4.6
48
- improved logging when receiving errors from the analysis server
59
- changed to displaying 'todo' issues to default to off

lib/analysis/refactor.dart

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import 'dart:async';
55

66
import 'package:logging/logging.dart';
77

8-
import '../analysis/analysis_server_lib.dart' show SourceChange, SourceFileEdit;
8+
import '../analysis/analysis_server_lib.dart'
9+
show SourceChange, SourceEdit, SourceFileEdit;
910
import '../analysis_server.dart';
1011
import '../atom.dart';
1112
import '../atom_utils.dart';
@@ -19,7 +20,8 @@ class RefactoringHelper implements Disposable {
1920
Disposables _commands = new Disposables();
2021

2122
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) {
2325
_handleRenameRefactor(e.editor);
2426
}));
2527
}
@@ -90,20 +92,55 @@ class RefactoringHelper implements Disposable {
9092
SourceChange change = result.change;
9193
List<SourceFileEdit> sourceFileEdits = change.edits;
9294

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+
93102
// We want to confirm this refactoring with users if it's going to
94103
// 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+
95111
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();
101143
}
102-
103-
_apply(sourceFileEdits, oldName, newName).then((_) {
104-
// Ensure the original file is selected.
105-
atom.workspace.open(path);
106-
});
107144
}
108145
}
109146
});

lib/projects.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ class DartProject {
236236

237237
String get path => directory.path;
238238

239+
String get name => directory.getBaseName();
240+
239241
int get hashCode => directory.hashCode;
240242

241243
bool contains(String path) => directory.contains(path);

web/entry.dart.js

Lines changed: 234 additions & 110 deletions
Large diffs are not rendered by default.

web/entry.dart.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)