Fixing bug 240723. Cleaning up nsIFilePicker a bit, no more nsIDOMWindowInternal, and use our string classes and not raw strings. r=caillon@gmail.com, sr=bzbarsky@mit.edu
This commit is contained in:
Родитель
7fd7fd5b7b
Коммит
34a10f2f1c
|
@ -287,7 +287,14 @@ GetFileNameForPrintSettings(nsIPrintSettings* aPS)
|
|||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("PrintToFile").get(), getter_Copies(title));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = filePicker->Init(nsnull, title.get(), nsIFilePicker::modeSave);
|
||||
nsCOMPtr<nsIWindowWatcher> wwatch =
|
||||
(do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window;
|
||||
wwatch->GetActiveWindow(getter_AddRefs(window));
|
||||
|
||||
rv = filePicker->Init(window, title, nsIFilePicker::modeSave);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = filePicker->AppendFilters(nsIFilePicker::filterAll);
|
||||
|
@ -308,7 +315,7 @@ GetFileNameForPrintSettings(nsIPrintSettings* aPS)
|
|||
}
|
||||
}
|
||||
if (!leafName.IsEmpty()) {
|
||||
rv = filePicker->SetDefaultString(leafName.get());
|
||||
rv = filePicker->SetDefaultString(leafName);
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
|
|
@ -272,9 +272,8 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent)
|
|||
if (!doc)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> parentWindow = do_QueryInterface(doc->GetScriptGlobalObject());
|
||||
if (!parentWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIDOMWindow> parentWindow =
|
||||
do_QueryInterface(doc->GetScriptGlobalObject());
|
||||
|
||||
// Get Loc title
|
||||
nsString title;
|
||||
|
@ -285,7 +284,7 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent)
|
|||
if (!filePicker)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
result = filePicker->Init(parentWindow, title.get(), nsIFilePicker::modeOpen);
|
||||
result = filePicker->Init(parentWindow, title, nsIFilePicker::modeOpen);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
|
@ -303,7 +302,7 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent)
|
|||
nsAutoString leafName;
|
||||
currentFile->GetLeafName(leafName);
|
||||
if (!leafName.IsEmpty()) {
|
||||
filePicker->SetDefaultString(leafName.get());
|
||||
filePicker->SetDefaultString(leafName);
|
||||
}
|
||||
|
||||
// set directory
|
||||
|
|
|
@ -272,9 +272,8 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent)
|
|||
if (!doc)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> parentWindow = do_QueryInterface(doc->GetScriptGlobalObject());
|
||||
if (!parentWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIDOMWindow> parentWindow =
|
||||
do_QueryInterface(doc->GetScriptGlobalObject());
|
||||
|
||||
// Get Loc title
|
||||
nsString title;
|
||||
|
@ -285,7 +284,7 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent)
|
|||
if (!filePicker)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
result = filePicker->Init(parentWindow, title.get(), nsIFilePicker::modeOpen);
|
||||
result = filePicker->Init(parentWindow, title, nsIFilePicker::modeOpen);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
|
@ -303,7 +302,7 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent)
|
|||
nsAutoString leafName;
|
||||
currentFile->GetLeafName(leafName);
|
||||
if (!leafName.IsEmpty()) {
|
||||
filePicker->SetDefaultString(leafName.get());
|
||||
filePicker->SetDefaultString(leafName);
|
||||
}
|
||||
|
||||
// set directory
|
||||
|
|
|
@ -1360,31 +1360,33 @@ NS_IMETHODIMP nsAddressBook::ExportAddressBook(nsIAbDirectory *aDirectory)
|
|||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
rv = bundleService->CreateBundle("chrome://messenger/locale/addressbook/addressBook.properties", getter_AddRefs(bundle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> parentWindow = do_GetInterface(mDocShell);
|
||||
|
||||
nsXPIDLString title;
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("ExportAddressBookTitle").get(), getter_Copies(title));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = filePicker->Init(nsnull, title.get(), nsIFilePicker::modeSave);
|
||||
rv = filePicker->Init(parentWindow, title, nsIFilePicker::modeSave);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsXPIDLString filterString;
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("LDIFFiles").get(), getter_Copies(filterString));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = filePicker->AppendFilter(filterString.get(), NS_LITERAL_STRING("*.ldi; *.ldif").get());
|
||||
rv = filePicker->AppendFilter(filterString, NS_LITERAL_STRING("*.ldi; *.ldif"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("CSVFiles").get(), getter_Copies(filterString));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = filePicker->AppendFilter(filterString.get(), NS_LITERAL_STRING("*.csv").get());
|
||||
rv = filePicker->AppendFilter(filterString, NS_LITERAL_STRING("*.csv"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("TABFiles").get(), getter_Copies(filterString));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = filePicker->AppendFilter(filterString.get(), NS_LITERAL_STRING("*.tab; *.txt").get());
|
||||
rv = filePicker->AppendFilter(filterString, NS_LITERAL_STRING("*.tab; *.txt"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRInt16 dialogResult;
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDocShell;
|
||||
interface nsIDOMWindowInternal;
|
||||
interface nsIDOMWindow;
|
||||
|
||||
[scriptable, uuid(a0032cf0-49e9-11d3-8d77-00805f8a6617)]
|
||||
interface nsIMsgStatusFeedback : nsISupports {
|
||||
|
@ -47,7 +47,7 @@ interface nsIMsgStatusFeedback : nsISupports {
|
|||
void startMeteors();
|
||||
void stopMeteors();
|
||||
void showProgress(in long percent);
|
||||
[noscript] void setDocShell(in nsIDocShell shell, in nsIDOMWindowInternal window);
|
||||
[noscript] void setDocShell(in nsIDocShell shell, in nsIDOMWindow window);
|
||||
void closeWindow();
|
||||
};
|
||||
|
||||
|
|
|
@ -318,7 +318,6 @@ public:
|
|||
nsMessenger::nsMessenger()
|
||||
{
|
||||
mScriptObject = nsnull;
|
||||
mWindow = nsnull;
|
||||
mMsgWindow = nsnull;
|
||||
mStringBundle = nsnull;
|
||||
mSendingUnsentMsgs = PR_FALSE;
|
||||
|
@ -327,8 +326,6 @@ nsMessenger::nsMessenger()
|
|||
|
||||
nsMessenger::~nsMessenger()
|
||||
{
|
||||
NS_IF_RELEASE(mWindow);
|
||||
|
||||
// Release search context.
|
||||
mSearchContext = nsnull;
|
||||
}
|
||||
|
@ -372,9 +369,7 @@ nsMessenger::SetWindow(nsIDOMWindowInternal *aWin, nsIMsgWindow *aMsgWindow)
|
|||
|
||||
mMsgWindow = aMsgWindow;
|
||||
|
||||
NS_IF_RELEASE(mWindow);
|
||||
mWindow = aWin;
|
||||
NS_ADDREF(aWin);
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
|
||||
NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE);
|
||||
|
@ -525,10 +520,10 @@ nsMessenger::PromptIfFileExists(nsFileSpec &fileSpec)
|
|||
do_CreateInstance("@mozilla.org/filepicker;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
filePicker->Init(nsnull,
|
||||
GetString(NS_LITERAL_STRING("SaveAttachment")).get(),
|
||||
filePicker->Init(mWindow,
|
||||
GetString(NS_LITERAL_STRING("SaveAttachment")),
|
||||
nsIFilePicker::modeSave);
|
||||
filePicker->SetDefaultString(path.get());
|
||||
filePicker->SetDefaultString(path);
|
||||
filePicker->AppendFilters(nsIFilePicker::filterAll);
|
||||
|
||||
nsCOMPtr <nsILocalFile> lastSaveDir;
|
||||
|
@ -817,9 +812,9 @@ nsMessenger::SaveAttachment(const char * contentType, const char * url,
|
|||
rv = ConvertAndSanitizeFileName(displayName, getter_Copies(defaultDisplayString), nsnull);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
filePicker->Init(nsnull, GetString(NS_LITERAL_STRING("SaveAttachment")).get(),
|
||||
filePicker->Init(mWindow, GetString(NS_LITERAL_STRING("SaveAttachment")),
|
||||
nsIFilePicker::modeSave);
|
||||
filePicker->SetDefaultString(defaultDisplayString.get());
|
||||
filePicker->SetDefaultString(defaultDisplayString);
|
||||
filePicker->AppendFilters(nsIFilePicker::filterAll);
|
||||
|
||||
rv = GetLastSaveDirectory(getter_AddRefs(lastSaveDir));
|
||||
|
@ -867,8 +862,8 @@ nsMessenger::SaveAllAttachments(PRUint32 count,
|
|||
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
filePicker->Init(nsnull,
|
||||
GetString(NS_LITERAL_STRING("SaveAllAttachments")).get(),
|
||||
filePicker->Init(mWindow,
|
||||
GetString(NS_LITERAL_STRING("SaveAllAttachments")),
|
||||
nsIFilePicker::modeGetFolder);
|
||||
|
||||
rv = GetLastSaveDirectory(getter_AddRefs(lastSaveDir));
|
||||
|
@ -956,21 +951,21 @@ nsMessenger::SaveAs(const char *aURI, PRBool aAsFile, nsIMsgIdentity *aIdentity,
|
|||
if (NS_FAILED(rv))
|
||||
goto done;
|
||||
|
||||
filePicker->Init(nsnull, GetString(NS_LITERAL_STRING("SaveMailAs")).get(),
|
||||
filePicker->Init(mWindow, GetString(NS_LITERAL_STRING("SaveMailAs")),
|
||||
nsIFilePicker::modeSave);
|
||||
|
||||
// if we have a non-null filename use it, otherwise use default save message one
|
||||
if (aMsgFilename)
|
||||
filePicker->SetDefaultString(aMsgFilename);
|
||||
filePicker->SetDefaultString(nsDependentString(aMsgFilename));
|
||||
else {
|
||||
filePicker->SetDefaultString(GetString(NS_LITERAL_STRING("defaultSaveMessageAsFileName")).get());
|
||||
filePicker->SetDefaultString(GetString(NS_LITERAL_STRING("defaultSaveMessageAsFileName")));
|
||||
}
|
||||
|
||||
// because we will be using GetFilterIndex()
|
||||
// we must call AppendFilters() one at a time,
|
||||
// in MESSENGER_SAVEAS_FILE_TYPE order
|
||||
filePicker->AppendFilter(GetString(NS_LITERAL_STRING("EMLFiles")).get(),
|
||||
NS_LITERAL_STRING("*.eml").get());
|
||||
filePicker->AppendFilter(GetString(NS_LITERAL_STRING("EMLFiles")),
|
||||
NS_LITERAL_STRING("*.eml"));
|
||||
filePicker->AppendFilters(nsIFilePicker::filterHTML);
|
||||
filePicker->AppendFilters(nsIFilePicker::filterText);
|
||||
filePicker->AppendFilters(nsIFilePicker::filterAll);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
|
@ -48,6 +48,7 @@
|
|||
#include "nsILocalFile.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
|
||||
class nsMessenger : public nsIMessenger, public nsIObserver, public nsSupportsWeakReference
|
||||
{
|
||||
|
@ -86,7 +87,7 @@ private:
|
|||
nsCOMPtr<nsITransactionManager> mTxnMgr;
|
||||
|
||||
/* rhp - need this to drive message display */
|
||||
nsIDOMWindowInternal *mWindow;
|
||||
nsCOMPtr<nsIDOMWindow> mWindow;
|
||||
nsCOMPtr<nsIMsgWindow> mMsgWindow;
|
||||
nsCOMPtr<nsIDocShell> mDocShell;
|
||||
|
||||
|
|
|
@ -330,7 +330,7 @@ NS_IMETHODIMP nsMsgProgress::ShowProgress(PRInt32 percent)
|
|||
}
|
||||
|
||||
/* [noscript] void setDocShell (in nsIDocShell shell, in nsIDOMWindowInternal window); */
|
||||
NS_IMETHODIMP nsMsgProgress::SetDocShell(nsIDocShell *shell, nsIDOMWindowInternal *window)
|
||||
NS_IMETHODIMP nsMsgProgress::SetDocShell(nsIDocShell *shell, nsIDOMWindow *window)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -239,18 +239,15 @@ NS_IMETHODIMP nsMsgStatusFeedback::CloseWindow()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgStatusFeedback::SetDocShell(nsIDocShell *shell, nsIDOMWindowInternal *aWindow)
|
||||
NS_IMETHODIMP nsMsgStatusFeedback::SetDocShell(nsIDocShell *shell, nsIDOMWindow *aWindow)
|
||||
{
|
||||
|
||||
if (aWindow)
|
||||
nsCOMPtr<nsPIDOMWindow> piDOMWindow(do_QueryInterface(aWindow));
|
||||
if (piDOMWindow)
|
||||
{
|
||||
nsCOMPtr<nsISupports> xpConnectObj;
|
||||
nsCOMPtr<nsPIDOMWindow> piDOMWindow(do_QueryInterface(aWindow));
|
||||
if (piDOMWindow)
|
||||
{
|
||||
piDOMWindow->GetObjectProperty(NS_LITERAL_STRING("MsgStatusFeedback").get(), getter_AddRefs(xpConnectObj));
|
||||
mStatusFeedback = do_QueryInterface(xpConnectObj);
|
||||
}
|
||||
nsCOMPtr<nsISupports> xpConnectObj;
|
||||
piDOMWindow->GetObjectProperty(NS_LITERAL_STRING("MsgStatusFeedback").get(), getter_AddRefs(xpConnectObj));
|
||||
mStatusFeedback = do_QueryInterface(xpConnectObj);
|
||||
}
|
||||
|
||||
mWindow = aWindow;
|
||||
|
|
|
@ -54,19 +54,19 @@ class nsMsgStatusFeedback : public nsIMsgStatusFeedback,
|
|||
public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
nsMsgStatusFeedback();
|
||||
virtual ~nsMsgStatusFeedback();
|
||||
nsMsgStatusFeedback();
|
||||
virtual ~nsMsgStatusFeedback();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMSGSTATUSFEEDBACK
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_DECL_NSIPROGRESSEVENTSINK
|
||||
|
||||
protected:
|
||||
nsIDOMWindowInternal *mWindow;
|
||||
PRBool m_meteorsSpinning;
|
||||
PRInt32 m_lastPercent;
|
||||
PRInt64 m_lastProgressTime;
|
||||
nsIDOMWindow *mWindow;
|
||||
PRBool m_meteorsSpinning;
|
||||
PRInt32 m_lastPercent;
|
||||
PRInt64 m_lastProgressTime;
|
||||
|
||||
|
||||
void BeginObserving();
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "prprf.h"
|
||||
#include "prmem.h"
|
||||
#include "nsDOMCID.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
|
@ -1689,7 +1689,7 @@ alertUser(const PRUnichar *message)
|
|||
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
|
||||
nsCOMPtr<nsIPrompt> prompter;
|
||||
if (wwatch)
|
||||
wwatch->GetNewPrompter(0, getter_AddRefs(prompter));
|
||||
wwatch->GetNewPrompter(0, getter_AddRefs(prompter));
|
||||
|
||||
if (prompter) {
|
||||
nsPSMUITracker tracker;
|
||||
|
@ -1734,12 +1734,21 @@ nsP12Runnable::Run()
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWindowWatcher> wwatch =
|
||||
(do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window;
|
||||
wwatch->GetActiveWindow(getter_AddRefs(window));
|
||||
|
||||
nsString filePickMessage;
|
||||
nssComponent->GetPIPNSSBundleString("chooseP12BackupFileDialog",
|
||||
filePickMessage);
|
||||
filePicker->Init(nsnull, filePickMessage.get(), nsIFilePicker::modeSave);
|
||||
filePicker->AppendFilter(NS_LITERAL_STRING("PKCS12").get(),
|
||||
NS_LITERAL_STRING("*.p12").get());
|
||||
rv = filePicker->Init(window, filePickMessage, nsIFilePicker::modeSave);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
filePicker->AppendFilter(NS_LITERAL_STRING("PKCS12"),
|
||||
NS_LITERAL_STRING("*.p12"));
|
||||
filePicker->AppendFilters(nsIFilePicker::filterAll);
|
||||
|
||||
PRInt16 dialogReturn;
|
||||
|
|
|
@ -1080,7 +1080,7 @@ static PRBool GetFileFromFileSelector(nsIDOMWindowInternal* aParentWindow,
|
|||
nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1");
|
||||
|
||||
if (filePicker) {
|
||||
rv = filePicker->Init(aParentWindow, NS_LITERAL_STRING("Open HTML").get(),
|
||||
rv = filePicker->Init(aParentWindow, NS_LITERAL_STRING("Open HTML"),
|
||||
nsIFilePicker::modeOpen);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
filePicker->AppendFilters(nsIFilePicker::filterAll | nsIFilePicker::filterHTML |
|
||||
|
|
|
@ -41,10 +41,10 @@
|
|||
|
||||
interface nsILocalFile;
|
||||
interface nsIFileURL;
|
||||
interface nsIDOMWindowInternal;
|
||||
interface nsIDOMWindow;
|
||||
interface nsISimpleEnumerator;
|
||||
|
||||
[scriptable, uuid(c47de916-1dd1-11b2-8141-82507fa02b21)]
|
||||
[scriptable, uuid(80faf095-c807-4558-a2cc-185ed70754ea)]
|
||||
interface nsIFilePicker : nsISupports
|
||||
{
|
||||
const short modeOpen = 0; // Load a file or directory
|
||||
|
@ -67,12 +67,13 @@ interface nsIFilePicker : nsISupports
|
|||
/**
|
||||
* Initialize the file widget.
|
||||
*
|
||||
* @param parent nsIDOMWindowInternal parent. This dialog should be dependent on this parent.
|
||||
* @param parent nsIDOMWindow parent. This dialog will be dependent
|
||||
* on this parent. parent must be non-null.
|
||||
* @param title The title for the file widget
|
||||
* @param mode load, save, or get folder
|
||||
*
|
||||
*/
|
||||
void init(in nsIDOMWindowInternal parent, in wstring title, in short mode);
|
||||
void init(in nsIDOMWindow parent, in AString title, in short mode);
|
||||
|
||||
/**
|
||||
* Append to the filter list with things from the predefined list
|
||||
|
@ -89,22 +90,22 @@ interface nsIFilePicker : nsISupports
|
|||
* @param filter extensions to filter -- semicolon and space separated
|
||||
*
|
||||
*/
|
||||
void appendFilter(in wstring title,
|
||||
in wstring filter);
|
||||
void appendFilter(in AString title,
|
||||
in AString filter);
|
||||
|
||||
/**
|
||||
* The filename that should be suggested to the user as a default.
|
||||
*
|
||||
* @throws NS_ERROR_FAILURE on attempts to get
|
||||
*/
|
||||
attribute wstring defaultString;
|
||||
attribute AString defaultString;
|
||||
|
||||
/**
|
||||
* The extension that should be associated with files of the type we
|
||||
* want to work with. On some platforms, this extension will be
|
||||
* automatically appended to filenames the user enters, if needed.
|
||||
*/
|
||||
attribute wstring defaultExtension;
|
||||
attribute AString defaultExtension;
|
||||
|
||||
/**
|
||||
* The filter which is currently selected in the File Picker dialog
|
||||
|
|
|
@ -310,13 +310,13 @@ NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
|||
// Get the file + path
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const PRUnichar *aString)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const nsAString& aString)
|
||||
{
|
||||
mDefault = aString;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(nsAString& aString)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -326,13 +326,13 @@ NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
|||
// The default extension to use for files
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(PRUnichar **aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(nsAString& aExtension)
|
||||
{
|
||||
*aExtension = nsnull;
|
||||
aExtension.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const PRUnichar *aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const nsAString& aExtension)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -361,123 +361,24 @@ NS_IMETHODIMP nsFilePicker::GetDisplayDirectory(nsILocalFile **aDirectory)
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::InitNative(nsIWidget *aParent,
|
||||
const PRUnichar *aTitle,
|
||||
PRInt16 aMode)
|
||||
void nsFilePicker::InitNative(nsIWidget *aParent,
|
||||
const nsAString& aTitle,
|
||||
PRInt16 aMode)
|
||||
{
|
||||
mParentWindow = 0;
|
||||
if (aParent) {
|
||||
BView *view = (BView *) aParent->GetNativeData(NS_NATIVE_WIDGET);
|
||||
if (view && view->LockLooper()) {
|
||||
mParentWindow = view->Window();
|
||||
view->UnlockLooper();
|
||||
}
|
||||
}
|
||||
|
||||
BView *view = (BView *) aParent->GetNativeData(NS_NATIVE_WIDGET);
|
||||
if (view && view->LockLooper()) {
|
||||
mParentWindow = view->Window();
|
||||
view->UnlockLooper();
|
||||
}
|
||||
|
||||
mTitle.Assign(aTitle);
|
||||
mMode = aMode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
//-------------------------------------------------------------------------
|
||||
void nsFilePicker::GetFileSystemCharset(nsString & fileSystemCharset)
|
||||
{
|
||||
static nsAutoString aCharset;
|
||||
nsresult rv;
|
||||
|
||||
if (aCharset.IsEmpty()) {
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, aCharset);
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "error getting platform charset");
|
||||
if (NS_FAILED(rv))
|
||||
aCharset.Assign(NS_LITERAL_STRING("UTF-8"));// XXX ok?
|
||||
}
|
||||
fileSystemCharset = aCharset;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
char * nsFilePicker::ConvertToFileSystemCharset(const PRUnichar *inString)
|
||||
{
|
||||
char *outString = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// get file system charset and create a unicode encoder
|
||||
if (!mUnicodeEncoder) {
|
||||
nsAutoString fileSystemCharset;
|
||||
GetFileSystemCharset(fileSystemCharset);
|
||||
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(kCharsetConverterManagerCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = ccm->GetUnicodeEncoder(&fileSystemCharset, &mUnicodeEncoder);
|
||||
}
|
||||
}
|
||||
|
||||
// converts from unicode to the file system charset
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt32 inLength = nsCRT::strlen(inString);
|
||||
PRInt32 outLength;
|
||||
rv = mUnicodeEncoder->GetMaxLength(inString, inLength, &outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString = NS_STATIC_CAST( char*, nsMemory::Alloc( outLength+1 ) );
|
||||
if (!outString) {
|
||||
return nsnull;
|
||||
}
|
||||
rv = mUnicodeEncoder->Convert(inString, &inLength, outString, &outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString[outLength] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_SUCCEEDED(rv) ? outString : nsnull;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRUnichar * nsFilePicker::ConvertFromFileSystemCharset(const char *inString)
|
||||
{
|
||||
PRUnichar *outString = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// get file system charset and create a unicode encoder
|
||||
if (!mUnicodeDecoder) {
|
||||
nsAutoString fileSystemCharset;
|
||||
GetFileSystemCharset(fileSystemCharset);
|
||||
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(kCharsetConverterManagerCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = ccm->GetUnicodeDecoder(&fileSystemCharset, &mUnicodeDecoder);
|
||||
}
|
||||
}
|
||||
|
||||
// converts from the file system charset to unicode
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt32 inLength = nsCRT::strlen(inString);
|
||||
PRInt32 outLength;
|
||||
rv = mUnicodeDecoder->GetMaxLength(inString, inLength, &outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString = NS_STATIC_CAST( PRUnichar*, nsMemory::Alloc( (outLength+1) * sizeof( PRUnichar ) ) );
|
||||
if (!outString) {
|
||||
return nsnull;
|
||||
}
|
||||
rv = mUnicodeDecoder->Convert(inString, &inLength, outString, &outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString[outLength] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "error charset conversion");
|
||||
return NS_SUCCEEDED(rv) ? outString : nsnull;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter)
|
||||
nsFilePicker::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
|
||||
{
|
||||
mFilterList.Append(aTitle);
|
||||
mFilterList.Append(PRUnichar('\0'));
|
||||
|
|
|
@ -70,96 +70,92 @@
|
|||
class nsFilePicker : public nsBaseFilePicker
|
||||
{
|
||||
public:
|
||||
nsFilePicker();
|
||||
virtual ~nsFilePicker();
|
||||
nsFilePicker();
|
||||
virtual ~nsFilePicker();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFilePicker (less what's in nsBaseFilePicker)
|
||||
NS_IMETHOD GetDefaultString(PRUnichar * *aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const PRUnichar * aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(PRUnichar * *aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const PRUnichar * aDefaultExtension);
|
||||
NS_IMETHOD GetDisplayDirectory(nsILocalFile * *aDisplayDirectory);
|
||||
NS_IMETHOD SetDisplayDirectory(nsILocalFile * aDisplayDirectory);
|
||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHOD Show(PRInt16 *_retval);
|
||||
NS_IMETHOD AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter) ;
|
||||
// nsIFilePicker (less what's in nsBaseFilePicker)
|
||||
NS_IMETHOD GetDefaultString(nsAString& aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const nsAString& aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||
NS_IMETHOD GetDisplayDirectory(nsILocalFile * *aDisplayDirectory);
|
||||
NS_IMETHOD SetDisplayDirectory(nsILocalFile * aDisplayDirectory);
|
||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHOD Show(PRInt16 *_retval);
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
|
||||
protected:
|
||||
// method from nsBaseFilePicker
|
||||
NS_IMETHOD InitNative(nsIWidget *aParent,
|
||||
const PRUnichar *aTitle,
|
||||
PRInt16 aMode);
|
||||
// method from nsBaseFilePicker
|
||||
virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle,
|
||||
PRInt16 aMode);
|
||||
|
||||
|
||||
void GetFilterListArray(nsString& aFilterList);
|
||||
// static void GetFileSystemCharset(nsString & fileSystemCharset);
|
||||
// char * ConvertToFileSystemCharset(const PRUnichar *inString);
|
||||
// PRUnichar * ConvertFromFileSystemCharset(const char *inString);
|
||||
void GetFilterListArray(nsString& aFilterList);
|
||||
|
||||
BWindow* mParentWindow;
|
||||
nsString mTitle;
|
||||
PRInt16 mMode;
|
||||
nsCString mFile;
|
||||
nsString mDefault;
|
||||
nsString mFilterList;
|
||||
nsIUnicodeEncoder* mUnicodeEncoder;
|
||||
nsIUnicodeDecoder* mUnicodeDecoder;
|
||||
nsCOMPtr<nsILocalFile> mDisplayDirectory;
|
||||
PRInt16 mSelectedType;
|
||||
nsCOMPtr <nsISupportsArray> mFiles;
|
||||
BWindow* mParentWindow;
|
||||
nsString mTitle;
|
||||
PRInt16 mMode;
|
||||
nsCString mFile;
|
||||
nsString mDefault;
|
||||
nsString mFilterList;
|
||||
nsIUnicodeEncoder* mUnicodeEncoder;
|
||||
nsIUnicodeDecoder* mUnicodeDecoder;
|
||||
nsCOMPtr<nsILocalFile> mDisplayDirectory;
|
||||
PRInt16 mSelectedType;
|
||||
nsCOMPtr <nsISupportsArray> mFiles;
|
||||
|
||||
#ifdef FILEPICKER_SAVE_LAST_DIR
|
||||
static char mLastUsedDirectory[];
|
||||
static char mLastUsedDirectory[];
|
||||
#endif
|
||||
};
|
||||
|
||||
class nsFilePanelBeOS : public BLooper, public BFilePanel
|
||||
{
|
||||
public:
|
||||
nsFilePanelBeOS(file_panel_mode mode,
|
||||
uint32 node_flavors,
|
||||
bool allow_multiple_selection,
|
||||
bool modal,
|
||||
bool hide_when_done);
|
||||
virtual ~nsFilePanelBeOS();
|
||||
nsFilePanelBeOS(file_panel_mode mode,
|
||||
uint32 node_flavors,
|
||||
bool allow_multiple_selection,
|
||||
bool modal,
|
||||
bool hide_when_done);
|
||||
virtual ~nsFilePanelBeOS();
|
||||
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
virtual void WaitForSelection();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
virtual void WaitForSelection();
|
||||
|
||||
virtual bool IsOpenSelected() {
|
||||
return (SelectedActivity() == OPEN_SELECTED);
|
||||
}
|
||||
virtual bool IsSaveSelected() {
|
||||
return (SelectedActivity() == SAVE_SELECTED);
|
||||
}
|
||||
virtual bool IsCancelSelected() {
|
||||
return (SelectedActivity() == CANCEL_SELECTED);
|
||||
}
|
||||
virtual uint32 SelectedActivity();
|
||||
virtual bool IsOpenSelected() {
|
||||
return (SelectedActivity() == OPEN_SELECTED);
|
||||
}
|
||||
virtual bool IsSaveSelected() {
|
||||
return (SelectedActivity() == SAVE_SELECTED);
|
||||
}
|
||||
virtual bool IsCancelSelected() {
|
||||
return (SelectedActivity() == CANCEL_SELECTED);
|
||||
}
|
||||
virtual uint32 SelectedActivity();
|
||||
|
||||
virtual BList *OpenRefs() { return &mOpenRefs; }
|
||||
virtual BString SaveFileName() { return mSaveFileName; }
|
||||
virtual entry_ref SaveDirRef() { return mSaveDirRef; }
|
||||
virtual BList *OpenRefs() { return &mOpenRefs; }
|
||||
virtual BString SaveFileName() { return mSaveFileName; }
|
||||
virtual entry_ref SaveDirRef() { return mSaveDirRef; }
|
||||
|
||||
enum {
|
||||
NOT_SELECTED = 0,
|
||||
OPEN_SELECTED = 1,
|
||||
SAVE_SELECTED = 2,
|
||||
CANCEL_SELECTED = 3
|
||||
};
|
||||
enum {
|
||||
NOT_SELECTED = 0,
|
||||
OPEN_SELECTED = 1,
|
||||
SAVE_SELECTED = 2,
|
||||
CANCEL_SELECTED = 3
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
sem_id wait_sem ;
|
||||
uint32 mSelectedActivity;
|
||||
bool mIsSelected;
|
||||
BString mSaveFileName;
|
||||
entry_ref mSaveDirRef;
|
||||
BList mOpenRefs;
|
||||
sem_id wait_sem ;
|
||||
uint32 mSelectedActivity;
|
||||
bool mIsSelected;
|
||||
BString mSaveFileName;
|
||||
entry_ref mSaveDirRef;
|
||||
BList mOpenRefs;
|
||||
};
|
||||
|
||||
#endif // nsFilePicker_h__
|
||||
|
|
|
@ -66,26 +66,24 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFilePicker (less what's in nsBaseFilePicker)
|
||||
NS_IMETHOD GetDefaultString(PRUnichar * *aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const PRUnichar * aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(PRUnichar * *aDefaultExtension);
|
||||
NS_IMETHOD GetDefaultString(nsAString& aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const nsAString& aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
|
||||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||
NS_IMETHOD SetFilterIndex(PRInt32 aFilterIndex);
|
||||
NS_IMETHOD SetDefaultExtension(const PRUnichar * aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||
NS_IMETHOD GetDisplayDirectory(nsILocalFile * *aDisplayDirectory);
|
||||
NS_IMETHOD SetDisplayDirectory(nsILocalFile * aDisplayDirectory);
|
||||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHOD Show(PRInt16 *_retval);
|
||||
NS_IMETHOD AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter);
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
|
||||
protected:
|
||||
|
||||
NS_IMETHOD InitNative(nsIWidget *aParent, const PRUnichar *aTitle, PRInt16 aMode);
|
||||
|
||||
NS_IMETHOD OnOk();
|
||||
NS_IMETHOD OnCancel();
|
||||
virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle,
|
||||
PRInt16 aMode);
|
||||
|
||||
// actual implementations of get/put dialogs using NSOpenPanel & NSSavePanel
|
||||
// aFile is an existing but unspecified file. These functions must specify it.
|
||||
|
@ -97,7 +95,6 @@ protected:
|
|||
void SetDialogTitle(const nsString& inTitle, id aDialog);
|
||||
NSString *PanelDefaultDirectory();
|
||||
|
||||
PRBool mWasCancelled;
|
||||
PRBool mAllFilesDisplayed;
|
||||
nsString mTitle;
|
||||
PRInt16 mMode;
|
||||
|
|
|
@ -54,7 +54,6 @@ NS_IMPL_ISUPPORTS1(nsFilePicker, nsIFilePicker)
|
|||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsFilePicker::nsFilePicker()
|
||||
: mWasCancelled(PR_FALSE)
|
||||
, mAllFilesDisplayed(PR_TRUE)
|
||||
, mMode(0)
|
||||
, mSelectedType(0)
|
||||
|
@ -73,38 +72,15 @@ nsFilePicker::~nsFilePicker()
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::InitNative(nsIWidget *aParent, const PRUnichar *aTitle, PRInt16 aMode)
|
||||
void
|
||||
nsFilePicker::InitNative(nsIWidget *aParent, const nsAString& aTitle,
|
||||
PRInt16 aMode)
|
||||
{
|
||||
mTitle = aTitle;
|
||||
mMode = aMode;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Ok's the dialog
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::OnOk()
|
||||
{
|
||||
mWasCancelled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Cancel the dialog
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::OnCancel()
|
||||
{
|
||||
mWasCancelled = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Show - Display the file dialog
|
||||
|
@ -458,13 +434,13 @@ NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
|||
// Get the file + path
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const PRUnichar *aString)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const nsAString& aString)
|
||||
{
|
||||
mDefault = aString;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(nsAString& aString)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -474,13 +450,13 @@ NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
|||
// The default extension to use for files
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(PRUnichar **aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(nsAString& aExtension)
|
||||
{
|
||||
*aExtension = nsnull;
|
||||
aExtension.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const PRUnichar *aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const nsAString& aExtension)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -515,12 +491,10 @@ NS_IMETHODIMP nsFilePicker::GetDisplayDirectory(nsILocalFile **aDirectory)
|
|||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter)
|
||||
nsFilePicker::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
|
||||
{
|
||||
// XXX this assumes that these buffers outlive us. Might want to copy
|
||||
// the strings.
|
||||
mFilters.AppendString(nsDependentString(aFilter));
|
||||
mTitles.AppendString(nsDependentString(aTitle));
|
||||
mFilters.AppendString(aFilter);
|
||||
mTitles.AppendString(aTitle);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ OSType nsFilePicker::sCurrentProcessSignature = 0;
|
|||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsFilePicker::nsFilePicker()
|
||||
: mWasCancelled(PR_FALSE)
|
||||
, mAllFilesDisplayed(PR_TRUE)
|
||||
, mSelectedType(0)
|
||||
, mTypeOffset(0)
|
||||
|
@ -126,38 +125,15 @@ nsFilePicker::~nsFilePicker()
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::InitNative(nsIWidget *aParent, const PRUnichar *aTitle, PRInt16 aMode)
|
||||
void
|
||||
nsFilePicker::InitNative(nsIWidget *aParent, const nsAString& aTitle,
|
||||
PRInt16 aMode)
|
||||
{
|
||||
mTitle = aTitle;
|
||||
mMode = aMode;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Ok's the dialog
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::OnOk()
|
||||
{
|
||||
mWasCancelled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Cancel the dialog
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::OnCancel()
|
||||
{
|
||||
mWasCancelled = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Show - Display the file dialog
|
||||
|
@ -877,13 +853,13 @@ NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
|||
// Get the file + path
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const PRUnichar *aString)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const nsAString& aString)
|
||||
{
|
||||
mDefault = aString;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(nsAString& aString)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -893,13 +869,13 @@ NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
|||
// The default extension to use for files
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(PRUnichar **aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(nsAString& aExtension)
|
||||
{
|
||||
*aExtension = nsnull;
|
||||
aExtension.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const PRUnichar *aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const nsAString& aExtension)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -931,10 +907,10 @@ NS_IMETHODIMP nsFilePicker::GetDisplayDirectory(nsILocalFile **aDirectory)
|
|||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter)
|
||||
nsFilePicker::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
|
||||
{
|
||||
mFilters.AppendString(nsDependentString(aFilter));
|
||||
mTitles.AppendString(nsDependentString(aTitle));
|
||||
mFilters.AppendString(aFilter);
|
||||
mTitles.AppendString(aTitle);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -67,10 +67,10 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFilePicker (less what's in nsBaseFilePicker)
|
||||
NS_IMETHOD GetDefaultString(PRUnichar * *aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const PRUnichar * aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(PRUnichar * *aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const PRUnichar * aDefaultExtension);
|
||||
NS_IMETHOD GetDefaultString(nsAString& aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const nsAString& aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||
NS_IMETHOD GetDisplayDirectory(nsILocalFile * *aDisplayDirectory);
|
||||
NS_IMETHOD SetDisplayDirectory(nsILocalFile * aDisplayDirectory);
|
||||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||
|
@ -79,14 +79,12 @@ public:
|
|||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHOD Show(PRInt16 *_retval);
|
||||
NS_IMETHOD AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter);
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
|
||||
protected:
|
||||
|
||||
NS_IMETHOD InitNative(nsIWidget *aParent, const PRUnichar *aTitle, PRInt16 aMode);
|
||||
|
||||
NS_IMETHOD OnOk();
|
||||
NS_IMETHOD OnCancel();
|
||||
virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle,
|
||||
PRInt16 aMode);
|
||||
|
||||
// actual implementations of get/put dialogs using NavServices
|
||||
PRInt16 GetLocalFiles(const nsString& inTitle, PRBool inAllowMultiple, nsCOMArray<nsILocalFile>& outFiles);
|
||||
|
@ -113,7 +111,6 @@ protected:
|
|||
NavCallBackUserData callbackUD,
|
||||
NavFilterModes filterMode ) ;
|
||||
|
||||
PRBool mWasCancelled;
|
||||
PRBool mAllFilesDisplayed;
|
||||
nsString mTitle;
|
||||
PRInt16 mMode;
|
||||
|
|
|
@ -421,7 +421,7 @@ NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
|||
// Get the file + path
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const PRUnichar *aString)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const nsAString& aString)
|
||||
{
|
||||
mDefault = aString;
|
||||
|
||||
|
@ -461,7 +461,7 @@ NS_IMETHODIMP nsFilePicker::SetDefaultString(const PRUnichar *aString)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(nsAString& aString)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -471,15 +471,13 @@ NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
|||
// The default extension to use for files
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(PRUnichar **aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(nsAString& aExtension)
|
||||
{
|
||||
*aExtension = ToNewUnicode(mDefaultExtension);
|
||||
if (!*aExtension)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
aExtension = mDefaultExtension;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const PRUnichar *aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const nsAString& aExtension)
|
||||
{
|
||||
mDefaultExtension = aExtension;
|
||||
return NS_OK;
|
||||
|
@ -528,14 +526,13 @@ NS_IMETHODIMP nsFilePicker::GetDisplayDirectory(nsILocalFile **aDirectory)
|
|||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::InitNative(nsIWidget *aParent,
|
||||
const PRUnichar *aTitle,
|
||||
PRInt16 aMode)
|
||||
void nsFilePicker::InitNative(nsIWidget *aParent,
|
||||
const nsAString& aTitle,
|
||||
PRInt16 aMode)
|
||||
{
|
||||
mWnd = (HWND) ((aParent) ? aParent->GetNativeData(NS_NATIVE_WINDOW) : 0);
|
||||
mTitle.Assign(aTitle);
|
||||
mMode = aMode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -558,7 +555,7 @@ void nsFilePicker::GetFileSystemCharset(nsCString & fileSystemCharset)
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
char * nsFilePicker::ConvertToFileSystemCharset(const PRUnichar *inString)
|
||||
char * nsFilePicker::ConvertToFileSystemCharset(const nsAString& inString)
|
||||
{
|
||||
char *outString = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
@ -577,15 +574,20 @@ char * nsFilePicker::ConvertToFileSystemCharset(const PRUnichar *inString)
|
|||
|
||||
// converts from unicode to the file system charset
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt32 inLength = nsCRT::strlen(inString);
|
||||
PRInt32 inLength = inString.Length();
|
||||
|
||||
const nsAFlatString& flatInString = PromiseFlatString(inString);
|
||||
|
||||
PRInt32 outLength;
|
||||
rv = mUnicodeEncoder->GetMaxLength(inString, inLength, &outLength);
|
||||
rv = mUnicodeEncoder->GetMaxLength(flatInString.get(), inLength,
|
||||
&outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString = NS_STATIC_CAST( char*, nsMemory::Alloc( outLength+1 ) );
|
||||
if (nsnull == outString) {
|
||||
return nsnull;
|
||||
}
|
||||
rv = mUnicodeEncoder->Convert(inString, &inLength, outString, &outLength);
|
||||
rv = mUnicodeEncoder->Convert(flatInString.get(), &inLength, outString,
|
||||
&outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString[outLength] = '\0';
|
||||
}
|
||||
|
@ -636,10 +638,10 @@ PRUnichar * nsFilePicker::ConvertFromFileSystemCharset(const char *inString)
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter)
|
||||
nsFilePicker::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
|
||||
{
|
||||
mFilters.AppendString(nsDependentString(aFilter));
|
||||
mTitles.AppendString(nsDependentString(aTitle));
|
||||
mFilters.AppendString(aFilter);
|
||||
mTitles.AppendString(aTitle);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -63,10 +63,10 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFilePicker (less what's in nsBaseFilePicker)
|
||||
NS_IMETHOD GetDefaultString(PRUnichar * *aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const PRUnichar * aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(PRUnichar * *aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const PRUnichar * aDefaultExtension);
|
||||
NS_IMETHOD GetDefaultString(nsAString& aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const nsAString& aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||
NS_IMETHOD GetDisplayDirectory(nsILocalFile * *aDisplayDirectory);
|
||||
NS_IMETHOD SetDisplayDirectory(nsILocalFile * aDisplayDirectory);
|
||||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||
|
@ -75,18 +75,17 @@ public:
|
|||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHOD Show(PRInt16 *_retval);
|
||||
NS_IMETHOD AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter) ;
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
|
||||
protected:
|
||||
/* method from nsBaseFilePicker */
|
||||
NS_IMETHOD InitNative(nsIWidget *aParent,
|
||||
const PRUnichar *aTitle,
|
||||
PRInt16 aMode);
|
||||
virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle,
|
||||
PRInt16 aMode);
|
||||
|
||||
|
||||
void GetFilterListArray(nsString& aFilterList);
|
||||
static void GetFileSystemCharset(nsCString & fileSystemCharset);
|
||||
char * ConvertToFileSystemCharset(const PRUnichar *inString);
|
||||
char * ConvertToFileSystemCharset(const nsAString& inString);
|
||||
PRUnichar * ConvertFromFileSystemCharset(const char *inString);
|
||||
|
||||
HWND mWnd;
|
||||
|
|
|
@ -280,13 +280,13 @@ NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
|||
// Get the file + path
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const PRUnichar *aString)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const nsAString& aString)
|
||||
{
|
||||
mDefault = aString;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(nsAString& aString)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -296,15 +296,13 @@ NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
|||
// The default extension to use for files
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(PRUnichar **aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(nsAString& aExtension)
|
||||
{
|
||||
*aExtension = ToNewUnicode(mDefaultExtension);
|
||||
if (!*aExtension)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
aExtension = mDefaultExtension;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const PRUnichar *aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const nsAString& aExtension)
|
||||
{
|
||||
mDefaultExtension = aExtension;
|
||||
return NS_OK;
|
||||
|
@ -334,20 +332,19 @@ NS_IMETHODIMP nsFilePicker::GetDisplayDirectory(nsILocalFile **aDirectory)
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::InitNative(nsIWidget *aParent,
|
||||
const PRUnichar *aTitle,
|
||||
PRInt16 aMode)
|
||||
void nsFilePicker::InitNative(nsIWidget *aParent,
|
||||
const nsAString& aTitle,
|
||||
PRInt16 aMode)
|
||||
{
|
||||
if( aParent ) mParentWidget = (PtWidget_t *)aParent->GetNativeData(NS_NATIVE_WIDGET);
|
||||
mParentWidget = (PtWidget_t *)aParent->GetNativeData(NS_NATIVE_WIDGET);
|
||||
mTitle.SetLength(0);
|
||||
mTitle.Append(aTitle);
|
||||
mMode = aMode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter)
|
||||
nsFilePicker::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
|
||||
{
|
||||
mFilterList.Append(aFilter);
|
||||
mFilterList.Append(PRUnichar(' '));
|
||||
|
@ -376,7 +373,7 @@ void nsFilePicker::GetFileSystemCharset(nsCString & fileSystemCharset)
|
|||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
char * nsFilePicker::ConvertToFileSystemCharset(const PRUnichar *inString)
|
||||
char * nsFilePicker::ConvertToFileSystemCharset(const nsAString& inString)
|
||||
{
|
||||
char *outString = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
@ -395,15 +392,20 @@ char * nsFilePicker::ConvertToFileSystemCharset(const PRUnichar *inString)
|
|||
|
||||
// converts from unicode to the file system charset
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt32 inLength = nsCRT::strlen(inString);
|
||||
PRInt32 inLength = inString.Length();
|
||||
|
||||
const nsAFlatString& flatInString = PromiseFlatString(inString);
|
||||
|
||||
PRInt32 outLength;
|
||||
rv = mUnicodeEncoder->GetMaxLength(inString, inLength, &outLength);
|
||||
rv = mUnicodeEncoder->GetMaxLength(flatInString.get(), inLength,
|
||||
&outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString = NS_STATIC_CAST( char*, nsMemory::Alloc( outLength+1 ) );
|
||||
if (nsnull == outString) {
|
||||
return nsnull;
|
||||
}
|
||||
rv = mUnicodeEncoder->Convert(inString, &inLength, outString, &outLength);
|
||||
rv = mUnicodeEncoder->Convert(flatInString.get(), &inLength, outString,
|
||||
&outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString[outLength] = '\0';
|
||||
}
|
||||
|
|
|
@ -61,10 +61,10 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFilePicker (less what's in nsBaseFilePicker)
|
||||
NS_IMETHOD GetDefaultString(PRUnichar * *aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const PRUnichar * aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(PRUnichar * *aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const PRUnichar * aDefaultExtension);
|
||||
NS_IMETHOD GetDefaultString(nsAString& aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const nsAString& aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||
NS_IMETHOD GetDisplayDirectory(nsILocalFile * *aDisplayDirectory);
|
||||
NS_IMETHOD SetDisplayDirectory(nsILocalFile * aDisplayDirectory);
|
||||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||
|
@ -72,19 +72,18 @@ public:
|
|||
NS_IMETHOD GetFile(nsILocalFile * *aFile);
|
||||
NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
|
||||
NS_IMETHOD Show(PRInt16 *_retval);
|
||||
NS_IMETHOD AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter) ;
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
|
||||
protected:
|
||||
// method from nsBaseFilePicker
|
||||
NS_IMETHOD InitNative(nsIWidget *aParent,
|
||||
const PRUnichar *aTitle,
|
||||
PRInt16 aMode);
|
||||
virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle,
|
||||
PRInt16 aMode);
|
||||
|
||||
|
||||
void GetFilterListArray(nsString& aFilterList);
|
||||
static void GetFileSystemCharset(nsCString & fileSystemCharset);
|
||||
char * ConvertToFileSystemCharset(const PRUnichar *inString);
|
||||
char * ConvertToFileSystemCharset(const nsAString& inString);
|
||||
PRUnichar * ConvertFromFileSystemCharset(const char *inString);
|
||||
|
||||
PtWidget_t *mParentWidget;
|
||||
|
|
|
@ -70,9 +70,6 @@ char nsFilePicker::mLastUsedDirectory[MAX_PATH+1] = { 0 };
|
|||
//-------------------------------------------------------------------------
|
||||
nsFilePicker::nsFilePicker()
|
||||
{
|
||||
mParentWidget = nsnull;
|
||||
mUnicodeEncoder = nsnull;
|
||||
mUnicodeDecoder = nsnull;
|
||||
mSelectedType = 1;
|
||||
mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1");
|
||||
}
|
||||
|
@ -84,9 +81,6 @@ nsFilePicker::nsFilePicker()
|
|||
//-------------------------------------------------------------------------
|
||||
nsFilePicker::~nsFilePicker()
|
||||
{
|
||||
NS_IF_RELEASE(mParentWidget);
|
||||
NS_IF_RELEASE(mUnicodeEncoder);
|
||||
NS_IF_RELEASE(mUnicodeDecoder);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -116,7 +110,8 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
|
|||
|
||||
// suppress blur events
|
||||
if (mParentWidget) {
|
||||
nsWindow *parent = NS_STATIC_CAST(nsWindow *, mParentWidget);
|
||||
nsIWidget *tmp = mParentWidget;
|
||||
nsWindow *parent = NS_STATIC_CAST(nsWindow *, tmp);
|
||||
parent->SuppressBlurEvents(PR_TRUE);
|
||||
}
|
||||
|
||||
|
@ -124,8 +119,7 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
|
|||
PRUnichar fileBuffer[FILE_BUFFER_SIZE+1];
|
||||
wcsncpy(fileBuffer, mDefault.get(), FILE_BUFFER_SIZE);
|
||||
|
||||
nsAutoString htmExt(NS_LITERAL_STRING("html"));
|
||||
PRUnichar *title = ToNewUnicode(mTitle);
|
||||
NS_NAMED_LITERAL_STRING(htmExt, "html");
|
||||
nsAutoString initialDir;
|
||||
mDisplayDirectory->GetPath(initialDir);
|
||||
|
||||
|
@ -143,10 +137,10 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
|
|||
|
||||
BROWSEINFOW browserInfo;
|
||||
browserInfo.hwndOwner = (HWND)
|
||||
(mParentWidget ? mParentWidget->GetNativeData(NS_NATIVE_WINDOW) : 0);
|
||||
(mParentWidget.get() ? mParentWidget->GetNativeData(NS_NATIVE_WINDOW) : 0);
|
||||
browserInfo.pidlRoot = nsnull;
|
||||
browserInfo.pszDisplayName = (LPWSTR)dirBuffer;
|
||||
browserInfo.lpszTitle = title;
|
||||
browserInfo.lpszTitle = mTitle.get();
|
||||
browserInfo.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS;
|
||||
if (initialDir.Length()) // convert folder path to native, the strdup copy will be released in BrowseCallbackProc
|
||||
{
|
||||
|
@ -192,11 +186,11 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
|
|||
ofn.lpstrInitialDir = initialDir.get();
|
||||
}
|
||||
|
||||
ofn.lpstrTitle = (LPCWSTR)title;
|
||||
ofn.lpstrTitle = (LPCWSTR)mTitle.get();
|
||||
ofn.lpstrFilter = (LPCWSTR)filterBuffer.get();
|
||||
ofn.nFilterIndex = mSelectedType;
|
||||
ofn.hwndOwner = (HWND)
|
||||
(mParentWidget ? mParentWidget->GetNativeData(NS_NATIVE_WINDOW) : 0);
|
||||
(mParentWidget.get() ? mParentWidget->GetNativeData(NS_NATIVE_WINDOW) : 0);
|
||||
ofn.lpstrFile = fileBuffer;
|
||||
ofn.nMaxFile = FILE_BUFFER_SIZE;
|
||||
|
||||
|
@ -325,9 +319,6 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
|
|||
|
||||
}
|
||||
|
||||
if (title)
|
||||
nsMemory::Free( title );
|
||||
|
||||
if (result) {
|
||||
PRInt16 returnOKorReplace = returnOK;
|
||||
|
||||
|
@ -365,7 +356,8 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
|
|||
*aReturnVal = returnCancel;
|
||||
}
|
||||
if (mParentWidget) {
|
||||
nsWindow *parent = NS_STATIC_CAST(nsWindow *, mParentWidget);
|
||||
nsIWidget *tmp = mParentWidget;
|
||||
nsWindow *parent = NS_STATIC_CAST(nsWindow *, tmp);
|
||||
parent->SuppressBlurEvents(PR_FALSE);
|
||||
}
|
||||
|
||||
|
@ -423,7 +415,7 @@ NS_IMETHODIMP nsFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
|||
// Get the file + path
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const PRUnichar *aString)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultString(const nsAString& aString)
|
||||
{
|
||||
mDefault = aString;
|
||||
|
||||
|
@ -455,7 +447,7 @@ NS_IMETHODIMP nsFilePicker::SetDefaultString(const PRUnichar *aString)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultString(nsAString& aString)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -465,15 +457,13 @@ NS_IMETHODIMP nsFilePicker::GetDefaultString(PRUnichar **aString)
|
|||
// The default extension to use for files
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(PRUnichar **aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::GetDefaultExtension(nsAString& aExtension)
|
||||
{
|
||||
*aExtension = ToNewUnicode(mDefaultExtension);
|
||||
if (!*aExtension)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
aExtension = mDefaultExtension;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const PRUnichar *aExtension)
|
||||
NS_IMETHODIMP nsFilePicker::SetDefaultExtension(const nsAString& aExtension)
|
||||
{
|
||||
mDefaultExtension = aExtension;
|
||||
return NS_OK;
|
||||
|
@ -524,126 +514,27 @@ NS_IMETHODIMP nsFilePicker::GetDisplayDirectory(nsILocalFile **aDirectory)
|
|||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFilePicker::InitNative(nsIWidget *aParent,
|
||||
const PRUnichar *aTitle,
|
||||
PRInt16 aMode)
|
||||
void nsFilePicker::InitNative(nsIWidget *aParent,
|
||||
const nsAString& aTitle,
|
||||
PRInt16 aMode)
|
||||
{
|
||||
mParentWidget = aParent;
|
||||
NS_IF_ADDREF(mParentWidget);
|
||||
mTitle.Assign(aTitle);
|
||||
mMode = aMode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsFilePicker::GetFileSystemCharset(nsCString & fileSystemCharset)
|
||||
{
|
||||
static nsCAutoString aCharset;
|
||||
nsresult rv;
|
||||
|
||||
if (aCharset.Length() < 1) {
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, aCharset);
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "error getting platform charset");
|
||||
if (NS_FAILED(rv))
|
||||
aCharset.Assign(NS_LITERAL_CSTRING("windows-1252"));
|
||||
}
|
||||
fileSystemCharset = aCharset;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
char * nsFilePicker::ConvertToFileSystemCharset(const PRUnichar *inString)
|
||||
{
|
||||
char *outString = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// get file system charset and create a unicode encoder
|
||||
if (nsnull == mUnicodeEncoder) {
|
||||
nsCAutoString fileSystemCharset;
|
||||
GetFileSystemCharset(fileSystemCharset);
|
||||
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(kCharsetConverterManagerCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = ccm->GetUnicodeEncoderRaw(fileSystemCharset.get(), &mUnicodeEncoder);
|
||||
}
|
||||
}
|
||||
|
||||
// converts from unicode to the file system charset
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt32 inLength = nsCRT::strlen(inString);
|
||||
PRInt32 outLength;
|
||||
rv = mUnicodeEncoder->GetMaxLength(inString, inLength, &outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString = NS_STATIC_CAST( char*, nsMemory::Alloc( outLength+1 ) );
|
||||
if (nsnull == outString) {
|
||||
return nsnull;
|
||||
}
|
||||
rv = mUnicodeEncoder->Convert(inString, &inLength, outString, &outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString[outLength] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_SUCCEEDED(rv) ? outString : nsnull;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRUnichar * nsFilePicker::ConvertFromFileSystemCharset(const char *inString)
|
||||
{
|
||||
PRUnichar *outString = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// get file system charset and create a unicode encoder
|
||||
if (nsnull == mUnicodeDecoder) {
|
||||
nsCAutoString fileSystemCharset;
|
||||
GetFileSystemCharset(fileSystemCharset);
|
||||
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(kCharsetConverterManagerCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = ccm->GetUnicodeDecoderRaw(fileSystemCharset.get(), &mUnicodeDecoder);
|
||||
}
|
||||
}
|
||||
|
||||
// converts from the file system charset to unicode
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt32 inLength = strlen(inString);
|
||||
PRInt32 outLength;
|
||||
rv = mUnicodeDecoder->GetMaxLength(inString, inLength, &outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString = NS_STATIC_CAST( PRUnichar*, nsMemory::Alloc( (outLength+1) * sizeof( PRUnichar ) ) );
|
||||
if (nsnull == outString) {
|
||||
return nsnull;
|
||||
}
|
||||
rv = mUnicodeDecoder->Convert(inString, &inLength, outString, &outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString[outLength] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "error charset conversion");
|
||||
return NS_SUCCEEDED(rv) ? outString : nsnull;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter)
|
||||
nsFilePicker::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
|
||||
{
|
||||
mFilterList.Append(aTitle);
|
||||
mFilterList.Append(PRUnichar('\0'));
|
||||
|
||||
if (!nsCRT::strcmp(aFilter, NS_LITERAL_STRING("..apps").get()))
|
||||
if (aFilter.Equals(NS_LITERAL_STRING("..apps")))
|
||||
mFilterList.Append(NS_LITERAL_STRING("*.exe;*.com"));
|
||||
else
|
||||
{
|
||||
nsString filter;
|
||||
filter.Assign(aFilter);
|
||||
nsAutoString filter(aFilter);
|
||||
filter.StripWhitespace();
|
||||
if (filter.Equals(NS_LITERAL_STRING("*")))
|
||||
filter.Append(NS_LITERAL_STRING(".*"));
|
||||
|
|
|
@ -63,10 +63,10 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFilePicker (less what's in nsBaseFilePicker)
|
||||
NS_IMETHOD GetDefaultString(PRUnichar * *aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const PRUnichar * aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(PRUnichar * *aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const PRUnichar * aDefaultExtension);
|
||||
NS_IMETHOD GetDefaultString(nsAString& aDefaultString);
|
||||
NS_IMETHOD SetDefaultString(const nsAString& aDefaultString);
|
||||
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
|
||||
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||
NS_IMETHOD GetDisplayDirectory(nsILocalFile * *aDisplayDirectory);
|
||||
NS_IMETHOD SetDisplayDirectory(nsILocalFile * aDisplayDirectory);
|
||||
NS_IMETHOD GetFilterIndex(PRInt32 *aFilterIndex);
|
||||
|
@ -76,29 +76,24 @@ public:
|
|||
NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
|
||||
NS_IMETHOD Show(PRInt16 *aReturnVal);
|
||||
NS_IMETHOD ShowW(PRInt16 *aReturnVal);
|
||||
NS_IMETHOD AppendFilter(const PRUnichar *aTitle, const PRUnichar *aFilter) ;
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
|
||||
protected:
|
||||
/* method from nsBaseFilePicker */
|
||||
NS_IMETHOD InitNative(nsIWidget *aParent,
|
||||
const PRUnichar *aTitle,
|
||||
PRInt16 aMode);
|
||||
virtual void InitNative(nsIWidget *aParent,
|
||||
const nsAString& aTitle,
|
||||
PRInt16 aMode);
|
||||
|
||||
|
||||
void GetFilterListArray(nsString& aFilterList);
|
||||
static void GetFileSystemCharset(nsCString & fileSystemCharset);
|
||||
char * ConvertToFileSystemCharset(const PRUnichar *inString);
|
||||
PRUnichar * ConvertFromFileSystemCharset(const char *inString);
|
||||
|
||||
nsIWidget *mParentWidget;
|
||||
nsCOMPtr<nsIWidget> mParentWidget;
|
||||
nsString mTitle;
|
||||
PRInt16 mMode;
|
||||
nsCString mFile;
|
||||
nsString mDefault;
|
||||
nsString mDefaultExtension;
|
||||
nsString mFilterList;
|
||||
nsIUnicodeEncoder* mUnicodeEncoder;
|
||||
nsIUnicodeDecoder* mUnicodeDecoder;
|
||||
nsCOMPtr<nsILocalFile> mDisplayDirectory;
|
||||
PRInt16 mSelectedType;
|
||||
nsCOMPtr <nsISupportsArray> mFiles;
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIContentViewer.h"
|
||||
|
@ -74,49 +74,43 @@ nsBaseFilePicker::~nsBaseFilePicker()
|
|||
}
|
||||
|
||||
/* XXX aaaarrrrrrgh! */
|
||||
NS_IMETHODIMP nsBaseFilePicker::DOMWindowToWidget(nsIDOMWindowInternal *dw, nsIWidget **aResult)
|
||||
nsIWidget *nsBaseFilePicker::DOMWindowToWidget(nsIDOMWindow *dw)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
*aResult = nsnull;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(dw);
|
||||
if (sgo) {
|
||||
nsIDocShell *docShell = sgo->GetDocShell();
|
||||
|
||||
if (docShell) {
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
rv = docShell->GetPresShell(getter_AddRefs(presShell));
|
||||
nsresult rv = docShell->GetPresShell(getter_AddRefs(presShell));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && presShell) {
|
||||
nsIView *view;
|
||||
rv = presShell->GetViewManager()->GetRootView(view);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*aResult = view->GetWidget();
|
||||
NS_IF_ADDREF(*aResult);
|
||||
return view->GetWidget();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsBaseFilePicker::Init(nsIDOMWindowInternal *aParent,
|
||||
const PRUnichar *aTitle,
|
||||
NS_IMETHODIMP nsBaseFilePicker::Init(nsIDOMWindow *aParent,
|
||||
const nsAString& aTitle,
|
||||
PRInt16 aMode)
|
||||
{
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
nsresult rv = DOMWindowToWidget(aParent, getter_AddRefs(widget));
|
||||
NS_PRECONDITION(aParent, "Null parent passed to filepicker, no file "
|
||||
"picker for you!");
|
||||
nsIWidget *widget = DOMWindowToWidget(aParent);
|
||||
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
return InitNative(widget, aTitle, aMode);
|
||||
} else {
|
||||
return InitNative(nsnull, aTitle, aMode);
|
||||
}
|
||||
InitNative(widget, aTitle, aMode);
|
||||
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -168,7 +162,7 @@ nsBaseFilePicker::AppendFilters(PRInt32 aFilterMask)
|
|||
stringBundle->GetStringFromName(NS_LITERAL_STRING("appsTitle").get(), getter_Copies(title));
|
||||
// Pass the magic string "..apps" to the platform filepicker, which it
|
||||
// should recognize and do the correct platform behavior for.
|
||||
AppendFilter(title, NS_LITERAL_STRING("..apps").get());
|
||||
AppendFilter(title, NS_LITERAL_STRING("..apps"));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ public:
|
|||
nsBaseFilePicker();
|
||||
virtual ~nsBaseFilePicker();
|
||||
|
||||
NS_IMETHOD Init(nsIDOMWindowInternal *aParent,
|
||||
const PRUnichar *aTitle,
|
||||
NS_IMETHOD Init(nsIDOMWindow *aParent,
|
||||
const nsAString& aTitle,
|
||||
PRInt16 aMode);
|
||||
|
||||
NS_IMETHOD AppendFilters(PRInt32 filterMask);
|
||||
|
@ -62,11 +62,12 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
NS_IMETHOD InitNative(nsIWidget *aParent, const PRUnichar *aTitle, PRInt16 aMode) = 0;
|
||||
virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle,
|
||||
PRInt16 aMode) = 0;
|
||||
|
||||
private:
|
||||
|
||||
NS_IMETHOD DOMWindowToWidget(nsIDOMWindowInternal *dw, nsIWidget **aResult);
|
||||
nsIWidget *DOMWindowToWidget(nsIDOMWindow *dw);
|
||||
};
|
||||
|
||||
#endif // nsBaseFilePicker_h__
|
||||
|
|
Загрузка…
Ссылка в новой задаче