Fixed file widget to use filespec, instead of string. Made input params const.

This commit is contained in:
mcmullen%netscape.com 1999-05-15 22:54:17 +00:00
Родитель 5d5155d733
Коммит db38deab4b
3 изменённых файлов: 20 добавлений и 37 удалений

Просмотреть файл

@ -98,8 +98,8 @@ PRBool nsFileWidget::Show()
GetFilterListArray(filterList);
char *filterBuffer = filterList.ToNewCString();
char *title = mTitle.ToNewCString();
char *initialDir = mDisplayDirectory.ToNewCString();
if (mDisplayDirectory.Length() > 0) {
const char *initialDir = mDisplayDirectory.GetNativePathCString();
if (initialDir && *initialDir) {
ofn.lpstrInitialDir = initialDir;
}
@ -129,14 +129,12 @@ PRBool nsFileWidget::Show()
// Store the current directory in mDisplayDirectory
char* newCurrentDirectory = new char[MAX_PATH+1];
VERIFY(::GetCurrentDirectory(MAX_PATH, newCurrentDirectory) > 0);
mDisplayDirectory.SetLength(0);
mDisplayDirectory.Append(newCurrentDirectory);
mDisplayDirectory = newCurrentDirectory;
delete[] newCurrentDirectory;
// Clean up filter buffers
delete[] filterBuffer;
delete[] title;
delete[] initialDir;
// Set user-selected location of file or directory
mFile.SetLength(0);
@ -182,19 +180,6 @@ NS_IMETHODIMP nsFileWidget::SetFilterList(PRUint32 aNumberOfFilters,const nsStri
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get the file + path
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFileWidget::GetFile(nsString& aFile)
{
aFile.SetLength(0);
aFile.Append(mFile);
return NS_OK;
}
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
@ -214,7 +199,7 @@ NS_METHOD nsFileWidget::GetFile(nsFileSpec& aFile)
// Get the file + path
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFileWidget::SetDefaultString(nsString& aString)
NS_IMETHODIMP nsFileWidget::SetDefaultString(const nsString& aString)
{
mDefault = aString;
return NS_OK;
@ -226,7 +211,7 @@ NS_IMETHODIMP nsFileWidget::SetDefaultString(nsString& aString)
// Set the display directory
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFileWidget::SetDisplayDirectory(nsString& aDirectory)
NS_IMETHODIMP nsFileWidget::SetDisplayDirectory(const nsFileSpec& aDirectory)
{
mDisplayDirectory = aDirectory;
return NS_OK;
@ -238,7 +223,7 @@ NS_IMETHODIMP nsFileWidget::SetDisplayDirectory(nsString& aDirectory)
// Get the display directory
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFileWidget::GetDisplayDirectory(nsString& aDirectory)
NS_IMETHODIMP nsFileWidget::GetDisplayDirectory(nsFileSpec& aDirectory)
{
aDirectory = mDisplayDirectory;
return NS_OK;
@ -247,7 +232,7 @@ NS_IMETHODIMP nsFileWidget::GetDisplayDirectory(nsString& aDirectory)
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFileWidget::Create(nsIWidget *aParent,
nsString& aTitle,
const nsString& aTitle,
nsFileDlgMode aMode,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
@ -263,7 +248,7 @@ NS_IMETHODIMP nsFileWidget::Create(nsIWidget *aParent,
//-------------------------------------------------------------------------
nsFileDlgResults nsFileWidget::GetFile(nsIWidget * aParent,
nsString & promptString,
const nsString & promptString,
nsFileSpec & theFileSpec)
{
Create(aParent, promptString, eMode_load, nsnull, nsnull);
@ -280,7 +265,7 @@ nsFileDlgResults nsFileWidget::GetFile(nsIWidget * aParent,
//-------------------------------------------------------------------------
nsFileDlgResults nsFileWidget::GetFolder(nsIWidget * aParent,
nsString & promptString,
const nsString & promptString,
nsFileSpec & theFileSpec)
{
Create(aParent, promptString, eMode_load, nsnull, nsnull);
@ -318,7 +303,7 @@ nsFileDlgResults nsFileWidget::GetFolder(nsIWidget * aParent,
//-------------------------------------------------------------------------
nsFileDlgResults nsFileWidget::PutFile(nsIWidget * aParent,
nsString & promptString,
const nsString & promptString,
nsFileSpec & theFileSpec)
{
Create(aParent, promptString, eMode_load, nsnull, nsnull);

Просмотреть файл

@ -40,7 +40,7 @@ class nsFileWidget : public nsIFileWidget
// nsIWidget interface
NS_IMETHOD Create( nsIWidget *aParent,
nsString& aTitle,
const nsString& aTitle,
nsFileDlgMode aMode,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
@ -49,26 +49,25 @@ class nsFileWidget : public nsIFileWidget
// nsIFileWidget part
virtual PRBool Show();
NS_IMETHOD GetFile(nsString& aFile);
NS_IMETHOD GetFile(nsFileSpec& aFile);
NS_IMETHOD SetDefaultString(nsString& aFile);
NS_IMETHOD SetDefaultString(const nsString& aFile);
NS_IMETHOD SetFilterList(PRUint32 aNumberOfFilters,const nsString aTitles[],const nsString aFilters[]);
NS_IMETHOD GetDisplayDirectory(nsString& aDirectory);
NS_IMETHOD SetDisplayDirectory(nsString& aDirectory);
NS_IMETHOD GetDisplayDirectory(nsFileSpec& aDirectory);
NS_IMETHOD SetDisplayDirectory(const nsFileSpec& aDirectory);
virtual nsFileDlgResults GetFile(
nsIWidget * aParent,
nsString & promptString, // Window title for the dialog
const nsString & promptString, // Window title for the dialog
nsFileSpec & theFileSpec); // Populate with initial path for file dialog
virtual nsFileDlgResults GetFolder(
nsIWidget * aParent,
nsString & promptString, // Window title for the dialog
const nsString & promptString, // Window title for the dialog
nsFileSpec & theFileSpec); // Populate with initial path for file dialog
virtual nsFileDlgResults PutFile(
nsIWidget * aParent,
nsString & promptString, // Window title for the dialog
const nsString & promptString, // Window title for the dialog
nsFileSpec & theFileSpec); // Populate with initial path for file dialog
protected:
@ -81,7 +80,7 @@ class nsFileWidget : public nsIFileWidget
const nsString* mTitles;
const nsString* mFilters;
nsString mDefault;
nsString mDisplayDirectory;
nsFileSpec mDisplayDirectory;
void GetFilterListArray(nsString& aFilterList);

Просмотреть файл

@ -1042,12 +1042,11 @@ nsEventStatus PR_CALLBACK HandleFileButtonEvent(nsGUIEvent *aEvent)
PRUint32 result = fileWidget->Show();
if (result) {
nsString file;
nsFileSpec file;
fileWidget->GetFile(file);
char* filestr = file.ToNewCString();
const char* filestr = file.GetNativePathCString();
printf("file widget contents %s\n", filestr);
statusText->SetText(filestr,actualSize);
delete[] filestr;
}
else
statusText->SetText("Cancel selected",actualSize);