Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java

Issue 9834028: Initial implementation of "Rename Local Variable" refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: LInked/inline mode for rename Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java
index de4c0d033418334a9ac9f26e31c75ad021ec12e5..7a34ca8168f6198aedee4543ad26241ebe1cbca0 100644
--- a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java
+++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java
@@ -1,7 +1,6 @@
package com.google.dart.tools.ui.internal.refactoring;
import com.google.dart.tools.ui.DartToolsPlugin;
-import com.google.dart.tools.ui.PreferenceConstants;
import com.google.dart.tools.ui.internal.text.editor.EditorUtility;
import com.google.dart.tools.ui.internal.util.CoreUtility;
import com.google.dart.tools.ui.internal.util.ExceptionHandler;
@@ -10,47 +9,19 @@ import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.GlobalBuildAction;
-import org.eclipse.ui.dialogs.ListDialog;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.Arrays;
/**
* Helper to save dirty editors prior to starting a refactoring.
- *
- * @see PreferenceConstants#REFACTOR_SAVE_ALL_EDITORS
- *
- * @noextend This class is not intended to be subclassed by clients.
*/
public class RefactoringSaveHelper {
- private boolean fFilesSaved;
+ private boolean filesSaved;
private final int fSaveMode;
/**
- * Save mode to save all dirty editors (always ask).
- */
- public static final int SAVE_ALL_ALWAYS_ASK = 1;
-
- /**
* Save mode to save all dirty editors.
*/
public static final int SAVE_ALL = 2;
@@ -60,118 +31,40 @@ public class RefactoringSaveHelper {
*/
public static final int SAVE_NOTHING = 3;
- /**
- * Save mode to save all editors that are known to cause trouble for Java refactorings, e.g.
- * editors on compilation units that are not in working copy mode.
- */
- public static final int SAVE_REFACTORING = 4;
-
- /**
- * Creates a refactoring save helper with the given save mode.
- *
- * @param saveMode one of the SAVE_* constants
- */
public RefactoringSaveHelper(int saveMode) {
- Assert.isLegal(saveMode == SAVE_ALL_ALWAYS_ASK
- || saveMode == SAVE_ALL
- || saveMode == SAVE_NOTHING
- || saveMode == SAVE_REFACTORING);
+ Assert.isLegal(saveMode == SAVE_ALL || saveMode == SAVE_NOTHING);
fSaveMode = saveMode;
}
/**
- * Returns whether this save helper did actually save any files.
- *
- * @return <code>true</code> iff files have been saved
- */
- public boolean didSaveFiles() {
- return fFilesSaved;
- }
-
- /**
- * Saves all editors. Depending on the {@link PreferenceConstants#REFACTOR_SAVE_ALL_EDITORS}
- * preference, the user is asked to save affected dirty editors.
+ * Saves all editors.
*
- * @param shell the parent shell for the confirmation dialog
* @return <code>true</code> if save was successful and refactoring can proceed; false if the
* refactoring must be cancelled
*/
public boolean saveEditors(Shell shell) {
- final IEditorPart[] dirtyEditors;
- switch (fSaveMode) {
- case SAVE_ALL_ALWAYS_ASK:
- case SAVE_ALL:
- dirtyEditors = EditorUtility.getDirtyEditors();
- break;
-
- case SAVE_REFACTORING:
- dirtyEditors = EditorUtility.getDirtyEditorsToSave(false);
- break;
-
- case SAVE_NOTHING:
- return true;
-
- default:
- throw new IllegalStateException(Integer.toString(fSaveMode));
+ // May be no save required.
+ if (fSaveMode == SAVE_NOTHING) {
+ return true;
}
+ // Prepare dirty editors.
+ IEditorPart[] dirtyEditors = EditorUtility.getDirtyEditors();
if (dirtyEditors.length == 0) {
return true;
}
- if (!askSaveAllDirtyEditors(shell, dirtyEditors)) {
- return false;
- }
try {
- // Save isn't cancelable.
boolean autoBuild = CoreUtility.setAutoBuilding(false);
try {
- if (fSaveMode == SAVE_ALL_ALWAYS_ASK
- || fSaveMode == SAVE_ALL
- || RefactoringSavePreferences.getSaveAllEditors()) {
- if (!DartToolsPlugin.getActiveWorkbenchWindow().getWorkbench().saveAllEditors(false)) {
- return false;
- }
- } else {
- IRunnableWithProgress runnable = new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor pm) throws InterruptedException {
- int count = dirtyEditors.length;
- pm.beginTask("", count); //$NON-NLS-1$
- for (int i = 0; i < count; i++) {
- IEditorPart editor = dirtyEditors[i];
- editor.doSave(new SubProgressMonitor(pm, 1));
- if (pm.isCanceled()) {
- throw new InterruptedException();
- }
- }
- pm.done();
- }
- };
- try {
- PlatformUI.getWorkbench().getProgressService().runInUI(
- DartToolsPlugin.getActiveWorkbenchWindow(),
- runnable,
- null);
- } catch (InterruptedException e) {
- return false;
- } catch (InvocationTargetException e) {
- ExceptionHandler.handle(
- e,
- shell,
- RefactoringMessages.RefactoringStarter_saving,
- RefactoringMessages.RefactoringStarter_unexpected_exception);
- return false;
- }
+ if (!DartToolsPlugin.getActiveWorkbenchWindow().getWorkbench().saveAllEditors(false)) {
+ return false;
}
- fFilesSaved = true;
+ filesSaved = true;
} finally {
CoreUtility.setAutoBuilding(autoBuild);
}
return true;
} catch (CoreException e) {
- ExceptionHandler.handle(
- e,
- shell,
- RefactoringMessages.RefactoringStarter_saving,
+ ExceptionHandler.handle(e, shell, RefactoringMessages.RefactoringStarter_saving,
RefactoringMessages.RefactoringStarter_unexpected_exception);
return false;
}
@@ -181,59 +74,9 @@ public class RefactoringSaveHelper {
* Triggers an incremental build if this save helper did save files before.
*/
public void triggerIncrementalBuild() {
- if (fFilesSaved && ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding()) {
+ if (filesSaved && ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding()) {
new GlobalBuildAction(DartToolsPlugin.getActiveWorkbenchWindow(),
IncrementalProjectBuilder.INCREMENTAL_BUILD).run();
}
}
-
- private boolean askSaveAllDirtyEditors(Shell shell, IEditorPart[] dirtyEditors) {
- final boolean canSaveAutomatically = fSaveMode != SAVE_ALL_ALWAYS_ASK;
- if (canSaveAutomatically && RefactoringSavePreferences.getSaveAllEditors()) {
- return true;
- }
- ListDialog dialog = new ListDialog(shell) {
- {
- setShellStyle(getShellStyle() | SWT.APPLICATION_MODAL);
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite result = (Composite) super.createDialogArea(parent);
- if (canSaveAutomatically) {
- final Button check = new Button(result, SWT.CHECK);
- check.setText(RefactoringMessages.RefactoringStarter_always_save);
- check.setSelection(RefactoringSavePreferences.getSaveAllEditors());
- check.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- RefactoringSavePreferences.setSaveAllEditors(check.getSelection());
- }
- });
- applyDialogFont(result);
- }
- return result;
- }
- };
- dialog.setTitle(RefactoringMessages.RefactoringStarter_save_all_resources);
- dialog.setLabelProvider(createDialogLabelProvider());
- dialog.setMessage(RefactoringMessages.RefactoringStarter_must_save);
- dialog.setContentProvider(new ArrayContentProvider());
- dialog.setInput(Arrays.asList(dirtyEditors));
- return dialog.open() == Window.OK;
- }
-
- private ILabelProvider createDialogLabelProvider() {
- return new LabelProvider() {
- @Override
- public Image getImage(Object element) {
- return ((IEditorPart) element).getTitleImage();
- }
-
- @Override
- public String getText(Object element) {
- return ((IEditorPart) element).getTitle();
- }
- };
- }
}

Powered by Google App Engine
This is Rietveld 408576698