зеркало из https://github.com/mozilla/pjs.git
Bug 412822 nsIFilePicker makes it hard to drop in other url systems
r=neil a=dsicore
This commit is contained in:
Родитель
2ddeb0c467
Коммит
2f26a5fe73
|
@ -132,12 +132,11 @@ NS_IMETHODIMP EmbedFilePicker::GetFile(nsILocalFile **aFile)
|
|||
{
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aFile);
|
||||
|
||||
if (mFilename.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
*aFile = nsnull;
|
||||
nsCOMPtr<nsIURI> baseURI;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(baseURI), mFilename);
|
||||
nsresult rv = GetFileURL(getter_AddRefs(baseURI));
|
||||
if (!baseURI)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(baseURI, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -162,19 +161,14 @@ NS_IMETHODIMP EmbedFilePicker::GetFile(nsILocalFile **aFile)
|
|||
}
|
||||
|
||||
/* readonly attribute nsIFileURL fileURL; */
|
||||
NS_IMETHODIMP EmbedFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
||||
NS_IMETHODIMP EmbedFilePicker::GetFileURL(nsIURI **aFileURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFileURL);
|
||||
*aFileURL = nsnull;
|
||||
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
GetFile(getter_AddRefs(file));
|
||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_CreateInstance(NS_STANDARDURL_CONTRACTID);
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_OUT_OF_MEMORY);
|
||||
fileURL->SetFile(file);
|
||||
NS_ADDREF(*aFileURL = fileURL);
|
||||
if (mFileURI.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
return NS_NewURI(aFileURL, mFileURI);
|
||||
}
|
||||
|
||||
/* readonly attribute nsISimpleEnumerator files; */
|
||||
|
@ -204,7 +198,7 @@ NS_IMETHODIMP EmbedFilePicker::Show(PRInt16 *_retval)
|
|||
|
||||
*_retval = response ? nsIFilePicker::returnOK : nsIFilePicker::returnCancel;
|
||||
|
||||
mFilename = retname;
|
||||
mFileURI = retname;
|
||||
if (retname)
|
||||
NS_Free(retname);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
protected:
|
||||
nsIDOMWindow *mParent;
|
||||
PRInt16 mMode;
|
||||
nsCString mFilename;
|
||||
nsCString mFileURI;
|
||||
|
||||
private:
|
||||
~EmbedFilePicker();
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
const nsIProperties = Components.interfaces.nsIProperties;
|
||||
const NS_DIRECTORYSERVICE_CONTRACTID = "@mozilla.org/file/directory_service;1";
|
||||
const NS_IOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
|
||||
const nsITreeBoxObject = Components.interfaces.nsITreeBoxObject;
|
||||
const nsIFileView = Components.interfaces.nsIFileView;
|
||||
const NS_FILEVIEW_CONTRACTID = "@mozilla.org/filepicker/fileview;1";
|
||||
|
@ -59,6 +60,7 @@ var retvals;
|
|||
var filePickerMode;
|
||||
var homeDir;
|
||||
var treeView;
|
||||
var allowURLs;
|
||||
|
||||
var textInput;
|
||||
var okButton;
|
||||
|
@ -91,6 +93,7 @@ function filepickerLoad() {
|
|||
const numFilters = filterTitles.length;
|
||||
|
||||
document.title = title;
|
||||
allowURLs = o.allowURLs;
|
||||
|
||||
if (initialText) {
|
||||
textInput.value = initialText;
|
||||
|
@ -235,9 +238,28 @@ function selectOnOK()
|
|||
var isDir = false;
|
||||
var isFile = false;
|
||||
|
||||
var fileList = processPath(textInput.value);
|
||||
retvals.filterIndex = document.getElementById("filterMenuList");
|
||||
retvals.fileURL = null;
|
||||
|
||||
if (!fileList) { // generic error message, should probably never happen
|
||||
if (allowURLs) {
|
||||
try {
|
||||
var ios = Components.classes[NS_IOSERVICE_CONTRACTID].getService(Components.interfaces.nsIIOService);
|
||||
retvals.fileURL = ios.newURI(textInput.value, '', null);
|
||||
var fileList = [];
|
||||
if (retvals.fileURL instanceof Components.interfaces.nsIFileURL)
|
||||
fileList.push(retvals.fileURL.nsIFileURL.file);
|
||||
gFilesEnumerator.mFiles = fileList;
|
||||
retvals.files = gFilesEnumerator;
|
||||
retvals.buttonStatus = ret;
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
var fileList = processPath(textInput.value);
|
||||
if (!fileList) {
|
||||
// generic error message, should probably never happen
|
||||
showErrorDialog("errorPathProblemTitle",
|
||||
"errorPathProblemMessage",
|
||||
textInput.value);
|
||||
|
@ -377,9 +399,6 @@ function selectOnOK()
|
|||
|
||||
retvals.files = gFilesEnumerator;
|
||||
retvals.buttonStatus = ret;
|
||||
|
||||
var filterMenuList = document.getElementById("filterMenuList");
|
||||
retvals.filterIndex = filterMenuList.selectedIndex;
|
||||
|
||||
return (ret != nsIFilePicker.returnCancel);
|
||||
}
|
||||
|
|
|
@ -40,11 +40,11 @@
|
|||
#include "nsISupports.idl"
|
||||
|
||||
interface nsILocalFile;
|
||||
interface nsIFileURL;
|
||||
interface nsIURI;
|
||||
interface nsIDOMWindow;
|
||||
interface nsISimpleEnumerator;
|
||||
|
||||
[scriptable, uuid(80faf095-c807-4558-a2cc-185ed70754ea)]
|
||||
[scriptable, uuid(d24ef0aa-d555-4117-84af-9cbbb7406909)]
|
||||
interface nsIFilePicker : nsISupports
|
||||
{
|
||||
const short modeOpen = 0; // Load a file or directory
|
||||
|
@ -63,6 +63,7 @@ interface nsIFilePicker : nsISupports
|
|||
const long filterXML = 0x10; // *.xml
|
||||
const long filterXUL = 0x20; // *.xul
|
||||
const long filterApps = 0x40; // Applications (per-platform implementation)
|
||||
const long filterAllowURLs = 0x80; // Allow URLs
|
||||
|
||||
/**
|
||||
* Initialize the file picker widget. The file picker is not valid until this
|
||||
|
@ -132,11 +133,11 @@ interface nsIFilePicker : nsISupports
|
|||
readonly attribute nsILocalFile file;
|
||||
|
||||
/**
|
||||
* Get the nsIFileURL for the file or directory.
|
||||
* Get the nsIURL for the file or directory.
|
||||
*
|
||||
* @return Returns the file currently selected
|
||||
*/
|
||||
readonly attribute nsIFileURL fileURL;
|
||||
readonly attribute nsIURI fileURL;
|
||||
|
||||
/**
|
||||
* Get the enumerator for the selected files
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
#include "nsFilePicker.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsEscape.h"
|
||||
|
@ -292,20 +291,15 @@ NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
|||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
||||
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIURI **aFileURL)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
file->InitWithNativePath(mFile);
|
||||
*aFileURL = nsnull;
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
nsresult rv = GetFile(getter_AddRefs(file));
|
||||
if (!file)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewFileURI(getter_AddRefs(uri), file);
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri));
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
|
||||
|
||||
NS_ADDREF(*aFileURL = fileURL);
|
||||
|
||||
return NS_OK;
|
||||
return NS_NewFileURI(aFileURL, file);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
|
@ -82,7 +82,7 @@ public:
|
|||
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHOD Show(PRInt16 *_retval);
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
|
|
|
@ -73,7 +73,7 @@ public:
|
|||
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
||||
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHOD Show(PRInt16 *_retval);
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
#include "nsILocalFile.h"
|
||||
#include "nsILocalFileMac.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsArrayEnumerator.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
||||
|
@ -540,7 +539,7 @@ NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile)
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
||||
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIURI **aFileURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFileURL);
|
||||
*aFileURL = nsnull;
|
||||
|
@ -548,15 +547,7 @@ NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
|||
if (mFiles.Count() == 0)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewFileURI(getter_AddRefs(uri), mFiles.ObjectAt(0));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri));
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
|
||||
|
||||
NS_ADDREF(*aFileURL = fileURL);
|
||||
return NS_OK;
|
||||
return NS_NewFileURI(aFileURL, mFiles.ObjectAt(0));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
|
@ -88,6 +88,8 @@ typedef enum
|
|||
|
||||
typedef gchar* (*_gtk_file_chooser_get_filename_fn)(GtkFileChooser *chooser);
|
||||
typedef GSList* (*_gtk_file_chooser_get_filenames_fn)(GtkFileChooser *chooser);
|
||||
typedef gchar* (*_gtk_file_chooser_get_uri_fn)(GtkFileChooser *chooser);
|
||||
typedef GSList* (*_gtk_file_chooser_get_uris_fn)(GtkFileChooser *chooser);
|
||||
typedef GtkWidget* (*_gtk_file_chooser_dialog_new_fn)(const gchar *title,
|
||||
GtkWindow *parent,
|
||||
GtkFileChooserAction action,
|
||||
|
@ -110,10 +112,12 @@ typedef void (*_gtk_image_set_from_pixbuf_fn)(GtkImage *image, GdkPixbuf *pixbuf
|
|||
typedef void (*_gtk_file_chooser_set_preview_widget_fn)(GtkFileChooser *chooser, GtkWidget *preview_widget);
|
||||
typedef GtkWidget* (*_gtk_image_new_fn)();
|
||||
typedef void (*_gtk_misc_set_padding_fn)(GtkMisc *misc, gint xpad, gint ypad);
|
||||
|
||||
typedef void (*_gtk_file_chooser_set_local_only_fn)(GtkFileChooser *chooser, gboolean local_only);
|
||||
|
||||
DECL_FUNC_PTR(gtk_file_chooser_get_filename);
|
||||
DECL_FUNC_PTR(gtk_file_chooser_get_filenames);
|
||||
DECL_FUNC_PTR(gtk_file_chooser_get_uri);
|
||||
DECL_FUNC_PTR(gtk_file_chooser_get_uris);
|
||||
DECL_FUNC_PTR(gtk_file_chooser_dialog_new);
|
||||
DECL_FUNC_PTR(gtk_file_chooser_set_select_multiple);
|
||||
DECL_FUNC_PTR(gtk_file_chooser_set_do_overwrite_confirmation);
|
||||
|
@ -132,6 +136,7 @@ DECL_FUNC_PTR(gtk_image_set_from_pixbuf);
|
|||
DECL_FUNC_PTR(gtk_file_chooser_set_preview_widget);
|
||||
DECL_FUNC_PTR(gtk_image_new);
|
||||
DECL_FUNC_PTR(gtk_misc_set_padding);
|
||||
DECL_FUNC_PTR(gtk_file_chooser_set_local_only);
|
||||
|
||||
static GtkWindow *
|
||||
get_gtk_window_for_nsiwidget(nsIWidget *widget)
|
||||
|
@ -204,6 +209,8 @@ nsFilePicker::LoadSymbolsGTK24()
|
|||
}
|
||||
|
||||
GET_LIBGTK_FUNC(gtk_file_chooser_get_filenames);
|
||||
GET_LIBGTK_FUNC(gtk_file_chooser_get_uri);
|
||||
GET_LIBGTK_FUNC(gtk_file_chooser_get_uris);
|
||||
GET_LIBGTK_FUNC(gtk_file_chooser_dialog_new);
|
||||
GET_LIBGTK_FUNC(gtk_file_chooser_set_select_multiple);
|
||||
GET_LIBGTK_FUNC_OPT(gtk_file_chooser_set_do_overwrite_confirmation);
|
||||
|
@ -222,6 +229,7 @@ nsFilePicker::LoadSymbolsGTK24()
|
|||
GET_LIBGTK_FUNC(gtk_file_chooser_set_preview_widget);
|
||||
GET_LIBGTK_FUNC(gtk_image_new);
|
||||
GET_LIBGTK_FUNC(gtk_misc_set_padding);
|
||||
GET_LIBGTK_FUNC(gtk_file_chooser_set_local_only);
|
||||
|
||||
initialized = PR_TRUE;
|
||||
|
||||
|
@ -340,17 +348,17 @@ ReadMultipleFiles(gpointer filename, gpointer array)
|
|||
void
|
||||
nsFilePicker::ReadValuesFromFileChooser(GtkWidget *file_chooser)
|
||||
{
|
||||
mFiles.Clear();
|
||||
mFilesURL.Clear();
|
||||
|
||||
if (mMode == nsIFilePicker::modeOpenMultiple) {
|
||||
mFile.Truncate();
|
||||
mFileURL.Truncate();
|
||||
|
||||
GSList *list = _gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(file_chooser));
|
||||
g_slist_foreach(list, ReadMultipleFiles, static_cast<gpointer>(&mFiles));
|
||||
g_slist_free(list);
|
||||
} else {
|
||||
gchar *filename = _gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(file_chooser));
|
||||
mFile.Assign(filename);
|
||||
gchar *filename = _gtk_file_chooser_get_uri (GTK_FILE_CHOOSER(file_chooser));
|
||||
mFileURL.Assign(filename);
|
||||
g_free(filename);
|
||||
}
|
||||
|
||||
|
@ -397,6 +405,7 @@ nsFilePicker::InitNative(nsIWidget *aParent,
|
|||
NS_IMETHODIMP
|
||||
nsFilePicker::AppendFilters(PRInt32 aFilterMask)
|
||||
{
|
||||
mAllowURLs = !!(aFilterMask & filterAllowURLs);
|
||||
return nsBaseFilePicker::AppendFilters(aFilterMask);
|
||||
}
|
||||
|
||||
|
@ -471,31 +480,26 @@ nsFilePicker::GetFile(nsILocalFile **aFile)
|
|||
NS_ENSURE_ARG_POINTER(aFile);
|
||||
|
||||
*aFile = nsnull;
|
||||
if (mFile.IsEmpty()) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = GetFileURL(getter_AddRefs(uri));
|
||||
if (!uri)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
file->InitWithNativePath(mFile);
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = fileURL->GetFile(getter_AddRefs(file));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NS_ADDREF(*aFile = file);
|
||||
|
||||
return NS_OK;
|
||||
return CallQueryInterface(file, aFile);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
||||
nsFilePicker::GetFileURL(nsIURI **aFileURL)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
GetFile(getter_AddRefs(file));
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewFileURI(getter_AddRefs(uri), file);
|
||||
NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
|
||||
|
||||
return CallQueryInterface(uri, aFileURL);
|
||||
*aFileURL = nsnull;
|
||||
return NS_NewFileURI(aFileURL, mFileURL);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -573,6 +577,9 @@ nsFilePicker::Show(PRInt16 *aReturn)
|
|||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
accept_button, GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
if (mAllowURLs) {
|
||||
_gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_chooser), FALSE);
|
||||
}
|
||||
|
||||
if (mMode == GTK_FILE_CHOOSER_ACTION_OPEN || mMode == GTK_FILE_CHOOSER_ACTION_SAVE) {
|
||||
GtkWidget *img_preview = _gtk_image_new();
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
NS_IMETHODIMP GetFilterIndex(PRInt32 *aFilterIndex);
|
||||
NS_IMETHODIMP SetFilterIndex(PRInt32 aFilterIndex);
|
||||
NS_IMETHODIMP GetFile(nsILocalFile **aFile);
|
||||
NS_IMETHODIMP GetFileURL(nsIFileURL **aFileURL);
|
||||
NS_IMETHODIMP GetFileURL(nsIURI **aFileURL);
|
||||
NS_IMETHODIMP GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHODIMP Show(PRInt16 *aReturn);
|
||||
|
||||
|
@ -86,7 +86,8 @@ protected:
|
|||
|
||||
PRInt16 mMode;
|
||||
PRInt16 mSelectedType;
|
||||
nsCString mFile;
|
||||
PRBool mAllowURLs;
|
||||
nsCString mFileURL;
|
||||
nsString mTitle;
|
||||
nsString mDefault;
|
||||
nsString mDefaultExtension;
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
#include "nsFilePicker.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsCRT.h"
|
||||
|
@ -400,20 +399,15 @@ NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile)
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
||||
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIURI **aFileURL)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
file->InitWithNativePath(mFile);
|
||||
*aFileURL = nsnull;
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
nsresult rv = GetFile(getter_AddRefs(file));
|
||||
if (!file)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewFileURI(getter_AddRefs(uri), file);
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri));
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
|
||||
|
||||
NS_ADDREF(*aFileURL = fileURL);
|
||||
|
||||
return NS_OK;
|
||||
return NS_NewFileURI(aFileURL, file);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHOD Show(PRInt16 *_retval);
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
#include "nsFilePicker.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsCRT.h"
|
||||
|
@ -267,20 +266,15 @@ NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
||||
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIURI **aFileURL)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
file->InitWithNativePath(mFile);
|
||||
*aFileURL = nsnull;
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
nsresult rv = GetFile(getter_AddRefs(file));
|
||||
if (!file)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewFileURI(getter_AddRefs(uri), file);
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri));
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
|
||||
|
||||
NS_ADDREF(*aFileURL = fileURL);
|
||||
|
||||
return NS_OK;
|
||||
return NS_NewFileURI(aFileURL, file);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
|
||||
NS_IMETHOD Show(PRInt16 *_retval);
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
|
|
|
@ -49,7 +49,6 @@
|
|||
#include "nsFilePicker.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsCRT.h"
|
||||
|
@ -406,6 +405,7 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *aReturnVal)
|
|||
NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFile);
|
||||
*aFile = nsnull;
|
||||
|
||||
if (mUnicodeFile.IsEmpty())
|
||||
return NS_OK;
|
||||
|
@ -422,20 +422,15 @@ NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile)
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
||||
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIURI **aFileURL)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
file->InitWithPath(mUnicodeFile);
|
||||
*aFileURL = nsnull;
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
nsresult rv = GetFile(getter_AddRefs(file));
|
||||
if (!file)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewFileURI(getter_AddRefs(uri), file);
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri));
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
|
||||
|
||||
NS_ADDREF(*aFileURL = fileURL);
|
||||
|
||||
return NS_OK;
|
||||
return NS_NewFileURI(aFileURL, file);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHOD Show(PRInt16 *aReturnVal);
|
||||
NS_IMETHOD ShowW(PRInt16 *aReturnVal);
|
||||
|
|
|
@ -116,16 +116,19 @@ nsFilePicker.prototype = {
|
|||
set files(a) { throw "readonly property"; },
|
||||
get files() { return this.mFilesEnumerator; },
|
||||
|
||||
/* readonly attribute nsIFileURL fileURL; */
|
||||
/* readonly attribute nsIURI fileURL; */
|
||||
set fileURL(a) { throw "readonly property"; },
|
||||
get fileURL() {
|
||||
if (this.mFilesEnumerator) {
|
||||
if (this.mFileURL)
|
||||
return this.mFileURL;
|
||||
|
||||
if (!this.mFilesEnumerator)
|
||||
return null;
|
||||
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var url = ioService.newFileURI(this.file);
|
||||
return url;
|
||||
}
|
||||
return null;
|
||||
|
||||
return this.mFileURL = ioService.newFileURI(this.file);
|
||||
},
|
||||
|
||||
/* attribute wstring defaultString; */
|
||||
|
@ -172,6 +175,7 @@ nsFilePicker.prototype = {
|
|||
this.appendFilter(bundle.GetStringFromName("xulTitle"),
|
||||
bundle.GetStringFromName("xulFilter"));
|
||||
}
|
||||
this.mAllowURLs = !!(filterMask & nsIFilePicker.filterAllowURLs);
|
||||
if (filterMask & nsIFilePicker.filterApps) {
|
||||
// We use "..apps" as a special filter for executable files
|
||||
this.appendFilter(bundle.GetStringFromName("appsTitle"),
|
||||
|
@ -207,6 +211,7 @@ nsFilePicker.prototype = {
|
|||
o.filters = new Object();
|
||||
o.filters.titles = this.mFilterTitles;
|
||||
o.filters.types = this.mFilters;
|
||||
o.allowURLs = this.mAllowURLs;
|
||||
o.retvals = new Object();
|
||||
|
||||
var parent;
|
||||
|
@ -247,6 +252,7 @@ nsFilePicker.prototype = {
|
|||
|
||||
this.mFilterIndex = o.retvals.filterIndex;
|
||||
this.mFilesEnumerator = o.retvals.files;
|
||||
this.mFileURL = o.retvals.fileURL;
|
||||
lastDirectory = o.retvals.directory;
|
||||
return o.retvals.buttonStatus;
|
||||
} catch(ex) { dump("unable to open file picker\n" + ex + "\n"); }
|
||||
|
|
Загрузка…
Ссылка в новой задаче