Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
nsBaseFilePicker Class Reference

#include <nsBaseFilePicker.h>

Inheritance diagram for nsBaseFilePicker:
Inheritance graph
[legend]
Collaboration diagram for nsBaseFilePicker:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsBaseFilePicker ()
virtual ~nsBaseFilePicker ()
NS_IMETHOD Init (nsIDOMWindow *aParent, const nsAString &aTitle, PRInt16 aMode)
NS_IMETHOD AppendFilters (PRInt32 filterMask)
NS_IMETHOD GetFilterIndex (PRInt32 *aFilterIndex)
NS_IMETHOD SetFilterIndex (PRInt32 aFilterIndex)
NS_IMETHOD GetFiles (nsISimpleEnumerator **aFiles)
NS_IMETHOD GetDisplayDirectory (nsILocalFile **aDisplayDirectory)
NS_IMETHOD SetDisplayDirectory (nsILocalFile *aDisplayDirectory)
void init (in nsIDOMWindow parent, in AString title, in short mode)
 Initialize the file picker widget.
void appendFilters (in long filterMask)
 Append to the filter list with things from the predefined list.
void appendFilter (in AString title, in AString filter)
 Add a filter.
short show ()
 Show File Dialog.

Public Attributes

const short modeOpen = 0
const short modeSave = 1
const short modeGetFolder = 2
const short modeOpenMultiple = 3
const short returnOK = 0
const short returnCancel = 1
const short returnReplace = 2
const long filterAll = 0x01
const long filterHTML = 0x02
const long filterText = 0x04
const long filterImages = 0x08
const long filterXML = 0x10
const long filterXUL = 0x20
const long filterApps = 0x40
attribute AString defaultString
 The filename that should be suggested to the user as a default.
attribute AString defaultExtension
 The extension that should be associated with files of the type we want to work with.
attribute long filterIndex
 The filter which is currently selected in the File Picker dialog.
attribute nsILocalFile displayDirectory
 Set the directory that the file open/save dialog initially displays.
readonly attribute nsILocalFile file
 Get the nsILocalFile for the file or directory.
readonly attribute nsIFileURL fileURL
 Get the nsIFileURL for the file or directory.
readonly attribute
nsISimpleEnumerator 
files
 Get the enumerator for the selected files only works in the modeOpenMultiple mode.

Protected Member Functions

virtual void InitNative (nsIWidget *aParent, const nsAString &aTitle, PRInt16 aMode)=0
nsIWidgetDOMWindowToWidget (nsIDOMWindow *dw)

Protected Attributes

nsCOMPtr< nsILocalFilemDisplayDirectory

Detailed Description

Definition at line 50 of file nsBaseFilePicker.h.


Constructor & Destructor Documentation

Definition at line 68 of file nsBaseFilePicker.cpp.

{

}

Definition at line 73 of file nsBaseFilePicker.cpp.

{

}

Member Function Documentation

void nsIFilePicker::appendFilter ( in AString  title,
in AString  filter 
) [inherited]

Add a filter.

Parameters:
titlename of the filter
filterextensions to filter -- semicolon and space separated

Reimplemented in nsFilePicker, and nsFilePicker.

