Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLakshmi Shanmugam2015-10-23 08:13:25 +0000
committerLakshmi Shanmugam2017-08-11 11:44:04 +0000
commita99439d30a7b8da847601ddd9043ac241ce028e9 (patch)
treebe5e70e99f9afc317dd7558d51ddcce1c584a76d /bundles/org.eclipse.swt/Eclipse SWT
parentd81458a98525bf0b98909d362bde0ba3e3199d56 (diff)
downloadeclipse.platform.swt-a99439d30a7b8da847601ddd9043ac241ce028e9.tar.gz
eclipse.platform.swt-a99439d30a7b8da847601ddd9043ac241ce028e9.tar.xz
eclipse.platform.swt-a99439d30a7b8da847601ddd9043ac241ce028e9.zip
Bug 467205 - [10.10] FileDialog/DirectoryDialog with SWT.SHEET misplacedI20170811-2000
after slide-down animation Replaced deprecated NSSavePanel and NSOpenPanel APIs with newer ones. The new API NSSavePanel.beginSheetModalForWindow that is required to show the Sheet, uses objective-c block for completion handler. This call can't be made directly from Java, as Java doesn't support the block syntax (^). Hence, it is called from a wrapper function inside C code in os_custom.c. The wrapper function calls beginSheetModalForWindow with the objective C block syntax. The completion handler block is also implemented in os_custom.c which callsback to the Java functionFileDialog/DirectoryDialog._completionHandler(). Change-Id: Ib03881a68ef7ecaf2132cf91a4137aef8b6fe3fc
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DirectoryDialog.java61
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FileDialog.java186
2 files changed, 157 insertions, 90 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DirectoryDialog.java
index 002e202ebf..989b9bd310 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DirectoryDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DirectoryDialog.java
@@ -12,6 +12,7 @@ package org.eclipse.swt.widgets;
import org.eclipse.swt.*;
+import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.cocoa.*;
@@ -34,6 +35,9 @@ import org.eclipse.swt.internal.cocoa.*;
* @noextend This class is not intended to be subclassed by clients.
*/
public class DirectoryDialog extends Dialog {
+ Callback completion_handler_callback;
+ NSOpenPanel panel;
+ String directoryPath;
String message = "", filterPath = "";
/**
@@ -85,6 +89,11 @@ public DirectoryDialog (Shell parent, int style) {
checkSubclass ();
}
+long _completionHandler (long result) {
+ handleResponse(result);
+ return result;
+}
+
/**
* Returns the path which the dialog will use to filter
* the directories it shows.
@@ -108,6 +117,19 @@ public String getMessage () {
return message;
}
+void handleResponse (long response) {
+ if (parent != null && (style & SWT.SHEET) != 0) {
+ NSApplication.sharedApplication().stopModal();
+ }
+ Display display = parent != null ? parent.getDisplay() : Display.getCurrent();
+ display.setModalDialog(null);
+ if (response == OS.NSFileHandlingPanelOKButton) {
+ NSString filename = panel.filename();
+ directoryPath = filterPath = filename.getString();
+ }
+ releaseHandles();
+}
+
/**
* Makes the dialog visible and brings it to the front
* of the display.
@@ -121,10 +143,9 @@ public String getMessage () {
* </ul>
*/
public String open () {
- String directoryPath = null;
- NSOpenPanel panel = NSOpenPanel.openPanel();
+ directoryPath = null;
+ panel = NSOpenPanel.openPanel();
- Display display = parent != null ? parent.getDisplay() : Display.getCurrent();
/*
* This line is intentionally commented. Don't show hidden files forcefully,
* instead allow Directory dialog to use the system preference.
@@ -137,25 +158,35 @@ public String open () {
panel.setCanChooseFiles(false);
panel.setCanChooseDirectories(true);
panel.setTreatsFilePackagesAsDirectories(true);
- NSApplication application = NSApplication.sharedApplication();
- if (parent != null && (style & SWT.SHEET) != 0) {
- application.beginSheet(panel, parent.view.window (), null, 0, 0);
- }
- display.setModalDialog(this, panel);
+
NSString dir = (filterPath != null && filterPath.length() > 0) ? NSString.stringWith(filterPath) : null;
- long /*int*/ response = panel.runModalForDirectory(dir, null);
+ panel.setDirectoryURL(NSURL.fileURLWithPath(dir));
+
+ Display display = parent != null ? parent.getDisplay() : Display.getCurrent();
+ display.setModalDialog(this, panel);
+
if (parent != null && (style & SWT.SHEET) != 0) {
- application.endSheet(panel, 0);
- }
- display.setModalDialog(null);
- if (response == OS.NSFileHandlingPanelOKButton) {
- NSString filename = panel.filename();
- directoryPath = filterPath = filename.getString();
+ completion_handler_callback = new Callback(this, "_completionHandler", 1);
+ long handler = completion_handler_callback.getAddress();
+ if (handler == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ OS.beginSheetModalForWindow(panel, parent.view.window(), handler);
+ NSApplication.sharedApplication().runModalForWindow(parent.view.window());
+ } else {
+ long response = panel.runModal();
+ handleResponse(response);
}
+
// options.optionFlags = OS.kNavSupportPackages | OS.kNavAllowOpenPackages | OS.kNavAllowInvisibleFiles;
return directoryPath;
}
+void releaseHandles () {
+ if (completion_handler_callback != null) {
+ completion_handler_callback.dispose();
+ completion_handler_callback = null;
+ }
+ panel = null;
+}
/**
* Sets the dialog's message, which is a description of
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FileDialog.java
index 0b563e730c..01399ed514 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FileDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FileDialog.java
@@ -38,13 +38,20 @@ import org.eclipse.swt.internal.cocoa.*;
* @noextend This class is not intended to be subclassed by clients.
*/
public class FileDialog extends Dialog {
+ Callback callback_completion_handler;
+ Callback callback_overwrite_existing_file;
NSSavePanel panel;
NSPopUpButton popup;
String [] filterNames = new String [0];
String [] filterExtensions = new String [0];
String [] fileNames = new String[0];
String filterPath = "", fileName = "";
+ String fullPath;
+ SWTPanelDelegate delegate = null;
int filterIndex = -1;
+ long /*int*/ jniRef = 0;
+ long /*int*/ method = 0;
+ long /*int*/ methodImpl = 0;
boolean overwrite = false;
static final char EXTENSION_SEPARATOR = ';';
@@ -101,6 +108,15 @@ public FileDialog (Shell parent, int style) {
checkSubclass ();
}
+long _completionHandler (long result) {
+ handleResponse(result);
+ return result;
+}
+
+long /*int*/ _overwriteExistingFileCheck (long /*int*/ id, long /*int*/ sel, long /*int*/ str) {
+ return 1;
+}
+
/**
* Returns the path of the first file that was
* selected in the dialog relative to the filter path, or an
@@ -188,6 +204,56 @@ public boolean getOverwrite () {
return overwrite;
}
+void handleResponse (long response) {
+ if (parent != null && (style & SWT.SHEET) != 0) {
+ NSApplication.sharedApplication().stopModal();
+ }
+ Display display = parent != null ? parent.getDisplay() : Display.getCurrent();
+ display.setModalDialog(null);
+
+ if (popup != null) {
+ filterIndex = (int)/*64*/popup.indexOfSelectedItem();
+ } else {
+ filterIndex = -1;
+ }
+
+ if (response == OS.NSFileHandlingPanelOKButton) {
+ NSString filename = panel.filename();
+ if ((style & SWT.SAVE) != 0) {
+ fullPath = filename.getString();
+ fileNames = new String [1];
+ fileName = fileNames [0] = filename.lastPathComponent().getString();
+ filterPath = filename.stringByDeletingLastPathComponent().getString();
+ } else {
+ fullPath = filename.getString();
+ NSArray filenames = ((NSOpenPanel)panel).filenames();
+ int count = (int)/*64*/filenames.count();
+ fileNames = new String[count];
+
+ for (int i = 0; i < count; i++) {
+ filename = new NSString(filenames.objectAtIndex(i));
+ NSString filenameOnly = filename.lastPathComponent();
+ NSString pathOnly = filename.stringByDeletingLastPathComponent();
+
+ if (i == 0) {
+ /* Filter path */
+ filterPath = pathOnly.getString();
+
+ /* File name */
+ fileName = fileNames [0] = filenameOnly.getString();
+ } else {
+ if (pathOnly.getString().equals (filterPath)) {
+ fileNames [i] = filenameOnly.getString();
+ } else {
+ fileNames [i] = filename.getString();
+ }
+ }
+ }
+ }
+ }
+ releaseHandles();
+}
+
/**
* Makes the dialog visible and brings it to the front
* of the display.
@@ -201,17 +267,13 @@ public boolean getOverwrite () {
* </ul>
*/
public String open () {
- String fullPath = null;
- fileNames = new String [0];
- long /*int*/ method = 0;
- long /*int*/ methodImpl = 0;
- Callback callback = null;
+ fullPath = null;
if ((style & SWT.SAVE) != 0) {
NSSavePanel savePanel = NSSavePanel.savePanel();
panel = savePanel;
if (!overwrite) {
- callback = new Callback(this, "_overwriteExistingFileCheck", 3);
- long /*int*/ proc = callback.getAddress();
+ callback_overwrite_existing_file = new Callback(this, "_overwriteExistingFileCheck", 3);
+ long /*int*/ proc = callback_overwrite_existing_file.getAddress();
if (proc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
method = OS.class_getInstanceMethod(OS.class_NSSavePanel, OS.sel_overwriteExistingFileCheck);
if (method != 0) methodImpl = OS.method_setImplementation(method, proc);
@@ -222,15 +284,14 @@ public String open () {
panel = openPanel;
}
- Display display = parent != null ? parent.getDisplay() : Display.getCurrent();
panel.setCanCreateDirectories(true);
/*
* This line is intentionally commented. Don't show hidden files forcefully,
* instead allow File dialog to use the system preference.
*/
// OS.objc_msgSend(panel.id, OS.sel_setShowsHiddenFiles_, true);
- long /*int*/ jniRef = 0;
- SWTPanelDelegate delegate = null;
+ jniRef = 0;
+ delegate = null;
if (filterExtensions != null && filterExtensions.length != 0) {
delegate = (SWTPanelDelegate)new SWTPanelDelegate().alloc().init();
jniRef = OS.NewGlobalRef(this);
@@ -265,79 +326,29 @@ public String open () {
panel.setTreatsFilePackagesAsDirectories(false);
}
panel.setTitle(NSString.stringWith(title != null ? title : ""));
- NSApplication application = NSApplication.sharedApplication();
- if (parent != null && (style & SWT.SHEET) != 0) {
- application.beginSheet(panel, parent.view.window (), null, 0, 0);
+ if (filterPath != null && filterPath.length() > 0) {
+ NSString dir = NSString.stringWith(filterPath);
+ panel.setDirectoryURL(NSURL.fileURLWithPath(dir));
+ }
+ if (fileName != null && fileName.length() > 0) {
+ panel.setNameFieldStringValue(NSString.stringWith(fileName));
}
+
+ Display display = parent != null ? parent.getDisplay() : Display.getCurrent();
display.setModalDialog(this, panel);
- NSString dir = (filterPath != null && filterPath.length() > 0) ? NSString.stringWith(filterPath) : null;
- NSString file = (fileName != null && fileName.length() > 0) ? NSString.stringWith(fileName) : null;
- long /*int*/ response = panel.runModalForDirectory(dir, file);
if (parent != null && (style & SWT.SHEET) != 0) {
- application.endSheet(panel, 0);
- }
- display.setModalDialog(null);
- if (!overwrite) {
- if (method != 0) OS.method_setImplementation(method, methodImpl);
- if (callback != null) callback.dispose();
- }
- if (popup != null) {
- filterIndex = (int)/*64*/popup.indexOfSelectedItem();
+ callback_completion_handler = new Callback(this, "_completionHandler", 1);
+ long handler = callback_completion_handler.getAddress();
+ if (handler == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ OS.beginSheetModalForWindow(panel, parent.view.window(), handler);
+ NSApplication.sharedApplication().runModalForWindow(parent.view.window());
} else {
- filterIndex = -1;
- }
- if (response == OS.NSFileHandlingPanelOKButton) {
- NSString filename = panel.filename();
- if ((style & SWT.SAVE) != 0) {
- fullPath = filename.getString();
- fileNames = new String [1];
- fileName = fileNames [0] = filename.lastPathComponent().getString();
- filterPath = filename.stringByDeletingLastPathComponent().getString();
- } else {
- fullPath = filename.getString();
- NSArray filenames = ((NSOpenPanel)panel).filenames();
- int count = (int)/*64*/filenames.count();
- fileNames = new String[count];
-
- for (int i = 0; i < count; i++) {
- filename = new NSString(filenames.objectAtIndex(i));
- NSString filenameOnly = filename.lastPathComponent();
- NSString pathOnly = filename.stringByDeletingLastPathComponent();
-
- if (i == 0) {
- /* Filter path */
- filterPath = pathOnly.getString();
-
- /* File name */
- fileName = fileNames [0] = filenameOnly.getString();
- } else {
- if (pathOnly.getString().equals (filterPath)) {
- fileNames [i] = filenameOnly.getString();
- } else {
- fileNames [i] = filename.getString();
- }
- }
- }
- }
- }
- if (popup != null) {
- panel.setAccessoryView(null);
- popup.release();
- popup = null;
- }
- if (delegate != null) {
- panel.setDelegate(null);
- delegate.release();
+ long response = panel.runModal();
+ handleResponse(response);
}
- if (jniRef != 0) OS.DeleteGlobalRef(jniRef);
- panel = null;
return fullPath;
}
-long /*int*/ _overwriteExistingFileCheck (long /*int*/ id, long /*int*/ sel, long /*int*/ str) {
- return 1;
-}
-
long /*int*/ panel_shouldShowFilename (long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1) {
NSString path = new NSString(arg1);
if (filterExtensions != null && filterExtensions.length != 0) {
@@ -372,6 +383,31 @@ long /*int*/ panel_shouldShowFilename (long /*int*/ id, long /*int*/ sel, long /
return 1;
}
+void releaseHandles() {
+ if (!overwrite) {
+ if (method != 0) OS.method_setImplementation(method, methodImpl);
+ if (callback_overwrite_existing_file != null) callback_overwrite_existing_file.dispose();
+ callback_overwrite_existing_file = null;
+ }
+ if (callback_completion_handler != null) {
+ callback_completion_handler.dispose();
+ callback_completion_handler = null;
+ }
+ if (popup != null) {
+ panel.setAccessoryView(null);
+ popup.release();
+ popup = null;
+ }
+ if (delegate != null) {
+ panel.setDelegate(null);
+ delegate.release();
+ delegate = null;
+ }
+ if (jniRef != 0) OS.DeleteGlobalRef(jniRef);
+ jniRef = 0;
+ panel = null;
+}
+
void sendSelection (long /*int*/ id, long /*int*/ sel, long /*int*/ arg) {
if (filterExtensions != null && filterExtensions.length > 0) {
String fileTypes = filterExtensions[(int)/*64*/popup.indexOfSelectedItem ()];

Back to the top