summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java
diff options
context:
space:
mode:
authorAndre Weinand <aweinand>2002-09-27 13:51:41 +0000
committerAndre Weinand <aweinand>2002-09-27 13:51:41 +0000
commit7ed1dcc5348017f60834b492c610b6f538174f29 (patch)
tree5aae588e195e6248fed5ab384f93e6331fb5d96b /bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java
parentf3574213a34cbfed877427d4e13e484544aa252e (diff)
downloadeclipse.platform.swt-7ed1dcc5348017f60834b492c610b6f538174f29.tar.gz
eclipse.platform.swt-7ed1dcc5348017f60834b492c610b6f538174f29.tar.xz
eclipse.platform.swt-7ed1dcc5348017f60834b492c610b6f538174f29.zip
fixed #24088
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java102
1 files changed, 59 insertions, 43 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java
index a289f58f20..400b1f04e7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java
@@ -134,20 +134,67 @@ public String [] getFilterExtensions () {
public String [] getFilterNames () {
return filterNames;
}
-
/**
- * Returns the directory path that the dialog will use.
- * File names in this path will appear in the dialog,
- * filtered according to the filter extensions.
+ * Returns the path which the dialog will use to filter
+ * the directories it shows.
*
- * @return the directory path string
- *
- * @see #setFilterExtensions
+ * @return the filter path
*/
public String getFilterPath () {
return filterPath;
}
+private String interpretOsAnswer(int dialog) {
+ String separator = System.getProperty ("file.separator");
+
+ String firstResult= null;
+ int[] tmp= new int[1];
+ OS.NavDialogGetReply(dialog, tmp);
+ int reply= tmp[0];
+
+ int selection= OS.NavReplyRecordGetSelection(reply);
+ OS.AECountItems(selection, tmp);
+ int count= tmp[0];
+
+ String commonPath= null;
+ if (count > 0) {
+ String fileName= null;
+ fileNames= new String[count];
+ for (int i= 0; i < count; i++) {
+ OS.AEGetNthPtr(selection, i+1, tmp);
+ String fullPath= MacUtil.getStringAndRelease(tmp[0]);
+ if (firstResult == null)
+ firstResult= fullPath;
+ if (fullPath != null && fullPath.length() > 0) {
+ int separatorIndex= fullPath.lastIndexOf(separator);
+ if (separatorIndex >= 0) {
+ fileName= fullPath.substring(separatorIndex+separator.length());
+ String fp= fullPath.substring(0, separatorIndex);
+ if (commonPath == null)
+ commonPath= fp; // remember common filterPath
+ else {
+ if (!commonPath.equals(fp)) // verify that filterPath is in fact common
+ System.out.println("FileDialog.getPaths: mismatch in filterPaths");
+ }
+ } else {
+ fileName= fullPath;
+ }
+ fileNames[i]= fileName;
+ }
+ }
+ } else {
+ fileNames= null;
+ }
+
+ if (commonPath != null)
+ filterPath= commonPath;
+ else
+ filterPath= "";
+
+ OS.NavDialogDisposeReply(reply);
+
+ return firstResult;
+}
/**
* Makes the dialog visible and brings it to the front
* of the display.
@@ -217,9 +264,7 @@ public String open () {
case OS.kNavUserActionOpen:
case OS.kNavUserActionChoose:
- fileNames= getPaths(dialog);
- if (fileNames.length > 0)
- result= fileNames[0];
+ result= interpretOsAnswer(dialog);
break;
case OS.kNavUserActionSaveAs:
@@ -273,43 +318,14 @@ public void setFilterExtensions (String [] extensions) {
public void setFilterNames (String [] names) {
filterNames = names;
}
-
/**
- * Sets the directory path that the dialog will use
- * to the argument, which may be null. File names in this
- * path will appear in the dialog, filtered according
- * to the filter extensions.
+ * Sets the path which the dialog will use to filter
+ * the directories it shows to the argument, which may be
+ * null.
*
- * @param string the directory path
- *
- * @see #setFilterExtensions
+ * @param string the filter path
*/
public void setFilterPath (String string) {
filterPath = string;
}
-
-////////////////////
-// Mac stuff
-////////////////////
-
- static String[] getPaths(int dialog) {
- int[] tmp= new int[1];
- OS.NavDialogGetReply(dialog, tmp);
- int reply= tmp[0];
-
- int selection= OS.NavReplyRecordGetSelection(reply);
- OS.AECountItems(selection, tmp);
- int count= tmp[0];
-
- String[] result= new String[count];
- for (int i= 0; i < count; i++) {
- OS.AEGetNthPtr(selection, i+1, tmp);
- result[i]= MacUtil.getStringAndRelease(tmp[0]);
- }
-
- OS.NavDialogDisposeReply(reply);
-
- return result;
- }
-
}