зеркало из https://github.com/mozilla/gecko-dev.git
Bug 268311 Rewrite nsIFilePicker.displayDirectory handling and (windows) nsFilePicker::ShowW
r=neil sr=neil
This commit is contained in:
Родитель
40690464a6
Коммит
33ac720268
|
@ -91,7 +91,6 @@ nsFilePicker::nsFilePicker()
|
|||
mUnicodeEncoder = nsnull;
|
||||
mUnicodeDecoder = nsnull;
|
||||
mSelectedType = 0;
|
||||
mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -142,7 +141,8 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval)
|
|||
if (nsnull == title)
|
||||
title = ToNewCString(mTitle);
|
||||
nsCAutoString initialDir;
|
||||
mDisplayDirectory->GetNativePath(initialDir);
|
||||
if (mDisplayDirectory)
|
||||
mDisplayDirectory->GetNativePath(initialDir);
|
||||
// If no display directory, re-use the last one.
|
||||
if(initialDir.IsEmpty())
|
||||
initialDir = mLastUsedDirectory;
|
||||
|
@ -167,7 +167,10 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval)
|
|||
*tempptr = '\0';
|
||||
if (filedlg.lReturn == DID_OK) {
|
||||
result = PR_TRUE;
|
||||
mDisplayDirectory->InitWithNativePath(nsDependentCString(filedlg.szFullFile));
|
||||
if (!mDisplayDirectory)
|
||||
mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1");
|
||||
if (mDisplayDirectory)
|
||||
mDisplayDirectory->InitWithNativePath(nsDependentCString(filedlg.szFullFile));
|
||||
mFile.Assign(filedlg.szFullFile);
|
||||
}
|
||||
}
|
||||
|
@ -338,9 +341,10 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval)
|
|||
if (result) {
|
||||
PRInt16 returnOKorReplace = returnOK;
|
||||
|
||||
nsresult rv;
|
||||
// Remember last used directory.
|
||||
nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1", &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
file->InitWithNativePath(mFile);
|
||||
nsCOMPtr<nsIFile> dir;
|
||||
|
@ -353,7 +357,10 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval)
|
|||
PL_strncpyz(mLastUsedDirectory, newDir.get(), MAX_PATH+1);
|
||||
// Update mDisplayDirectory with this directory, also.
|
||||
// Some callers rely on this.
|
||||
mDisplayDirectory->InitWithNativePath( nsDependentCString(mLastUsedDirectory) );
|
||||
if (!mDisplayDirectory)
|
||||
mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1");
|
||||
if (mDisplayDirectory)
|
||||
mDisplayDirectory->InitWithNativePath( nsDependentCString(mLastUsedDirectory) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,15 +67,24 @@ char nsFilePicker::mLastUsedDirectory[PATH_MAX+1] = { 0 };
|
|||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsFilePicker::nsFilePicker()
|
||||
: mParentWidget( nsnull )
|
||||
: mParentWidget(nsnull)
|
||||
, mUnicodeEncoder(nsnull)
|
||||
, mUnicodeDecoder(nsnull)
|
||||
{
|
||||
mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1");
|
||||
char *path = getenv( "HOME" );
|
||||
if( path ) {
|
||||
mDisplayDirectory->InitWithNativePath( nsDependentCString(path) );
|
||||
}
|
||||
char *path = getenv("HOME");
|
||||
if (path) {
|
||||
nsCOMPtr<nsILocalFile> displayDirectory = do_CreateInstance("@mozilla.org/file/local;1");
|
||||
if (displayDirectory) {
|
||||
nsresult rv = displayDirectory->InitWithNativePath(nsDependentCString(path));
|
||||
PRBool cond;
|
||||
if (NS_SUCCEEDED(rv) &&
|
||||
NS_SUCCEEDED(displayDirectory->Exists(&cond)) &&
|
||||
cond &&
|
||||
NS_SUCCEEDED(displayDirectory->IsDirectory(&cond)) &&
|
||||
cond)
|
||||
mDisplayDirectory = displayDirectory
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -124,17 +133,18 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *aReturnVal)
|
|||
char *title = ToNewUTF8String( mTitle );
|
||||
|
||||
nsCAutoString initialDir;
|
||||
mDisplayDirectory->GetNativePath(initialDir);
|
||||
if (mDisplayDirectory)
|
||||
mDisplayDirectory->GetNativePath(initialDir);
|
||||
// If no display directory, re-use the last one.
|
||||
if(initialDir.IsEmpty()) {
|
||||
// Allocate copy of last used dir.
|
||||
initialDir = mLastUsedDirectory;
|
||||
}
|
||||
|
||||
if( !mDefault.IsEmpty() ) {
|
||||
initialDir.AppendWithConversion( NS_LITERAL_STRING( "/" ) );
|
||||
initialDir.AppendWithConversion( mDefault );
|
||||
}
|
||||
if( !mDefault.IsEmpty() ) {
|
||||
initialDir.AppendWithConversion( NS_LITERAL_STRING( "/" ) );
|
||||
initialDir.AppendWithConversion( mDefault );
|
||||
}
|
||||
|
||||
char extensionBuffer[MAX_EXTENSION_LENGTH+1] = "*";
|
||||
if( !mFilterList.IsEmpty() ) {
|
||||
|
@ -220,10 +230,13 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *aReturnVal)
|
|||
}
|
||||
}
|
||||
|
||||
PL_strncpyz( mLastUsedDirectory, info.path, PATH_MAX+1 );
|
||||
mDisplayDirectory->InitWithNativePath( nsDependentCString(mLastUsedDirectory) );
|
||||
PL_strncpyz( mLastUsedDirectory, info.path, PATH_MAX+1 );
|
||||
if (!mDisplayDirectory)
|
||||
mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1");
|
||||
if (mDisplayDirectory)
|
||||
mDisplayDirectory->InitWithNativePath( nsDependentCString(mLastUsedDirectory) );
|
||||
|
||||
if( title ) nsMemory::Free( title );
|
||||
if( title ) nsMemory::Free( title );
|
||||
|
||||
return NS_OK;
|
||||
|
||||
|
|
|
@ -71,7 +71,6 @@ char nsFilePicker::mLastUsedDirectory[MAX_PATH+1] = { 0 };
|
|||
nsFilePicker::nsFilePicker()
|
||||
{
|
||||
mSelectedType = 1;
|
||||
mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
|
@ -221,12 +221,14 @@ NS_IMETHODIMP nsBaseFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsBaseFilePicker::SetDisplayDirectory(nsILocalFile *aDirectory)
|
||||
{
|
||||
if (mDisplayDirectory)
|
||||
return mDisplayDirectory->InitWithFile(aDirectory);
|
||||
if (!aDirectory)
|
||||
if (!aDirectory) {
|
||||
mDisplayDirectory = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsCOMPtr<nsIFile> directory;
|
||||
nsresult rv = aDirectory->Clone(getter_AddRefs(directory));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
mDisplayDirectory = do_QueryInterface(directory, &rv);
|
||||
return rv;
|
||||
}
|
||||
|
@ -238,10 +240,9 @@ NS_IMETHODIMP nsBaseFilePicker::SetDisplayDirectory(nsILocalFile *aDirectory)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsBaseFilePicker::GetDisplayDirectory(nsILocalFile **aDirectory)
|
||||
{
|
||||
if (!mDisplayDirectory) {
|
||||
*aDirectory = nsnull;
|
||||
*aDirectory = nsnull;
|
||||
if (!mDisplayDirectory)
|
||||
return NS_OK;
|
||||
}
|
||||
nsCOMPtr<nsIFile> directory;
|
||||
nsresult rv = mDisplayDirectory->Clone(getter_AddRefs(directory));
|
||||
if (NS_FAILED(rv))
|
||||
|
|
|
@ -83,14 +83,16 @@ function nsFilePicker()
|
|||
/* attributes */
|
||||
this.mDefaultString = "";
|
||||
this.mFilterIndex = 0;
|
||||
if (lastDirectory) {
|
||||
this.mDisplayDirectory = Components.classes[LOCAL_FILE_CONTRACTID].createInstance(nsILocalFile);
|
||||
this.mDisplayDirectory.initWithPath(lastDirectory);
|
||||
} else {
|
||||
this.mDisplayDirectory = null;
|
||||
}
|
||||
this.mFilterTitles = new Array();
|
||||
this.mFilters = new Array();
|
||||
this.mDisplayDirectory = null;
|
||||
if (lastDirectory) {
|
||||
try {
|
||||
var dir = Components.classes[LOCAL_FILE_CONTRACTID].createInstance(nsILocalFile);
|
||||
dir.initWithPath(lastDirectory);
|
||||
this.mDisplayDirectory = dir;
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
nsFilePicker.prototype = {
|
||||
|
|
Загрузка…
Ссылка в новой задаче