Adding GetFile, GetFolder and PutFile wrappers to hide widgetness of file dialogs.

git-svn-id: svn://10.0.0.236/trunk@26638 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sdagley%netscape.com 1999-04-07 00:49:38 +00:00
parent a0d9d6f73f
commit ed02f8e039
3 changed files with 91 additions and 0 deletions

View File

@ -40,6 +40,13 @@ enum nsMode {
eMode_getfolder
};
enum nsFileDlgResults {
nsFileDlgResults_Cancel, // User hit cancel, ignore selection
nsFileDlgResults_OK, // User hit Ok, process selection
nsFileDlgResults_Replace // User acknowledged file already exists so ok to replace, process selection
};
/**
* File selector widget.
* Modally selects files for loading or saving from a list.
@ -136,6 +143,20 @@ public:
NS_IMETHOD GetDisplayDirectory(nsString& aDirectory) = 0;
virtual nsFileDlgResults GetFile(
nsIWidget * aParent,
nsString & promptString, // Window title for the dialog
nsFileSpec & theFileSpec) = 0; // Populate with initial path for file dialog
virtual nsFileDlgResults GetFolder(
nsIWidget * aParent,
nsString & promptString, // Window title for the dialog
nsFileSpec & theFileSpec) = 0; // Populate with initial path for file dialog
virtual nsFileDlgResults PutFile(
nsIWidget * aParent,
nsString & promptString, // Window title for the dialog
nsFileSpec & theFileSpec) = 0; // Populate with initial path for file dialog
};
#endif // nsIFileWidget_h__

View File

@ -248,6 +248,11 @@ nsFileWidget :: PutFile ( Str255 & inTitle, Str255 & inDefaultName, FSSpec* outS
if (anErr == noErr) {
*outSpec = theFSSpec; // Return the FSSpec
if (reply.replacing)
mSelectResult = nsFileDlgResults_Replace;
else
mSelectResult = nsFileDlgResults_OK;
// Some housekeeping for Nav Services
::NavCompleteSave(&reply, kNavTranslateInPlace);
::NavDisposeReply(&reply);
@ -314,6 +319,7 @@ nsFileWidget :: GetFile ( Str255 & inTitle, /* filter list here later */ FSSpec*
if (anErr == noErr) {
*outSpec = theFSSpec; // Return the FSSpec
mSelectResult = nsFileDlgResults_OK;
// Some housekeeping for Nav Services
::NavDisposeReply(&reply);
@ -377,6 +383,7 @@ nsFileWidget :: GetFolder ( Str255 & inTitle, FSSpec* outSpec )
if (anErr == noErr) {
*outSpec = theFSSpec; // Return the FSSpec
mSelectResult = nsFileDlgResults_OK;
// Some housekeeping for Nav Services
::NavDisposeReply(&reply);
@ -486,6 +493,51 @@ NS_METHOD nsFileWidget::GetDisplayDirectory(nsString& aDirectory)
}
nsFileDlgResults nsFileWidget::GetFile(
nsIWidget * aParent,
nsString & promptString,
nsFileSpec & theFileSpec)
{
Create(aParent, promptString, eMode_load, nsnull, nsnull);
if (Show() == PR_TRUE)
{
theFileSpec = mFileSpec;
return mSelectResult;
}
return nsFileDlgResults_Cancel;
}
nsFileDlgResults nsFileWidget::GetFolder(
nsIWidget * aParent,
nsString & promptString,
nsFileSpec & theFileSpec)
{
Create(aParent, promptString, eMode_getfolder, nsnull, nsnull);
if (Show() == PR_TRUE)
{
theFileSpec = mFileSpec;
return mSelectResult;
}
return nsFileDlgResults_Cancel;
}
nsFileDlgResults nsFileWidget::PutFile(
nsIWidget * aParent,
nsString & promptString,
nsFileSpec & theFileSpec)
{
Create(aParent, promptString, eMode_save, nsnull, nsnull);
if (Show() == PR_TRUE)
{
theFileSpec = mFileSpec;
return mSelectResult;
}
return nsFileDlgResults_Cancel;
}
//-------------------------------------------------------------------------
//
// nsFileWidget destructor

View File

@ -77,6 +77,23 @@ class nsFileWidget : public nsWindow, public nsIFileWidget
NS_IMETHOD GetDisplayDirectory(nsString& aDirectory);
NS_IMETHOD SetDisplayDirectory(nsString& aDirectory);
virtual nsFileDlgResults GetFile(
nsIWidget * aParent,
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
nsFileSpec & theFileSpec); // Populate with initial path for file dialog
virtual nsFileDlgResults PutFile(
nsIWidget * aParent,
nsString & promptString, // Window title for the dialog
nsFileSpec & theFileSpec); // Populate with initial path for file dialog
protected:
NS_IMETHOD OnOk();
NS_IMETHOD OnCancel();
@ -98,6 +115,7 @@ class nsFileWidget : public nsWindow, public nsIFileWidget
nsString mDefault;
nsString mDisplayDirectory;
nsFileSpec mFileSpec;
nsFileDlgResults mSelectResult;
void GetFilterListArray(nsString& aFilterList);