Definition at line 128 of file nsBaseFilePicker.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIStringBundleService> stringService = do_GetService(kStringBundleServiceCID);
  nsCOMPtr<nsIStringBundle> stringBundle;

  rv = stringService->CreateBundle(FILEPICKER_PROPERTIES, getter_AddRefs(stringBundle));
  if (NS_FAILED(rv))
    return NS_ERROR_FAILURE;

  nsXPIDLString title;
  nsXPIDLString filter;

  if (aFilterMask & filterAll) {
    stringBundle->GetStringFromName(NS_LITERAL_STRING("allTitle").get(), getter_Copies(title));
    stringBundle->GetStringFromName(NS_LITERAL_STRING("allFilter").get(), getter_Copies(filter));
    AppendFilter(title,filter);
  }
  if (aFilterMask & filterHTML) {
    stringBundle->GetStringFromName(NS_LITERAL_STRING("htmlTitle").get(), getter_Copies(title));
    stringBundle->GetStringFromName(NS_LITERAL_STRING("htmlFilter").get(), getter_Copies(filter));
    AppendFilter(title,filter);
  }
  if (aFilterMask & filterText) {
    stringBundle->GetStringFromName(NS_LITERAL_STRING("textTitle").get(), getter_Copies(title));
    stringBundle->GetStringFromName(NS_LITERAL_STRING("textFilter").get(), getter_Copies(filter));
    AppendFilter(title,filter);
  }
  if (aFilterMask & filterImages) {
    stringBundle->GetStringFromName(NS_LITERAL_STRING("imageTitle").get(), getter_Copies(title));
    stringBundle->GetStringFromName(NS_LITERAL_STRING("imageFilter").get(), getter_Copies(filter));
    AppendFilter(title,filter);
  }
  if (aFilterMask & filterXML) {
    stringBundle->GetStringFromName(NS_LITERAL_STRING("xmlTitle").get(), getter_Copies(title));
    stringBundle->GetStringFromName(NS_LITERAL_STRING("xmlFilter").get(), getter_Copies(filter));
    AppendFilter(title,filter);
  }
  if (aFilterMask & filterXUL) {
    stringBundle->GetStringFromName(NS_LITERAL_STRING("xulTitle").get(), getter_Copies(title));
    stringBundle->GetStringFromName(NS_LITERAL_STRING("xulFilter").get(), getter_Copies(filter));
    AppendFilter(title, filter);
  }
  if (aFilterMask & filterApps) {
    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"));
  }
  return NS_OK;
}

Here is the call graph for this function:

void nsIFilePicker::appendFilters ( in long  filterMask) [inherited]

Append to the filter list with things from the predefined list.

Parameters:
filtersmask of filters i.e. (filterAll | filterHTML)

Definition at line 78 of file nsBaseFilePicker.cpp.

{
  nsCOMPtr<nsIWidget> widget;

  nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(dw);
  if (sgo) {
    nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(sgo->GetDocShell()));

    while (!widget && baseWin) {
      baseWin->GetParentWidget(getter_AddRefs(widget));
      if (!widget) {
        nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(baseWin));
        if (!docShellAsItem)
          return nsnull;

        nsCOMPtr<nsIDocShellTreeItem> parent;
        docShellAsItem->GetSameTypeParent(getter_AddRefs(parent));

        sgo = do_GetInterface(parent);
        if (!sgo)
          return nsnull;

        baseWin = do_QueryInterface(sgo->GetDocShell());
      }
    }
  }

  // This will return a pointer that we're about to release, but
  // that's ok since the docshell (nsIBaseWindow) holds the widget
  // alive.
  return widget.get();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 241 of file nsBaseFilePicker.cpp.

{
  *aDirectory = nsnull;
  if (!mDisplayDirectory)
    return NS_OK;
  nsCOMPtr<nsIFile> directory;
  nsresult rv = mDisplayDirectory->Clone(getter_AddRefs(directory));
  if (NS_FAILED(rv))
    return rv;
  return CallQueryInterface(directory, aDirectory);
}

Here is the call graph for this function:

Reimplemented in nsFilePicker, nsFilePicker, nsFilePicker, nsFilePicker, nsFilePicker, nsFilePicker, and nsFilePicker.

Definition at line 196 of file nsBaseFilePicker.cpp.

{
  NS_ENSURE_ARG_POINTER(aFiles);
  nsCOMPtr <nsISupportsArray> files;
  nsresult rv = NS_NewISupportsArray(getter_AddRefs(files));
  NS_ENSURE_SUCCESS(rv,rv);

  // if we get into the base class, the platform
  // doesn't implement GetFiles() yet.
  // so we fake it.
  nsCOMPtr <nsILocalFile> file;
  rv = GetFile(getter_AddRefs(file));
  NS_ENSURE_SUCCESS(rv,rv);

  rv = files->AppendElement(file);
  NS_ENSURE_SUCCESS(rv,rv);

  return NS_NewArrayEnumerator(aFiles, files);
}

Here is the call graph for this function:

Reimplemented in nsFilePicker, nsFilePicker, nsFilePicker, nsFilePicker, nsFilePicker, and nsFilePicker.

Definition at line 185 of file nsBaseFilePicker.cpp.

{
  *aFilterIndex = 0;
  return NS_OK;
}
NS_IMETHODIMP nsBaseFilePicker::Init ( nsIDOMWindow aParent,
const nsAString &  aTitle,
PRInt16  aMode 
)

Reimplemented in nsFilePicker, and nsFilePicker.

Definition at line 112 of file nsBaseFilePicker.cpp.

