mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 412822 nsIFilePicker makes it hard to drop in other url systems r=neil a=dsicore
This commit is contained in:
parent
9026a2a9c8
commit
54584cc580
@ -132,12 +132,11 @@ NS_IMETHODIMP EmbedFilePicker::GetFile(nsILocalFile **aFile)
|
|||||||
{
|
{
|
||||||
|
|
||||||
NS_ENSURE_ARG_POINTER(aFile);
|
NS_ENSURE_ARG_POINTER(aFile);
|
||||||
|
*aFile = nsnull;
|
||||||
if (mFilename.IsEmpty())
|
|
||||||
return NS_OK;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> baseURI;
|
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));
|
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(baseURI, &rv));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
@ -162,19 +161,14 @@ NS_IMETHODIMP EmbedFilePicker::GetFile(nsILocalFile **aFile)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* readonly attribute nsIFileURL fileURL; */
|
/* readonly attribute nsIFileURL fileURL; */
|
||||||
NS_IMETHODIMP EmbedFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
NS_IMETHODIMP EmbedFilePicker::GetFileURL(nsIURI **aFileURL)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG_POINTER(aFileURL);
|
NS_ENSURE_ARG_POINTER(aFileURL);
|
||||||
*aFileURL = nsnull;
|
*aFileURL = nsnull;
|
||||||
|
if (mFileURI.IsEmpty())
|
||||||
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);
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
|
return NS_NewURI(aFileURL, mFileURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* readonly attribute nsISimpleEnumerator files; */
|
/* readonly attribute nsISimpleEnumerator files; */
|
||||||
@ -204,7 +198,7 @@ NS_IMETHODIMP EmbedFilePicker::Show(PRInt16 *_retval)
|
|||||||
|
|
||||||
*_retval = response ? nsIFilePicker::returnOK : nsIFilePicker::returnCancel;
|
*_retval = response ? nsIFilePicker::returnOK : nsIFilePicker::returnCancel;
|
||||||
|
|
||||||
mFilename = retname;
|
mFileURI = retname;
|
||||||
if (retname)
|
if (retname)
|
||||||
NS_Free(retname);
|
NS_Free(retname);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
nsIDOMWindow *mParent;
|
nsIDOMWindow *mParent;
|
||||||
PRInt16 mMode;
|
PRInt16 mMode;
|
||||||
nsCString mFilename;
|
nsCString mFileURI;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~EmbedFilePicker();
|
~EmbedFilePicker();
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||||
const nsIProperties = Components.interfaces.nsIProperties;
|
const nsIProperties = Components.interfaces.nsIProperties;
|
||||||
const NS_DIRECTORYSERVICE_CONTRACTID = "@mozilla.org/file/directory_service;1";
|
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 nsITreeBoxObject = Components.interfaces.nsITreeBoxObject;
|
||||||
const nsIFileView = Components.interfaces.nsIFileView;
|
const nsIFileView = Components.interfaces.nsIFileView;
|
||||||
const NS_FILEVIEW_CONTRACTID = "@mozilla.org/filepicker/fileview;1";
|
const NS_FILEVIEW_CONTRACTID = "@mozilla.org/filepicker/fileview;1";
|
||||||
@ -59,6 +60,7 @@ var retvals;
|
|||||||
var filePickerMode;
|
var filePickerMode;
|
||||||
var homeDir;
|
var homeDir;
|
||||||
var treeView;
|
var treeView;
|
||||||
|
var allowURLs;
|
||||||
|
|
||||||
var textInput;
|
var textInput;
|
||||||
var okButton;
|
var okButton;
|
||||||
@ -91,6 +93,7 @@ function filepickerLoad() {
|
|||||||
const numFilters = filterTitles.length;
|
const numFilters = filterTitles.length;
|
||||||
|
|
||||||
document.title = title;
|
document.title = title;
|
||||||
|
allowURLs = o.allowURLs;
|
||||||
|
|
||||||
if (initialText) {
|
if (initialText) {
|
||||||
textInput.value = initialText;
|
textInput.value = initialText;
|
||||||
@ -235,9 +238,28 @@ function selectOnOK()
|
|||||||
var isDir = false;
|
var isDir = false;
|
||||||
var isFile = 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",
|
showErrorDialog("errorPathProblemTitle",
|
||||||
"errorPathProblemMessage",
|
"errorPathProblemMessage",
|
||||||
textInput.value);
|
textInput.value);
|
||||||
@ -377,9 +399,6 @@ function selectOnOK()
|
|||||||
|
|
||||||
retvals.files = gFilesEnumerator;
|
retvals.files = gFilesEnumerator;
|
||||||
retvals.buttonStatus = ret;
|
retvals.buttonStatus = ret;
|
||||||
|
|
||||||
var filterMenuList = document.getElementById("filterMenuList");
|
|
||||||
retvals.filterIndex = filterMenuList.selectedIndex;
|
|
||||||
|
|
||||||
return (ret != nsIFilePicker.returnCancel);
|
return (ret != nsIFilePicker.returnCancel);
|
||||||
}
|
}
|
||||||
|
@ -40,11 +40,11 @@
|
|||||||
#include "nsISupports.idl"
|
#include "nsISupports.idl"
|
||||||
|
|
||||||
interface nsILocalFile;
|
interface nsILocalFile;
|
||||||
interface nsIFileURL;
|
interface nsIURI;
|
||||||
interface nsIDOMWindow;
|
interface nsIDOMWindow;
|
||||||
interface nsISimpleEnumerator;
|
interface nsISimpleEnumerator;
|
||||||
|
|
||||||
[scriptable, uuid(80faf095-c807-4558-a2cc-185ed70754ea)]
|
[scriptable, uuid(d24ef0aa-d555-4117-84af-9cbbb7406909)]
|
||||||
interface nsIFilePicker : nsISupports
|
interface nsIFilePicker : nsISupports
|
||||||
{
|
{
|
||||||
const short modeOpen = 0; // Load a file or directory
|
const short modeOpen = 0; // Load a file or directory
|
||||||
@ -63,6 +63,7 @@ interface nsIFilePicker : nsISupports
|
|||||||
const long filterXML = 0x10; // *.xml
|
const long filterXML = 0x10; // *.xml
|
||||||
const long filterXUL = 0x20; // *.xul
|
const long filterXUL = 0x20; // *.xul
|
||||||
const long filterApps = 0x40; // Applications (per-platform implementation)
|
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
|
* Initialize the file picker widget. The file picker is not valid until this
|
||||||
@ -132,11 +133,11 @@ interface nsIFilePicker : nsISupports
|
|||||||
readonly attribute nsILocalFile file;
|
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
|
* @return Returns the file currently selected
|
||||||
*/
|
*/
|
||||||
readonly attribute nsIFileURL fileURL;
|
readonly attribute nsIURI fileURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the enumerator for the selected files
|
* Get the enumerator for the selected files
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
#include "nsFilePicker.h"
|
#include "nsFilePicker.h"
|
||||||
#include "nsILocalFile.h"
|
#include "nsILocalFile.h"
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
#include "nsIFileURL.h"
|
|
||||||
#include "nsIStringBundle.h"
|
#include "nsIStringBundle.h"
|
||||||
#include "nsReadableUtils.h"
|
#include "nsReadableUtils.h"
|
||||||
#include "nsEscape.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"));
|
*aFileURL = nsnull;
|
||||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
nsCOMPtr<nsILocalFile> file;
|
||||||
file->InitWithNativePath(mFile);
|
nsresult rv = GetFile(getter_AddRefs(file));
|
||||||
|
if (!file)
|
||||||
|
return rv;
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
return NS_NewFileURI(aFileURL, file);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
@ -82,7 +82,7 @@ public:
|
|||||||
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
|
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
|
||||||
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
|
||||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||||
NS_IMETHOD Show(PRInt16 *_retval);
|
NS_IMETHOD Show(PRInt16 *_retval);
|
||||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||||
|
@ -73,7 +73,7 @@ public:
|
|||||||
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
||||||
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
|
||||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||||
NS_IMETHOD Show(PRInt16 *_retval);
|
NS_IMETHOD Show(PRInt16 *_retval);
|
||||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||||
|
@ -56,7 +56,6 @@
|
|||||||
#include "nsILocalFile.h"
|
#include "nsILocalFile.h"
|
||||||
#include "nsILocalFileMac.h"
|
#include "nsILocalFileMac.h"
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
#include "nsIFileURL.h"
|
|
||||||
#include "nsArrayEnumerator.h"
|
#include "nsArrayEnumerator.h"
|
||||||
#include "nsIStringBundle.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);
|
NS_ENSURE_ARG_POINTER(aFileURL);
|
||||||
*aFileURL = nsnull;
|
*aFileURL = nsnull;
|
||||||
@ -548,15 +547,7 @@ NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
|||||||
if (mFiles.Count() == 0)
|
if (mFiles.Count() == 0)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
return NS_NewFileURI(aFileURL, mFiles.ObjectAt(0));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
@ -88,6 +88,8 @@ typedef enum
|
|||||||
|
|
||||||
typedef gchar* (*_gtk_file_chooser_get_filename_fn)(GtkFileChooser *chooser);
|
typedef gchar* (*_gtk_file_chooser_get_filename_fn)(GtkFileChooser *chooser);
|
||||||
typedef GSList* (*_gtk_file_chooser_get_filenames_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,
|
typedef GtkWidget* (*_gtk_file_chooser_dialog_new_fn)(const gchar *title,
|
||||||
GtkWindow *parent,
|
GtkWindow *parent,
|
||||||
GtkFileChooserAction action,
|
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 void (*_gtk_file_chooser_set_preview_widget_fn)(GtkFileChooser *chooser, GtkWidget *preview_widget);
|
||||||
typedef GtkWidget* (*_gtk_image_new_fn)();
|
typedef GtkWidget* (*_gtk_image_new_fn)();
|
||||||
typedef void (*_gtk_misc_set_padding_fn)(GtkMisc *misc, gint xpad, gint ypad);
|
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_filename);
|
||||||
DECL_FUNC_PTR(gtk_file_chooser_get_filenames);
|
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_dialog_new);
|
||||||
DECL_FUNC_PTR(gtk_file_chooser_set_select_multiple);
|
DECL_FUNC_PTR(gtk_file_chooser_set_select_multiple);
|
||||||
DECL_FUNC_PTR(gtk_file_chooser_set_do_overwrite_confirmation);
|
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_file_chooser_set_preview_widget);
|
||||||
DECL_FUNC_PTR(gtk_image_new);
|
DECL_FUNC_PTR(gtk_image_new);
|
||||||
DECL_FUNC_PTR(gtk_misc_set_padding);
|
DECL_FUNC_PTR(gtk_misc_set_padding);
|
||||||
|
DECL_FUNC_PTR(gtk_file_chooser_set_local_only);
|
||||||
|
|
||||||
static GtkWindow *
|
static GtkWindow *
|
||||||
get_gtk_window_for_nsiwidget(nsIWidget *widget)
|
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_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_dialog_new);
|
||||||
GET_LIBGTK_FUNC(gtk_file_chooser_set_select_multiple);
|
GET_LIBGTK_FUNC(gtk_file_chooser_set_select_multiple);
|
||||||
GET_LIBGTK_FUNC_OPT(gtk_file_chooser_set_do_overwrite_confirmation);
|
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_file_chooser_set_preview_widget);
|
||||||
GET_LIBGTK_FUNC(gtk_image_new);
|
GET_LIBGTK_FUNC(gtk_image_new);
|
||||||
GET_LIBGTK_FUNC(gtk_misc_set_padding);
|
GET_LIBGTK_FUNC(gtk_misc_set_padding);
|
||||||
|
GET_LIBGTK_FUNC(gtk_file_chooser_set_local_only);
|
||||||
|
|
||||||
initialized = PR_TRUE;
|
initialized = PR_TRUE;
|
||||||
|
|
||||||
@ -340,17 +348,17 @@ ReadMultipleFiles(gpointer filename, gpointer array)
|
|||||||
void
|
void
|
||||||
nsFilePicker::ReadValuesFromFileChooser(GtkWidget *file_chooser)
|
nsFilePicker::ReadValuesFromFileChooser(GtkWidget *file_chooser)
|
||||||
{
|
{
|
||||||
mFiles.Clear();
|
mFilesURL.Clear();
|
||||||
|
|
||||||
if (mMode == nsIFilePicker::modeOpenMultiple) {
|
if (mMode == nsIFilePicker::modeOpenMultiple) {
|
||||||
mFile.Truncate();
|
mFileURL.Truncate();
|
||||||
|
|
||||||
GSList *list = _gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(file_chooser));
|
GSList *list = _gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(file_chooser));
|
||||||
g_slist_foreach(list, ReadMultipleFiles, static_cast<gpointer>(&mFiles));
|
g_slist_foreach(list, ReadMultipleFiles, static_cast<gpointer>(&mFiles));
|
||||||
g_slist_free(list);
|
g_slist_free(list);
|
||||||
} else {
|
} else {
|
||||||
gchar *filename = _gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(file_chooser));
|
gchar *filename = _gtk_file_chooser_get_uri (GTK_FILE_CHOOSER(file_chooser));
|
||||||
mFile.Assign(filename);
|
mFileURL.Assign(filename);
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,6 +405,7 @@ nsFilePicker::InitNative(nsIWidget *aParent,
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsFilePicker::AppendFilters(PRInt32 aFilterMask)
|
nsFilePicker::AppendFilters(PRInt32 aFilterMask)
|
||||||
{
|
{
|
||||||
|
mAllowURLs = !!(aFilterMask & filterAllowURLs);
|
||||||
return nsBaseFilePicker::AppendFilters(aFilterMask);
|
return nsBaseFilePicker::AppendFilters(aFilterMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,31 +480,26 @@ nsFilePicker::GetFile(nsILocalFile **aFile)
|
|||||||
NS_ENSURE_ARG_POINTER(aFile);
|
NS_ENSURE_ARG_POINTER(aFile);
|
||||||
|
|
||||||
*aFile = nsnull;
|
*aFile = nsnull;
|
||||||
if (mFile.IsEmpty()) {
|
nsCOMPtr<nsIURI> uri;
|
||||||
return NS_OK;
|
nsresult rv = GetFileURL(getter_AddRefs(uri));
|
||||||
}
|
if (!uri)
|
||||||
|
return rv;
|
||||||
|
|
||||||
nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
|
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri, &rv));
|
||||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
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 CallQueryInterface(file, aFile);
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
nsFilePicker::GetFileURL(nsIURI **aFileURL)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsILocalFile> file;
|
*aFileURL = nsnull;
|
||||||
GetFile(getter_AddRefs(file));
|
return NS_NewFileURI(aFileURL, mFileURL);
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
|
||||||
NS_NewFileURI(getter_AddRefs(uri), file);
|
|
||||||
NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
|
|
||||||
|
|
||||||
return CallQueryInterface(uri, aFileURL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
@ -573,6 +577,9 @@ nsFilePicker::Show(PRInt16 *aReturn)
|
|||||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||||
accept_button, GTK_RESPONSE_ACCEPT,
|
accept_button, GTK_RESPONSE_ACCEPT,
|
||||||
NULL);
|
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) {
|
if (mMode == GTK_FILE_CHOOSER_ACTION_OPEN || mMode == GTK_FILE_CHOOSER_ACTION_SAVE) {
|
||||||
GtkWidget *img_preview = _gtk_image_new();
|
GtkWidget *img_preview = _gtk_image_new();
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
NS_IMETHODIMP GetFilterIndex(PRInt32 *aFilterIndex);
|
NS_IMETHODIMP GetFilterIndex(PRInt32 *aFilterIndex);
|
||||||
NS_IMETHODIMP SetFilterIndex(PRInt32 aFilterIndex);
|
NS_IMETHODIMP SetFilterIndex(PRInt32 aFilterIndex);
|
||||||
NS_IMETHODIMP GetFile(nsILocalFile **aFile);
|
NS_IMETHODIMP GetFile(nsILocalFile **aFile);
|
||||||
NS_IMETHODIMP GetFileURL(nsIFileURL **aFileURL);
|
NS_IMETHODIMP GetFileURL(nsIURI **aFileURL);
|
||||||
NS_IMETHODIMP GetFiles(nsISimpleEnumerator **aFiles);
|
NS_IMETHODIMP GetFiles(nsISimpleEnumerator **aFiles);
|
||||||
NS_IMETHODIMP Show(PRInt16 *aReturn);
|
NS_IMETHODIMP Show(PRInt16 *aReturn);
|
||||||
|
|
||||||
@ -86,7 +86,8 @@ protected:
|
|||||||
|
|
||||||
PRInt16 mMode;
|
PRInt16 mMode;
|
||||||
PRInt16 mSelectedType;
|
PRInt16 mSelectedType;
|
||||||
nsCString mFile;
|
PRBool mAllowURLs;
|
||||||
|
nsCString mFileURL;
|
||||||
nsString mTitle;
|
nsString mTitle;
|
||||||
nsString mDefault;
|
nsString mDefault;
|
||||||
nsString mDefaultExtension;
|
nsString mDefaultExtension;
|
||||||
|
@ -51,7 +51,6 @@
|
|||||||
#include "nsFilePicker.h"
|
#include "nsFilePicker.h"
|
||||||
#include "nsILocalFile.h"
|
#include "nsILocalFile.h"
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
#include "nsIFileURL.h"
|
|
||||||
#include "nsIStringBundle.h"
|
#include "nsIStringBundle.h"
|
||||||
#include "nsEnumeratorUtils.h"
|
#include "nsEnumeratorUtils.h"
|
||||||
#include "nsCRT.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"));
|
*aFileURL = nsnull;
|
||||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
nsCOMPtr<nsILocalFile> file;
|
||||||
file->InitWithNativePath(mFile);
|
nsresult rv = GetFile(getter_AddRefs(file));
|
||||||
|
if (!file)
|
||||||
|
return rv;
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
return NS_NewFileURI(aFileURL, file);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
||||||
|
@ -70,7 +70,7 @@ public:
|
|||||||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||||
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
||||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
|
||||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||||
NS_IMETHOD Show(PRInt16 *_retval);
|
NS_IMETHOD Show(PRInt16 *_retval);
|
||||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||||
|
@ -47,7 +47,6 @@
|
|||||||
#include "nsFilePicker.h"
|
#include "nsFilePicker.h"
|
||||||
#include "nsILocalFile.h"
|
#include "nsILocalFile.h"
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
#include "nsIFileURL.h"
|
|
||||||
#include "nsIStringBundle.h"
|
#include "nsIStringBundle.h"
|
||||||
#include "nsEnumeratorUtils.h"
|
#include "nsEnumeratorUtils.h"
|
||||||
#include "nsCRT.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"));
|
*aFileURL = nsnull;
|
||||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
nsCOMPtr<nsILocalFile> file;
|
||||||
file->InitWithNativePath(mFile);
|
nsresult rv = GetFile(getter_AddRefs(file));
|
||||||
|
if (!file)
|
||||||
|
return rv;
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
return NS_NewFileURI(aFileURL, file);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||||
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
||||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
|
||||||
NS_IMETHOD Show(PRInt16 *_retval);
|
NS_IMETHOD Show(PRInt16 *_retval);
|
||||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
#include "nsFilePicker.h"
|
#include "nsFilePicker.h"
|
||||||
#include "nsILocalFile.h"
|
#include "nsILocalFile.h"
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
#include "nsIFileURL.h"
|
|
||||||
#include "nsIStringBundle.h"
|
#include "nsIStringBundle.h"
|
||||||
#include "nsEnumeratorUtils.h"
|
#include "nsEnumeratorUtils.h"
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
@ -406,6 +405,7 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *aReturnVal)
|
|||||||
NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile)
|
NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG_POINTER(aFile);
|
NS_ENSURE_ARG_POINTER(aFile);
|
||||||
|
*aFile = nsnull;
|
||||||
|
|
||||||
if (mUnicodeFile.IsEmpty())
|
if (mUnicodeFile.IsEmpty())
|
||||||
return NS_OK;
|
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"));
|
*aFileURL = nsnull;
|
||||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
nsCOMPtr<nsILocalFile> file;
|
||||||
file->InitWithPath(mUnicodeFile);
|
nsresult rv = GetFile(getter_AddRefs(file));
|
||||||
|
if (!file)
|
||||||
|
return rv;
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
return NS_NewFileURI(aFileURL, file);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
||||||
|
@ -70,7 +70,7 @@ public:
|
|||||||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||||
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
||||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
|
||||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||||
NS_IMETHOD Show(PRInt16 *aReturnVal);
|
NS_IMETHOD Show(PRInt16 *aReturnVal);
|
||||||
NS_IMETHOD ShowW(PRInt16 *aReturnVal);
|
NS_IMETHOD ShowW(PRInt16 *aReturnVal);
|
||||||
|
@ -116,16 +116,19 @@ nsFilePicker.prototype = {
|
|||||||
set files(a) { throw "readonly property"; },
|
set files(a) { throw "readonly property"; },
|
||||||
get files() { return this.mFilesEnumerator; },
|
get files() { return this.mFilesEnumerator; },
|
||||||
|
|
||||||
/* readonly attribute nsIFileURL fileURL; */
|
/* readonly attribute nsIURI fileURL; */
|
||||||
set fileURL(a) { throw "readonly property"; },
|
set fileURL(a) { throw "readonly property"; },
|
||||||
get fileURL() {
|
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"]
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||||
.getService(Components.interfaces.nsIIOService);
|
.getService(Components.interfaces.nsIIOService);
|
||||||
var url = ioService.newFileURI(this.file);
|
|
||||||
return url;
|
return this.mFileURL = ioService.newFileURI(this.file);
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/* attribute wstring defaultString; */
|
/* attribute wstring defaultString; */
|
||||||
@ -172,6 +175,7 @@ nsFilePicker.prototype = {
|
|||||||
this.appendFilter(bundle.GetStringFromName("xulTitle"),
|
this.appendFilter(bundle.GetStringFromName("xulTitle"),
|
||||||
bundle.GetStringFromName("xulFilter"));
|
bundle.GetStringFromName("xulFilter"));
|
||||||
}
|
}
|
||||||
|
this.mAllowURLs = !!(filterMask & nsIFilePicker.filterAllowURLs);
|
||||||
if (filterMask & nsIFilePicker.filterApps) {
|
if (filterMask & nsIFilePicker.filterApps) {
|
||||||
// We use "..apps" as a special filter for executable files
|
// We use "..apps" as a special filter for executable files
|
||||||
this.appendFilter(bundle.GetStringFromName("appsTitle"),
|
this.appendFilter(bundle.GetStringFromName("appsTitle"),
|
||||||
@ -207,6 +211,7 @@ nsFilePicker.prototype = {
|
|||||||
o.filters = new Object();
|
o.filters = new Object();
|
||||||
o.filters.titles = this.mFilterTitles;
|
o.filters.titles = this.mFilterTitles;
|
||||||
o.filters.types = this.mFilters;
|
o.filters.types = this.mFilters;
|
||||||
|
o.allowURLs = this.mAllowURLs;
|
||||||
o.retvals = new Object();
|
o.retvals = new Object();
|
||||||
|
|
||||||
var parent;
|
var parent;
|
||||||
@ -247,6 +252,7 @@ nsFilePicker.prototype = {
|
|||||||
|
|
||||||
this.mFilterIndex = o.retvals.filterIndex;
|
this.mFilterIndex = o.retvals.filterIndex;
|
||||||
this.mFilesEnumerator = o.retvals.files;
|
this.mFilesEnumerator = o.retvals.files;
|
||||||
|
this.mFileURL = o.retvals.fileURL;
|
||||||
lastDirectory = o.retvals.directory;
|
lastDirectory = o.retvals.directory;
|
||||||
return o.retvals.buttonStatus;
|
return o.retvals.buttonStatus;
|
||||||
} catch(ex) { dump("unable to open file picker\n" + ex + "\n"); }
|
} catch(ex) { dump("unable to open file picker\n" + ex + "\n"); }
|
||||||
|
Loading…
Reference in New Issue
Block a user