Xfce Foundation Classes
Main Page | Index | Namespace List | Alphabetical List | Class List | File List

# Xfc::Gtk::FileChooserDialog Class Reference

A GtkFileChooserDialog C++ wrapper class. More...

`#include <xfc/gtk/filechooserdialog.hh>`

Inheritance diagram for Xfc::Gtk::FileChooserDialog:

List of all members.

## Public Member Functions

Constructors

- FileChooserDialog (const String &title, FileChooserAction action, const char *backend=0)
    Constructs a new FileChooserDialog with no parent.
- FileChooserDialog (const String &title, Window *parent, FileChooserAction action, const char *backend=0)
    Constructs a new FileChooserDialog.
- virtual ~FileChooserDialog ()
    Destructor.

Accessors

- GtkFileChooserDialog * gtk_file_chooser_dialog () const
    Get a pointer to the GtkFileChooserDialog structure.
- operator GtkFileChooserDialog * () const
    Conversion operator; safely converts an FileChooserDialog to a GtkFileChooserDialog pointer.

## Protected Member Functions

Constructors

- FileChooserDialog (GtkFileChooserDialog *dialog, bool owns_reference=false)
    Construct a new FileChooserDialog from an existing GtkFileChooserDialog.

## Detailed Description

A GtkFileChooserDialog C++ wrapper class.

FileChooserDialog is a dialog box suitable for use with "File/Open" or "File/Save as" commands. This widget works by putting a Gtk::FileChooserWidget inside a Gtk::Dialog. It exposes the Gtk::FileChooser interface, so you can use all of the Gtk::FileChooser functions on the file chooser dialog as well as those for Gtk::Dialog. To add buttons to the dialog call Gtk::Dialog::add_button().

Note that FileChooserDialog does not have any methods of its own. Instead, you should use the functions that work on a Gtk::FileChooser.

Example: Typical usage

In the simplest of cases, you can use FileChooserDialog as in the following code:

        Gtk::FileChooserDialog dialog("Open File", parent_window, Gtk::FILE_CHOOSER_ACTION_OPEN);
        dialog->add_button(Gtk::StockId::CANCEL, Gtk::RESPONSE_CANCEL);
        dialog->add_button(Gtk::StockId::OPEN, Gtk::RESPONSE_ACCEPT);

        if (dialog->run() == Gtk::RESPONSE_ACCEPT)
        {
            String filename = dialog->get_filename();
            open_file(filename.c_str());
        }

Response Codes

FileChooserDialog inherits from Gtk::Dialog, so buttons that go in its action area have response codes such as Gtk::RESPONSE_ACCEPT and Gtk::RESPONSE_CANCEL. In the above example the calls to add_button() adds stock "Cancel" and "Open" buttons that use the response indentifiers from Gtk::ResponseType. For most dialog boxes you can use your own custom response codes rather than the ones in Gtk::ResponseType, but Gtk::FileChooserDialog assumes that its "accept"-type action, e.g. an "Open" or "Save" button, will have one of the following response codes:

- Gtk::RESPONSE_ACCEPT
- Gtk::RESPONSE_OK
- Gtk::RESPONSE_YES
- Gtk::RESPONSE_APPLY

This is because Gtk::FileChooserDialog must intercept responses and switch to folders if appropriate, rather than letting the dialog terminate the implementation uses these known response codes to know which responses can be blocked if appropriate.

Note: Make sure you use a stock response code when you use Gtk::FileChooserDialog to ensure proper operation.

See also: the File Chooser HOWTO and the file chooser example in the <tests/filechooser> suddirectory.

## Constructor & Destructor Documentation

Xfc::Gtk::FileChooserDialog::FileChooserDialog | ( | GtkFileChooserDialog * | dialog,
|  | bool | owns_reference = `false`
| ) | `[explicit, protected]`

  | Construct a new FileChooserDialog from an existing GtkFileChooserDialog. Parameters:
  | dialog | A pointer to a GtkFileChooserDialog.
  | owns_reference | Set false if the initial reference count is floating, set true if it's not.
The dialog can be a newly created GtkFileChooserDialog or an existing GtkFileChooserDialog (see G::Object::Object).

Xfc::Gtk::FileChooserDialog::FileChooserDialog | ( | const String & | title,
|  | FileChooserAction | action,
|  | const char * | backend = `0`
| ) |

  | Constructs a new FileChooserDialog with no parent. Parameters:
  | title | The title of the dialog, or null.
  | action | Open or save mode for the dialog.
  | backend | The name of the specific filesystem backend to use, or null for the default.

Xfc::Gtk::FileChooserDialog::FileChooserDialog | ( | const String & | title,
|  | Window * | parent,
|  | FileChooserAction | action,
|  | const char * | backend = `0`
| ) |

  | Constructs a new FileChooserDialog. Parameters:
  | title | The title of the dialog, or null.
  | parent | The transient parent of the dialog.
  | action | Open or save mode for the dialog.
  | backend | The name of the specific filesystem backend to use, or null for the default.

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

- filechooserdialog.hh

Xfce Foundation Classes

Copyright © 2004-2005 The XFC Development Team | XFC 4.3