aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSravan Kumar Lakkimsetti2014-01-29 23:51:36 (EST)
committerGerrit Code Review @ Eclipse.org2014-02-21 06:48:43 (EST)
commitb647d62c5bdcee9c1d9104cd6245d80b8fca31e7 (patch)
treee8d18019f3efdee0bff5672cd3095731e83b8a29
parent24fdfd9c26f6e2472ad6e0a091d30c9851d291d5 (diff)
downloadeclipse.platform.swt-b647d62c5bdcee9c1d9104cd6245d80b8fca31e7.zip
eclipse.platform.swt-b647d62c5bdcee9c1d9104cd6245d80b8fca31e7.tar.gz
eclipse.platform.swt-b647d62c5bdcee9c1d9104cd6245d80b8fca31e7.tar.bz2
Bug 332178 - FileDialog overwrites file without prompt.refs/changes/06/21306/10
Change-Id: I2265c59fb67619c6c5f4d69649a01ab1327879d6 Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java65
1 files changed, 49 insertions, 16 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java
index a4f4c39..38de0c0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 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
@@ -199,20 +199,6 @@ String computeResultChooserDialog () {
int separatorIndex = fullPath.lastIndexOf (SEPARATOR);
fileName = fullPath.substring (separatorIndex + 1);
filterPath = fullPath.substring (0, separatorIndex);
- int fileExtensionIndex = fileName.indexOf(FILE_EXTENSION_SEPARATOR);
- if ((style & SWT.SAVE) != 0 && fileExtensionIndex == -1 && filterIndex != -1) {
- if (filterExtensions.length > filterIndex) {
- String selection = filterExtensions [filterIndex];
- int length = selection.length ();
- int index = selection.indexOf (EXTENSION_SEPARATOR);
- if (index == -1) index = length;
- String extension = selection.substring (0, index).trim ();
- if (!extension.equals ("*") && !extension.equals ("*.*")) {
- if (extension.startsWith ("*.")) extension = extension.substring (1);
- fullPath = fullPath + extension;
- }
- }
- }
}
return fullPath;
}
@@ -379,6 +365,9 @@ void presetChooserDialog () {
if (filterPath == null) filterPath = "";
if (fileName == null) fileName = "";
if ((style & SWT.SAVE) != 0) {
+ if (fileName.equals ("")) {
+ fileName = "Untitled";
+ }
if (filterPath.length () > 0) {
if (uriMode) {
byte [] buffer = Converter.wcsToMbcs (null, filterPath, true);
@@ -390,7 +379,32 @@ void presetChooserDialog () {
}
}
if (fileName.length () > 0) {
- byte [] buffer = Converter.wcsToMbcs (null, fileName, true);
+ StringBuffer filenameWithExt = new StringBuffer();
+ filenameWithExt.append (fileName);
+ if ((fileName.lastIndexOf (FILE_EXTENSION_SEPARATOR) == -1) &&
+ (filterExtensions.length != 0)) { // Filename doesn't contain the extension and user has provided filter extensions
+ String selectedFilter = null;
+ if (this.filterIndex == -1) {
+ selectedFilter = filterExtensions[0];
+ } else {
+ selectedFilter = filterExtensions[filterIndex];
+ }
+ String extFilter = null;
+ int index = selectedFilter.indexOf (EXTENSION_SEPARATOR);
+ if (index == -1) {
+ extFilter = selectedFilter.trim ();
+ } else {
+ extFilter = selectedFilter.substring (0, index).trim ();
+ }
+
+ int separatorIndex = extFilter.lastIndexOf (FILE_EXTENSION_SEPARATOR);
+ String extension = extFilter.substring (separatorIndex);
+
+ if (!isGlobPattern (extension)) { //if the extension is of type glob pattern we should not add the extension
+ filenameWithExt.append (extension);
+ }
+ }
+ byte [] buffer = Converter.wcsToMbcs (null, filenameWithExt.toString (), true);
OS.gtk_file_chooser_set_current_name (handle, buffer);
}
} else {
@@ -462,6 +476,25 @@ void presetChooserDialog () {
fileNames = new String [0];
}
/**
+ * Check whether the file extension is a glob pattern.
+ * For example, *.* is a glob pattern which corresponds to all files
+ * *.jp* corresponds to all the files with extension starting with jp like jpg,jpeg etc
+ * *.jp? corresponds to 3 letter extension starting with jp with any 3rd letter
+ * *.[pq]ng this corresponds to *.png and *.qng
+ *
+ * @param extension file extension as a string
+ *
+ * @returns true if the extension contains any of the glob pattern wildcards
+ */
+private boolean isGlobPattern (String extension) {
+ if (extension.contains ("*") ||
+ extension.contains ("?") ||
+ (extension.contains ("[") && extension.contains ("]"))) {
+ return true;
+ }
+ return false;
+}
+/**
* Set the initial filename which the dialog will
* select by default when opened to the argument,
* which may be null. The name will be prefixed with