Tutorial

Inti Logo

« Color Selection
 Font Selection »

File Selections

The file selection widget is a quick and simple way to display a File dialog box. It comes complete with Ok, Cancel, and Help buttons, a great way to cut down on programming time.

To create a new file selection box use one of the following constructors:

FileSelection();

explicit FileSelection(const String& title);

Both constructors create a FileSelectionDialog, the first with the default title which is just the program name and the second with the title specified.

To set the filename, for example to bring up a specific directory, or give a default filename, use this method:

void set_filename(const String& filename);

To grab the text that the user has entered or clicked on, use this method:

String get_filename() const;

There are also accessors that return a pointer to the corresponding widget contained within the file selection widget. These are:

Gtk::Entry* selection_entry() const;

Gtk::Label* selection_text() const;

Gtk::Button* ok_button() const;

Gtk::Button* cancel_button() const;

Gtk::Button* help_button() const;

Most likely you will want to use the ok_button(), cancel_button(), and help_button() accessors for signal connection.

Here is an example of a FileSelection widget modified to run on its own. As you will see, there is nothing much to creating a file selection widget. In this example the Help button is hidden.

File Selection

The header file for File selection is filesel.h

#include<inti/main.h>
#include <inti/gtk/fileselection.h>

using namespace Inti;

class FileSelection : public Gtk::FileSelection
{
protected:
    void on_ok();

public:
    FileSelection();
    virtual ~FileSelection();
};

and the source file is filesel.cc

#include"filesel.h"
#include <inti/gtk/button.h>
#include <iostream>


FileSelection::FileSelection()
: Gtk::FileSelection("File selection")
{
    ok_button()->sig_clicked().connect(slot(this, &FileSelection::on_ok));
    cancel_button()->sig_clicked().connect(slot(this, &FileSelection::dispose));

    // Lets set the filename, as if this were a save dialog, and we are giving a default filename.
    set_filename("penguin.png");
}

FileSelection::~FileSelection()
{
}

void
FileSelection::on_ok()
{
    std::cout << get_filename().c_str() << '\n';
}

INTI_MAIN(FileSelection)



« Color Selection Index
Miscellaneous Widgets
Top
Font Selection  »