Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Keller2012-10-05 14:11:44 +0000
committerMarkus Keller2012-10-05 14:11:44 +0000
commit557ba618fc1d1f0161c453067e6b17fd848148b9 (patch)
tree47b3cd3e38a14a7138085acbe51999819a99e2f5
parentcf5628f6e8c70f01b2ddfa4de81ffbcc816e54d7 (diff)
downloadeclipse.platform.text-557ba618fc1d1f0161c453067e6b17fd848148b9.tar.gz
eclipse.platform.text-557ba618fc1d1f0161c453067e6b17fd848148b9.tar.xz
eclipse.platform.text-557ba618fc1d1f0161c453067e6b17fd848148b9.zip
Bug 321306: Convert line delimiters should report ignored binary filesv20121005-141144I20121009-0800
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileBufferOperationAction.java9
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/ConvertLineDelimitersAction.java67
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/SelectResourcesBlock.java30
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/SelectResourcesDialog.java17
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java4
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties4
6 files changed, 107 insertions, 24 deletions
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileBufferOperationAction.java b/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileBufferOperationAction.java
index afc28fe89..59b7e96d3 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileBufferOperationAction.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileBufferOperationAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -154,6 +154,13 @@ public class FileBufferOperationAction extends Action implements IWorkbenchWindo
doRun(null, fLocation, fFileBufferOperation);
}
+ /**
+ * Collect the files to process. This method may show a dialog to ask the user.
+ * Subclasses may extend or reimplement.
+ *
+ * @param resources selected resources
+ * @return the files to process, can be <code>null</code>
+ */
protected IFile[] collectFiles(IResource[] resources) {
Set files= new HashSet();
for (int i= 0; i < resources.length; i++) {
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/ConvertLineDelimitersAction.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/ConvertLineDelimitersAction.java
index a4d37ebe0..5dd535b02 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/ConvertLineDelimitersAction.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/ConvertLineDelimitersAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,6 +13,13 @@ package org.eclipse.ui.internal.editors.text;
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.resources.IFile;
@@ -24,6 +31,9 @@ import org.eclipse.core.filebuffers.manipulation.ConvertLineDelimitersOperation;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.Window;
@@ -57,9 +67,6 @@ public class ConvertLineDelimitersAction extends FileBufferOperationAction {
return label;
}
- /*
- * @see org.eclipse.ui.internal.editors.text.FileBufferOperationAction#isAcceptableLocation(org.eclipse.core.runtime.IPath)
- */
protected boolean isAcceptableLocation(IPath location) {
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
return location != null && manager.isTextFileLocation(location, fStrictCheckIfTextLocation);
@@ -70,15 +77,12 @@ public class ConvertLineDelimitersAction extends FileBufferOperationAction {
fStrictCheckIfTextLocation= !(selection instanceof ITextSelection);
}
- /*
- * @see org.eclipse.ui.internal.editors.text.FileBufferOperationAction#collectFiles(org.eclipse.core.resources.IResource[])
- */
protected IFile[] collectFiles(final IResource[] resources) {
fStrictCheckIfTextLocation= fStrictCheckIfTextLocation || resources.length != 1 || resources[0].getType() != IResource.FILE;
- IFile[] files= super.collectFiles(resources);
- files= filterUnacceptableFiles(files);
- if (containsOnlyFiles(resources))
- return files;
+ if (containsOnlyFiles(resources)) {
+ IFile[] files= super.collectFiles(resources);
+ return filterUnacceptableFiles(files);
+ }
final IFilter filter= new IFilter() {
public boolean accept(IResource resource) {
@@ -86,7 +90,25 @@ public class ConvertLineDelimitersAction extends FileBufferOperationAction {
}
};
- SelectResourcesDialog dialog= new SelectResourcesDialog(getShell(), NLSUtility.format(TextEditorMessages.ConvertLineDelimitersAction_dialog_title, fLabel), TextEditorMessages.ConvertLineDelimitersAction_dialog_description, filter);
+ SelectResourcesDialog dialog= new SelectResourcesDialog(getShell(), getDialogTitle(), TextEditorMessages.ConvertLineDelimitersAction_dialog_description, filter) {
+ protected Composite createSelectionButtonGroup(Composite parent) {
+ Composite buttonGroup= super.createSelectionButtonGroup(parent);
+
+ final Button button = new Button(buttonGroup, SWT.CHECK);
+ ((GridLayout) buttonGroup.getLayout()).numColumns++;
+ button.setText(TextEditorMessages.ConvertLineDelimitersAction_show_only_text_files);
+ button.setFont(JFaceResources.getDialogFont());
+ button.setSelection(fStrictCheckIfTextLocation);
+ button.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ fStrictCheckIfTextLocation= button.getSelection();
+ refresh();
+ }
+ });
+
+ return buttonGroup;
+ }
+ };
dialog.setInput(resources);
int result= dialog.open();
if (Window.OK == result) {
@@ -95,6 +117,10 @@ public class ConvertLineDelimitersAction extends FileBufferOperationAction {
}
return null;
}
+
+ private String getDialogTitle() {
+ return NLSUtility.format(TextEditorMessages.ConvertLineDelimitersAction_dialog_title, fLabel);
+ }
/**
* Checks whether the given resources array contains
@@ -121,11 +147,26 @@ public class ConvertLineDelimitersAction extends FileBufferOperationAction {
* @since 3.2
*/
private IFile[] filterUnacceptableFiles(IFile[] files) {
+ boolean askForBinary= true;
Set filtered= new HashSet();
for (int i= 0; i < files.length; i++) {
IFile file= files[i];
- if (isAcceptableLocation(file.getFullPath()))
+ if (isAcceptableLocation(file.getFullPath())) {
filtered.add(file);
+ } else if (askForBinary) {
+ int result= new MessageDialog(getShell(), getDialogTitle(), null,
+ TextEditorMessages.ConvertLineDelimitersAction_nontext_selection,
+ MessageDialog.WARNING,
+ new String[] { TextEditorMessages.ConvertLineDelimitersAction_convert_all , TextEditorMessages.ConvertLineDelimitersAction_convert_text, IDialogConstants.CANCEL_LABEL}, 1).open();
+ if (result == 0) {
+ fStrictCheckIfTextLocation= false;
+ filtered.add(file);
+ } else if (result == 1) {
+ askForBinary= false;
+ } else {
+ return null;
+ }
+ }
}
return (IFile[]) filtered.toArray(new IFile[filtered.size()]);
}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/SelectResourcesBlock.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/SelectResourcesBlock.java
index f95593291..2d9a01544 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/SelectResourcesBlock.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/SelectResourcesBlock.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -21,14 +21,17 @@ import java.util.Set;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
@@ -208,6 +211,7 @@ class SelectResourcesBlock implements ICheckStateListener, ISelectionChangedList
GridData data= new GridData(GridData.FILL_BOTH);
if (useHeightHint)
data.heightHint= PREFERRED_HEIGHT;
+ data.widthHint= getViewerWidthHint(parent);
listViewer.getTable().setLayoutData(data);
listViewer.getTable().setFont(parent.getFont());
listViewer.setContentProvider(listContentProvider);
@@ -226,6 +230,7 @@ class SelectResourcesBlock implements ICheckStateListener, ISelectionChangedList
GridData data= new GridData(GridData.FILL_BOTH);
if (useHeightHint)
data.heightHint= PREFERRED_HEIGHT;
+ data.widthHint= getViewerWidthHint(parent);
tree.setLayoutData(data);
tree.setFont(parent.getFont());
@@ -238,6 +243,13 @@ class SelectResourcesBlock implements ICheckStateListener, ISelectionChangedList
treeViewer.addSelectionChangedListener(this);
}
+ private int getViewerWidthHint(Control control) {
+ GC gc= new GC(control);
+ int width= Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 50);
+ gc.dispose();
+ return width;
+ }
+
/**
* Returns a boolean indicating whether the passed tree element should be at
* LEAST gray-checked. Note that this method does not consider whether it
@@ -493,7 +505,9 @@ class SelectResourcesBlock implements ICheckStateListener, ISelectionChangedList
treeViewer.setInput(root);
this.expandedTreeNodes= new ArrayList();
this.expandedTreeNodes.add(root);
-
+ Object[] topElements= treeContentProvider.getElements(root);
+ if (topElements.length == 1)
+ treeViewer.setExpandedState(topElements[0], true);
}
/**
@@ -631,7 +645,7 @@ class SelectResourcesBlock implements ICheckStateListener, ISelectionChangedList
Object selectedElement= selection.getFirstElement();
if (selectedElement == null) {
currentTreeSelection= null;
- listViewer.setInput(currentTreeSelection);
+ listViewer.setInput(null);
return;
}
@@ -664,6 +678,16 @@ class SelectResourcesBlock implements ICheckStateListener, ISelectionChangedList
}
});
}
+
+ public void refresh() {
+ //Potentially long operation - show a busy cursor
+ BusyIndicator.showWhile(treeViewer.getControl().getDisplay(), new Runnable() {
+ public void run() {
+ treeViewer.refresh();
+ populateListViewer(currentTreeSelection);
+ }
+ });
+ }
/**
* The treeElement has been white selected. Get the list for the element and
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/SelectResourcesDialog.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/SelectResourcesDialog.java
index c30bd3900..897ffeb0f 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/SelectResourcesDialog.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/SelectResourcesDialog.java
@@ -25,7 +25,6 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -41,6 +40,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -89,6 +89,11 @@ class SelectResourcesDialog extends Dialog {
fInput= input;
}
+ public void refresh() {
+ fResourceGroup.refresh();
+ setSelection(fInput, fAcceptableLocationsFilter);
+ }
+
public IResource[] getSelectedResources() {
List items= fResourceGroup.getAllCheckedListItems();
return (IResource[]) items.toArray(new IResource[items.size()]);
@@ -177,7 +182,7 @@ class SelectResourcesDialog extends Dialog {
};
}
- protected final void createSelectionButtonGroup(Composite parent) {
+ protected Composite createSelectionButtonGroup(Composite parent) {
Font font= parent.getFont();
@@ -185,11 +190,7 @@ class SelectResourcesDialog extends Dialog {
Composite buttonComposite= new Composite(parent, SWT.NONE);
buttonComposite.setFont(parent.getFont());
- GridLayout layout= new GridLayout();
- layout.numColumns= 3;
- layout.makeColumnsEqualWidth= true;
- buttonComposite.setLayout(layout);
- buttonComposite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
+ buttonComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(0).equalWidth(true).create());
Button selectButton= createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, TextEditorMessages.SelectResourcesDialog_selectAll, false);
@@ -226,6 +227,8 @@ class SelectResourcesDialog extends Dialog {
selectTypesButton.addSelectionListener(listener);
selectTypesButton.setFont(font);
setButtonLayoutData(selectTypesButton);
+
+ return buttonComposite;
}
protected void handleSelectFileTypes() {
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java
index 5db0fe15d..dcbf8c8cd 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java
@@ -93,11 +93,15 @@ final class TextEditorMessages extends NLS {
public static String SelectResourcesDialog_noFilesSelected;
public static String SelectResourcesDialog_oneFileSelected;
public static String SelectResourcesDialog_nFilesSelected;
+ public static String ConvertLineDelimitersAction_convert_all;
+ public static String ConvertLineDelimitersAction_convert_text;
public static String ConvertLineDelimitersAction_default_label;
public static String ConvertLineDelimitersAction_dialog_title;
public static String ConvertLineDelimitersToWindows_label;
public static String ConvertLineDelimitersToUnix_label;
public static String ConvertLineDelimitersAction_dialog_description;
+ public static String ConvertLineDelimitersAction_nontext_selection;
+ public static String ConvertLineDelimitersAction_show_only_text_files;
public static String RemoveTrailingWhitespaceHandler_dialog_title;
public static String RemoveTrailingWhitespaceHandler_dialog_description;
public static String HyperlinksEnabled_label;
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
index fe80a68fc..96813a10e 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
@@ -121,11 +121,15 @@ SelectResourcesDialog_noFilesSelected= No file selected.
SelectResourcesDialog_oneFileSelected= 1 file selected.
SelectResourcesDialog_nFilesSelected= {0} files selected.
+ConvertLineDelimitersAction_convert_all=Convert &All
+ConvertLineDelimitersAction_convert_text=Convert &Text Files
ConvertLineDelimitersAction_default_label=\ [default]
ConvertLineDelimitersAction_dialog_title=Convert Line Delimiters to {0}
ConvertLineDelimitersToWindows_label=&Windows (CRLF, \\r\\n, 0D0A, \u00A4\u00B6)
ConvertLineDelimitersToUnix_label=&Unix (LF, \\n, 0A, \u00B6)
ConvertLineDelimitersAction_dialog_description=Select files to convert:
+ConvertLineDelimitersAction_nontext_selection=The selection contains files that could have binary content. Do you want to convert all files or only text files?
+ConvertLineDelimitersAction_show_only_text_files=Show only &text files
RemoveTrailingWhitespaceHandler_dialog_title=Remove Trailing Whitespace
RemoveTrailingWhitespaceHandler_dialog_description=Select files:

Back to the top