diff options
author | Andre Weinand <aweinand> | 2002-09-27 13:51:41 +0000 |
---|---|---|
committer | Andre Weinand <aweinand> | 2002-09-27 13:51:41 +0000 |
commit | 7ed1dcc5348017f60834b492c610b6f538174f29 (patch) | |
tree | 5aae588e195e6248fed5ab384f93e6331fb5d96b /bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse | |
parent | f3574213a34cbfed877427d4e13e484544aa252e (diff) | |
download | eclipse.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')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java | 47 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java | 102 |
2 files changed, 87 insertions, 62 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java index 32e807c18c..f301b96258 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java @@ -99,6 +99,21 @@ public String getFilterPath () { public String getMessage () { return message; } +private String interpretOsAnswer(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]; + + if (count > 0) { + OS.AEGetNthPtr(selection, 1, tmp); + return MacUtil.getStringAndRelease(tmp[0]); + } + return null; +} /** * Makes the dialog visible and brings it to the front * of the display. @@ -112,10 +127,7 @@ public String getMessage () { * </ul> */ public String open () { - int dialog= 0; - String result= null; - int titleHandle= 0; int messageHandle= 0; try { @@ -142,12 +154,11 @@ public String open () { case OS.kNavUserActionOpen: case OS.kNavUserActionChoose: - String[] directories= FileDialog.getPaths(dialog); - if (directories.length > 0) - result= directories[0]; - break; + return interpretOsAnswer(dialog); } } + + return null; } finally { if (titleHandle != 0) @@ -157,18 +168,6 @@ public String open () { if (dialog != 0) OS.NavDialogDispose(dialog); } - - return result; -} -/** - * Sets the path which the dialog will use to filter - * the directories it shows to the argument, which may be - * null. - * - * @param string the filter path - */ -public void setFilterPath (String string) { - filterPath = string; } /** * Sets the dialog's message, which is a description of @@ -180,4 +179,14 @@ public void setFilterPath (String string) { public void setMessage (String string) { message = string; } +/** + * Sets the path which the dialog will use to filter + * the directories it shows to the argument, which may be + * null. + * + * @param string the filter path + */ +public void setFilterPath (String string) { + filterPath = string; +} } 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; - } - } |