ocarina/ocarina/chooser.cpp

38 lines
782 B
C++

#include <ocarina/gtk.h>
#include <ocarina/chooser.h>
namespace ocarina
{
static string generic_chooser(GtkFileChooserAction action)
{
GtkWidget *chooser = gtk_file_chooser_dialog_new(
"Open File", NULL, action,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
char *c_file;
string filename = "";
if ( gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_ACCEPT) {
c_file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser));
filename = c_file;
g_free(c_file);
}
gtk_widget_destroy(chooser);
return filename;
}
string choose_file()
{
return generic_chooser(GTK_FILE_CHOOSER_ACTION_OPEN);
}
string choose_dir()
{
return generic_chooser(GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
}
};