{
  NS_PRECONDITION(aParent, "Null parent passed to filepicker, no file "
                  "picker for you!");
  nsIWidget *widget = DOMWindowToWidget(aParent);
  NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);

  InitNative(widget, aTitle, aMode);

  return NS_OK;
}

Here is the call graph for this function:

void nsIFilePicker::init ( in nsIDOMWindow  parent,
in AString  title,
in short  mode 
) [inherited]

Initialize the file picker widget.

The file picker is not valid until this method is called.

Parameters:
parentnsIDOMWindow parent. This dialog will be dependent on this parent. parent must be non-null.
titleThe title for the file widget
modeload, save, or get folder
virtual void nsBaseFilePicker::InitNative ( nsIWidget aParent,
const nsAString &  aTitle,
PRInt16  aMode 
) [protected, pure virtual]

Implemented in nsFilePicker, nsFilePicker, nsFilePicker, nsFilePicker, nsFilePicker, nsFilePicker, and nsFilePicker.

Here is the caller graph for this function:

Definition at line 222 of file nsBaseFilePicker.cpp.

{
  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;
}

Here is the call graph for this function:

Reimplemented in nsFilePicker, nsFilePicker, nsFilePicker, nsFilePicker, nsFilePicker, and nsFilePicker.

Definition at line 191 of file nsBaseFilePicker.cpp.

{
  return NS_OK;
}
short nsIFilePicker::show ( ) [inherited]

Show File Dialog.

The dialog is displayed modally.

Returns:
returnOK if the user selects OK, returnCancel if the user selects cancel

Member Data Documentation

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.

Definition at line 109 of file nsIFilePicker.idl.

The filename that should be suggested to the user as a default.

Exceptions:
NS_ERROR_FAILUREon attempts to get

Definition at line 102 of file nsIFilePicker.idl.

Set the directory that the file open/save dialog initially displays.

Parameters:
displayDirectorythe name of the directory

Definition at line 124 of file nsIFilePicker.idl.

Get the nsILocalFile for the file or directory.

Returns:
Returns the file currently selected

Definition at line 132 of file nsIFilePicker.idl.

Get the enumerator for the selected files only works in the modeOpenMultiple mode.

Returns:
Returns the files currently selected

Definition at line 147 of file nsIFilePicker.idl.

Get the nsIFileURL for the file or directory.

Returns:
Returns the file currently selected

Definition at line 139 of file nsIFilePicker.idl.

const long nsIFilePicker::filterAll = 0x01 [inherited]

Definition at line 59 of file nsIFilePicker.idl.

const long nsIFilePicker::filterApps = 0x40 [inherited]

Definition at line 65 of file nsIFilePicker.idl.

const long nsIFilePicker::filterHTML = 0x02 [inherited]

Definition at line 60 of file nsIFilePicker.idl.

Definition at line 62 of file nsIFilePicker.idl.

The filter which is currently selected in the File Picker dialog.

Returns:
Returns the index (0 based) of the selected filter in the filter list.

Definition at line 116 of file nsIFilePicker.idl.

const long nsIFilePicker::filterText = 0x04 [inherited]

Definition at line 61 of file nsIFilePicker.idl.

const long nsIFilePicker::filterXML = 0x10 [inherited]

Definition at line 63 of file nsIFilePicker.idl.

const long nsIFilePicker::filterXUL = 0x20 [inherited]

Definition at line 64 of file nsIFilePicker.idl.

Definition at line 76 of file nsBaseFilePicker.h.

const short nsIFilePicker::modeGetFolder = 2 [inherited]

Definition at line 52 of file nsIFilePicker.idl.

const short nsIFilePicker::modeOpen = 0 [inherited]

Definition at line 50 of file nsIFilePicker.idl.

const short nsIFilePicker::modeOpenMultiple = 3 [inherited]

Definition at line 53 of file nsIFilePicker.idl.

const short nsIFilePicker::modeSave = 1 [inherited]

Definition at line 51 of file nsIFilePicker.idl.

const short nsIFilePicker::returnCancel = 1 [inherited]

Definition at line 56 of file nsIFilePicker.idl.

const short nsIFilePicker::returnOK = 0 [inherited]

Definition at line 55 of file nsIFilePicker.idl.

const short nsIFilePicker::returnReplace = 2 [inherited]

Definition at line 57 of file nsIFilePicker.idl.


The documentation for this class was generated from the following files: