From ad8f59cb37e0951b60605aa088b5c06514c1b987 Mon Sep 17 00:00:00 2001 From: "pavlov%netscape.com" Date: Tue, 4 Apr 2000 23:50:41 +0000 Subject: [PATCH] Make nsIFileURL scriptable and QueryInterfaceable. fix bug #34335 and 34328 and 34470. Minor cleanups on unix file picker dialog --- editor/ui/composer/content/EditorCommands.js | 4 ++-- netwerk/base/public/nsIURL.idl | 1 + netwerk/base/src/nsStdURL.cpp | 3 ++- widget/public/nsIFilePicker.idl | 10 +++++++++- widget/src/mac/nsFilePicker.cpp | 12 ++++++++++++ widget/src/windows/nsFilePicker.cpp | 17 +++++++++++++++++ widget/src/xpwidgets/nsBaseFilePicker.cpp | 2 ++ xpfe/browser/resources/content/navigator.js | 8 ++------ xpfe/browser/resources/content/openLocation.js | 10 +++------- .../filepicker/res/content/filepicker.xul | 3 +-- xpfe/components/filepicker/src/nsFilePicker.js | 11 +++++++++++ .../filepicker/src/nsFilePicker.js.in | 11 +++++++++++ 12 files changed, 73 insertions(+), 19 deletions(-) diff --git a/editor/ui/composer/content/EditorCommands.js b/editor/ui/composer/content/EditorCommands.js index 52c0dbb6c14..0bd6a04f6b8 100644 --- a/editor/ui/composer/content/EditorCommands.js +++ b/editor/ui/composer/content/EditorCommands.js @@ -310,13 +310,13 @@ function EditorOpen() /* check for already open window and activate it... */ if (fp.file) { - var found = FindAndSelectEditorWindowWithURL(fp.file.path); + var found = FindAndSelectEditorWindowWithURL(fp.fileURL.spec); if (!found) { /* open new window */ window.openDialog("chrome://editor/content", "_blank", "chrome,dialog=no,all", - fp.file.path); + fp.fileURL.spec); } } } diff --git a/netwerk/base/public/nsIURL.idl b/netwerk/base/public/nsIURL.idl index e4d8cd5785d..3c0a1c68e79 100644 --- a/netwerk/base/public/nsIURL.idl +++ b/netwerk/base/public/nsIURL.idl @@ -142,6 +142,7 @@ interface nsIFile; * nsIFileURL is used for the file: protocol, and gives access to the * underlying nsIFile object. */ +[scriptable, uuid(d26b2e2e-1dd1-11b2-88f3-8545a7ba7949)] interface nsIFileURL : nsIURL { attribute nsIFile file; diff --git a/netwerk/base/src/nsStdURL.cpp b/netwerk/base/src/nsStdURL.cpp index d2e088fec8c..83cabcaebb3 100644 --- a/netwerk/base/src/nsStdURL.cpp +++ b/netwerk/base/src/nsStdURL.cpp @@ -197,7 +197,8 @@ nsStdURL::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = GetInner(); else if (aIID.Equals(kThisStdURLImplementationCID) || // used by Equals aIID.Equals(NS_GET_IID(nsIURL)) || - aIID.Equals(NS_GET_IID(nsIURI))) + aIID.Equals(NS_GET_IID(nsIURI)) || + aIID.Equals(NS_GET_IID(nsIFileURL))) *aInstancePtr = NS_STATIC_CAST(nsIURL*, this); else { *aInstancePtr = nsnull; diff --git a/widget/public/nsIFilePicker.idl b/widget/public/nsIFilePicker.idl index cd45e462bb7..b6eb80f271d 100644 --- a/widget/public/nsIFilePicker.idl +++ b/widget/public/nsIFilePicker.idl @@ -22,6 +22,7 @@ */ #include "nsISupports.idl" +#include "nsIURL.idl" #include "nsILocalFile.idl" interface nsIDOMWindow; @@ -85,12 +86,19 @@ interface nsIFilePicker : nsISupports /** - * Get the nsFileSpec for the file or directory. + * Get the nsILocalFile for the file or directory. * * @return Returns the file currently selected */ readonly attribute nsILocalFile file; + /** + * Get the nsIFileURL for the file or directory. + * + * @return Returns the file currently selected + */ + readonly attribute nsIFileURL fileURL; + /** * Show File Dialog. The dialog is displayed modally. * diff --git a/widget/src/mac/nsFilePicker.cpp b/widget/src/mac/nsFilePicker.cpp index 4cf0cb7a36a..88b7086ba71 100644 --- a/widget/src/mac/nsFilePicker.cpp +++ b/widget/src/mac/nsFilePicker.cpp @@ -27,6 +27,7 @@ #include "nsIComponentManager.h" #include "nsILocalFile.h" #include "nsILocalFileMac.h" +#include "nsIURL.h" #include "nsStringUtil.h" @@ -499,6 +500,17 @@ NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile) return NS_OK; } +//------------------------------------------------------------------------- +NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL) +{ + nsCOMPtr file(do_CreateInstance("component://netscape/network/standard-url")); + NS_ENSURE_TRUE(file, NS_ERROR_FAILURE); + file->SetFile(mFile); + NS_ADDREF(*aFileURL = file); + return NS_OK; +} + + //------------------------------------------------------------------------- // // Get the file + path diff --git a/widget/src/windows/nsFilePicker.cpp b/widget/src/windows/nsFilePicker.cpp index 843e24df869..53a2c9d7af6 100644 --- a/widget/src/windows/nsFilePicker.cpp +++ b/widget/src/windows/nsFilePicker.cpp @@ -33,6 +33,7 @@ #undef NS_IMPL_IDS #include "nsFilePicker.h" #include "nsILocalFile.h" +#include "nsIURL.h" #include "nsIStringBundle.h" #include #include @@ -234,6 +235,22 @@ NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile) return NS_OK; } +//------------------------------------------------------------------------- +NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL) +{ + nsCOMPtr file(do_CreateInstance("component://mozilla/file/local")); + NS_ENSURE_TRUE(file, NS_ERROR_FAILURE); + file->InitWithPath(nsCAutoString(mFile)); + + nsCOMPtr fileURL(do_CreateInstance("component://netscape/network/standard-url")); + NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE); + fileURL->SetFile(file); + + NS_ADDREF(*aFileURL = fileURL); + + return NS_OK; +} + //------------------------------------------------------------------------- // // Get the file + path diff --git a/widget/src/xpwidgets/nsBaseFilePicker.cpp b/widget/src/xpwidgets/nsBaseFilePicker.cpp index b19193cf5fc..13dbdec8061 100644 --- a/widget/src/xpwidgets/nsBaseFilePicker.cpp +++ b/widget/src/xpwidgets/nsBaseFilePicker.cpp @@ -96,6 +96,8 @@ NS_IMETHODIMP nsBaseFilePicker::Init(nsIDOMWindow *aParent, if (NS_SUCCEEDED(rv)) { return InitNative(widget, aTitle, aMode); + } else { + return InitNative(nsnull, aTitle, aMode); } return rv; diff --git a/xpfe/browser/resources/content/navigator.js b/xpfe/browser/resources/content/navigator.js index b0203d7bdaf..c29e996deff 100644 --- a/xpfe/browser/resources/content/navigator.js +++ b/xpfe/browser/resources/content/navigator.js @@ -714,12 +714,8 @@ function RevealSearchPanel() fp.init(window, bundle.GetStringFromName("openFile"), nsIFilePicker.modeOpen); fp.setFilters(nsIFilePicker.filterAll); fp.show(); - - // Hack to get a file: url from an nsIFile - var tempFileSpec = Components.classes["component://netscape/filespec"].createInstance(Components.interfaces.nsIFileSpec); - tempFileSpec.nativePath = fp.file.path; - - openNewWindowWith(tempFileSpec.URLString); + + openNewWindowWith(fp.fileURL.spec); } catch (ex) { } } diff --git a/xpfe/browser/resources/content/openLocation.js b/xpfe/browser/resources/content/openLocation.js index 06f2b725591..b6e5abc72a3 100644 --- a/xpfe/browser/resources/content/openLocation.js +++ b/xpfe/browser/resources/content/openLocation.js @@ -45,7 +45,7 @@ function onLoad() { // No browser supplied - we are calling from Composer dialog.openAppList.selectedItem = dialog.openEditWindow; - dialog.openTopWindow.disabled = true; + dialog.openTopWindow.setAttribute("disabled", "true"); } else dialog.openAppList.selectedItem = dialog.openTopWindow; @@ -125,13 +125,9 @@ function onChooseFile() fp.setFilters(nsIFilePicker.filterAll); fp.show(); - if (fp.file.path && fp.file.path.length > 0) + if (fp.fileURL.spec && fp.fileURL.spec.length > 0) { - // Hack to get a file: url from an nsIFile - var tempFileSpec = Components.classes["component://netscape/filespec"].createInstance(Components.interfaces.nsIFileSpec); - tempFileSpec.nativePath = fp.file.path; - - dialog.input.value = tempFileSpec.URLString; + dialog.input.value = fp.fileURL.spec; } } catch(ex) { } diff --git a/xpfe/components/filepicker/res/content/filepicker.xul b/xpfe/components/filepicker/res/content/filepicker.xul index f7460db6d69..4414dd045cb 100644 --- a/xpfe/components/filepicker/res/content/filepicker.xul +++ b/xpfe/components/filepicker/res/content/filepicker.xul @@ -20,8 +20,7 @@ -