2 * \file FileDialogPrivate.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 // Too hard to make concept checks work with this file
15 #ifdef _GLIBCPP_CONCEPT_CHECKS
16 #undef _GLIBCPP_CONCEPT_CHECKS
19 #include "FileDialogPrivate.h"
21 #include "support/filefilterlist.h"
26 FileDialog::Private::Private(string const & title,
28 FileDialog::Button /*b1*/,
29 FileDialog::Button /*b2*/) :
31 fileChooser_("You shouldn't see this", Gtk::FILE_CHOOSER_ACTION_OPEN)
33 fileChooser_.set_title(title);
37 FileDialog::Result const
38 FileDialog::Private::open(string const & path,
39 lyx::support::FileFilterList const & filters,
40 string const & suggested)
42 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_OPEN);
43 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
44 fileChooser_.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
46 return showChooser(path, filters, suggested);
50 FileDialog::Result const FileDialog::Private::opendir(string const & path,
51 string const & suggested)
53 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
54 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
55 fileChooser_.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
57 return showChooser(path, lyx::support::FileFilterList(), suggested);
61 FileDialog::Result const FileDialog::Private::save(string const & path,
62 lyx::support::FileFilterList const & filters,
63 string const & suggested)
65 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_SAVE);
66 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
67 fileChooser_.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
69 return showChooser(path, filters, suggested);
73 FileDialog::Result const FileDialog::Private::showChooser(string const & path,
74 lyx::support::FileFilterList const & filters,
75 string const & suggested)
77 lyxerr[Debug::GUI] << "File Dialog with path \"" << path
78 << "\", mask \"" << filters.as_string()
79 << "\", suggested \"" << suggested << "\"\n";
81 for (lyx::support::FileFilterList::size_type i = 0; i < filters.size(); ++i) {
82 typedef lyx::support::FileFilterList::Filter::glob_iterator glob_iterator;
83 glob_iterator it = filters[i].begin();
84 glob_iterator const end = filters[i].end();
88 Gtk::FileFilter filter;
89 filter.set_name(filters[i].description());
90 for (; it != end; ++it)
91 filter.add_pattern(*it);
93 fileChooser_.add_filter(filter);
97 fileChooser_.set_filename(path);
98 fileChooser_.set_default_response(Gtk::RESPONSE_OK);
100 result.first = FileDialog::Chosen;
101 if (fileChooser_.run() == Gtk::RESPONSE_OK)
102 result.second = fileChooser_.get_filename();
104 result.second = string();