diff dwt/browser/FilePicker.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents e831403a80a9
children 5583f8eeee6c
line wrap: on
line diff
--- a/dwt/browser/FilePicker.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/browser/FilePicker.d	Mon Dec 01 17:07:00 2008 +0100
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2007 IBM Corporation and others.
+/*******************************************************************************
+ * Copyright (c) 2003, 2008 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
@@ -18,12 +18,12 @@
 import dwt.internal.mozilla.XPCOMObject;
 import dwt.internal.mozilla.nsEmbedString;
 import dwt.internal.mozilla.nsID;
+import dwt.internal.mozilla.nsIDOMWindow;
 import dwt.internal.mozilla.nsIFilePicker;
 import dwt.internal.mozilla.nsIFilePicker_1_8;
 import dwt.internal.mozilla.nsILocalFile;
 import dwt.internal.mozilla.nsISupports;
 import dwt.widgets.DirectoryDialog;
-import dwt.widgets.Display;
 import dwt.widgets.FileDialog;
 import dwt.widgets.Shell;
 
@@ -124,6 +124,12 @@
     return refCount;
 }
 
+Browser getBrowser (int /*long*/ aDOMWindow) {
+    if (aDOMWindow is 0) return null;
+    nsIDOMWindow window = new nsIDOMWindow (aDOMWindow);
+    return Mozilla.findBrowser (window);
+}
+
 /*
  * As of Mozilla 1.8 some of nsIFilePicker's string arguments changed type.  This method
  * answers a java string based on the type of string that is appropriate for the Mozilla
@@ -153,10 +159,12 @@
     /* picking a file */
     int style = mode is nsIFilePicker.modeSave ? DWT.SAVE : DWT.OPEN;
     if (mode is nsIFilePicker.modeOpenMultiple) style |= DWT.MULTI;
-    Display display = Display.getCurrent ();
-    Shell parent = null; // TODO compute parent
-    if (parent is null) {
-        parent = new Shell (display);
+    Browser browser = getBrowser (parentHandle);
+    Shell parent = null;
+    if (browser !is null) {
+        parent = browser.getShell ();
+    } else {
+        parent = new Shell ();
     }
     FileDialog dialog = new FileDialog (parent, style);
     if (title !is null) dialog.setText (title);
@@ -174,10 +182,12 @@
 }
 
 int showDirectoryPicker () {
-    Display display = Display.getCurrent ();
-    Shell parent = null; // TODO compute parent
-    if (parent is null) {
-        parent = new Shell (display);
+    Browser browser = getBrowser (parentHandle);
+    Shell parent = null;
+    if (browser !is null) {
+        parent = browser.getShell ();
+    } else {
+        parent = new Shell ();
     }
     DirectoryDialog dialog = new DirectoryDialog (parent, DWT.NONE);
     if (title !is null) dialog.setText (title);
@@ -226,7 +236,7 @@
 }
 
 int GetDisplayDirectory (int /*long*/ aDisplayDirectory) {
-    String directoryName = directory !is null ? directory : "";  //$NON-NLS-1$
+    String directoryName = directory !is null ? directory : ""; //$NON-NLS-1$
     nsEmbedString path = new nsEmbedString (directoryName);
     int /*long*/[] file = new int /*long*/[1];
     int rc = XPCOM.NS_NewLocalFile (path.getAddress (), 1, file);