Exemple #1
0
void Forest::importFile()
{
    Gtk::FileChooserDialog * fc = new Gtk::FileChooserDialog("Import Cal3d File");
    // fc->set_transient_for(*this);

    fc->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    fc->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);


    Gtk::FileFilter filter_cfg;
    filter_cfg.set_name("Cal3d Model files");
    filter_cfg.add_pattern("*.cfg");
    filter_cfg.add_pattern("*.cal");
    fc->add_filter(filter_cfg);

    Gtk::FileFilter filter_component;
    filter_component.set_name("Cal3d Component files");
    filter_component.add_pattern("*.caf");
    filter_component.add_pattern("*.cmf");
    filter_component.add_pattern("*.cmf");
    fc->add_filter(filter_component);

    fc->signal_response().connect(sigc::bind<Gtk::FileChooserDialog*>(sigc::mem_fun(*this, &Forest::import_response), fc));
    fc->show_all();
}
void Window::vCreateFileOpenDialog()
{
    if (m_poFileOpenDialog != NULL) {
        return;
    }

    std::string sGBDir = m_poDirConfig->sGetKey("gb_roms");
    std::string sGBADir = m_poDirConfig->sGetKey("gba_roms");

    Gtk::FileChooserDialog* poDialog = new Gtk::FileChooserDialog(*this, _("Open"));
    poDialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    poDialog->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);

    try {
        if (sGBDir != "") {
            poDialog->add_shortcut_folder(sGBDir);
            poDialog->set_current_folder(sGBDir);
        }

        if (sGBADir != "" && sGBADir != sGBDir) {
            poDialog->add_shortcut_folder(sGBADir);
            poDialog->set_current_folder(sGBADir);
        }
    } catch (const Gtk::FileChooserError& e) {
        // Most likely the shortcut already exists, so do nothing
    }

    const char* acsPattern[] = {
        // GBA
        "*.[bB][iI][nN]", "*.[aA][gG][bB]", "*.[gG][bB][aA]",
        // GB
        "*.[gG][bB]", "*.[sS][gG][bB]", "*.[cC][gG][bB]", "*.[gG][bB][cC]",
        // Both
        "*.[mM][bB]", "*.[eE][lL][fF]", "*.[zZ][iI][pP]", "*.[zZ]", "*.[gG][zZ]",
        "*.7[zZ]",
    };

#if !GTK_CHECK_VERSION(3, 0, 0)
    Gtk::FileFilter oAllGBAFilter;
    oAllGBAFilter.set_name(_("All Gameboy Advance files"));
    for (guint i = 0; i < G_N_ELEMENTS(acsPattern); i++) {
        oAllGBAFilter.add_pattern(acsPattern[i]);
    }

    Gtk::FileFilter oGBAFilter;
    oGBAFilter.set_name(_("Gameboy Advance files"));
    for (int i = 0; i < 3; i++) {
        oGBAFilter.add_pattern(acsPattern[i]);
    }

    Gtk::FileFilter oGBFilter;
    oGBFilter.set_name(_("Gameboy files"));
    for (int i = 3; i < 7; i++) {
        oGBFilter.add_pattern(acsPattern[i]);
    }
#else
    const Glib::RefPtr<Gtk::FileFilter> oAllGBAFilter = Gtk::FileFilter::create();
    oAllGBAFilter->set_name(_("All Gameboy Advance files"));
    for (guint i = 0; i < G_N_ELEMENTS(acsPattern); i++) {
        oAllGBAFilter->add_pattern(acsPattern[i]);
    }

    const Glib::RefPtr<Gtk::FileFilter> oGBAFilter = Gtk::FileFilter::create();
    oGBAFilter->set_name(_("Gameboy Advance files"));
    for (int i = 0; i < 3; i++) {
        oGBAFilter->add_pattern(acsPattern[i]);
    }

    const Glib::RefPtr<Gtk::FileFilter> oGBFilter = Gtk::FileFilter::create();
    oGBFilter->set_name(_("Gameboy files"));
    for (int i = 3; i < 7; i++) {
        oGBFilter->add_pattern(acsPattern[i]);
    }
#endif

    poDialog->add_filter(oAllGBAFilter);
    poDialog->add_filter(oGBAFilter);
    poDialog->add_filter(oGBFilter);

    m_poFileOpenDialog = poDialog;
}