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

improved the confirm dialog for the rename refactoring #353

Merged
merged 1 commit into from
Sep 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# dartlang plugin changelog

## unreleased
- filtered 'potential' edits from rename refactorings
- improved the confirm dialog for the rename refactoring confirmation

## 0.4.6
- improved logging when receiving errors from the analysis server
- changed to displaying 'todo' issues to default to off
Expand Down
61 changes: 49 additions & 12 deletions lib/analysis/refactor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import 'dart:async';

import 'package:logging/logging.dart';

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

RefactoringHelper() {
_commands.add(atom.commands.add('atom-text-editor', 'dartlang:refactor-rename', (e) {
_commands.add(atom.commands.add('atom-text-editor',
'dartlang:refactor-rename', (e) {
_handleRenameRefactor(e.editor);
}));
}
Expand Down Expand Up @@ -90,20 +92,55 @@ class RefactoringHelper implements Disposable {
SourceChange change = result.change;
List<SourceFileEdit> sourceFileEdits = change.edits;

// Remove any 'potential' edits. The analysis server sends over things
// like edits to package: files.
sourceFileEdits.forEach((SourceFileEdit fileEdit) {
fileEdit.edits.removeWhere((SourceEdit edit) => edit.id != null);
});
sourceFileEdits.removeWhere((SourceFileEdit fileEdit) => fileEdit.edits.isEmpty);

// We want to confirm this refactoring with users if it's going to
// rename across files.
var apply = () {
_apply(sourceFileEdits, oldName, newName).then((_) {
// Ensure the original file is selected.
atom.workspace.open(path);
});
};

if (sourceFileEdits.length > 1) {
String fileSummary = sourceFileEdits.map((edit) => edit.file).join('\n');
var val = atom.confirm('Confirm rename in ${sourceFileEdits.length} files?',
detailedMessage: fileSummary,
buttons: ['Rename', 'Cancel']);
if (val != 0) return;
var project = projectManager.getProjectFor(path);
String projectPrefix = project == null ? '' : project.path;

Iterable<String> paths = sourceFileEdits.map((edit) {
String filePath = edit.file;
if (filePath.startsWith(projectPrefix)) {
return project.name + filePath.substring(projectPrefix.length);
} else {
return filePath;
}
});
String fileSummary = (paths.toList()..sort()).join('\n');
Notification notification;

var userConfirmed = () {
notification.dismiss();
apply();
};

var userCancelled = () => notification.dismiss();

notification = atom.notifications.addInfo(
'Confirm rename in ${sourceFileEdits.length} files?',
detail: fileSummary,
dismissable: true,
buttons: [
new NotificationButton('Rename', userConfirmed),
new NotificationButton('Cancel', userCancelled)
]);
} else {
apply();
}

_apply(sourceFileEdits, oldName, newName).then((_) {
// Ensure the original file is selected.
atom.workspace.open(path);
});
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions lib/projects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ class DartProject {

String get path => directory.path;

String get name => directory.getBaseName();

int get hashCode => directory.hashCode;

bool contains(String path) => directory.contains(path);
Expand Down
344 changes: 234 additions & 110 deletions web/entry.dart.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions web/entry.dart.js.map

Large diffs are not rendered by default.