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 _GLIBCXX_CONCEPT_CHECKS
16 #undef _GLIBCXX_CONCEPT_CHECKS
18 #ifdef _GLIBCPP_CONCEPT_CHECKS
19 #undef _GLIBCPP_CONCEPT_CHECKS
22 #include "FileDialogPrivate.h"
24 #include "support/filefilterlist.h"
31 FileDialog::Private::Private(docstring const & title,
33 FileDialog::Button /*b1*/,
34 FileDialog::Button /*b2*/) :
36 fileChooser_("You shouldn't see this", Gtk::FILE_CHOOSER_ACTION_OPEN)
38 fileChooser_.set_title(lyx::to_utf8(title));
42 FileDialog::Result const
43 FileDialog::Private::open(docstring const & path,
44 lyx::support::FileFilterList const & filters,
45 docstring const & suggested)
47 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_OPEN);
48 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
49 fileChooser_.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
51 return showChooser(path, filters, suggested);
55 FileDialog::Result const FileDialog::Private::opendir(docstring const & path,
56 docstring const & suggested)
58 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
59 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
60 fileChooser_.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
62 return showChooser(path, lyx::support::FileFilterList(), suggested);
66 FileDialog::Result const FileDialog::Private::save(docstring const & path,
67 lyx::support::FileFilterList const & filters,
68 docstring const & suggested)
70 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_SAVE);
71 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
72 fileChooser_.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
74 return showChooser(path, filters, suggested);
78 FileDialog::Result const FileDialog::Private::showChooser(docstring const & path,
79 lyx::support::FileFilterList const & filters,
80 docstring const & suggested)
82 lyxerr[Debug::GUI] << "File Dialog with path \"" << lyx::to_utf8(path)
83 << "\", mask \"" << lyx::to_utf8(filters.as_string())
84 << "\", suggested \"" << lyx::to_utf8(suggested) << "\"\n";
86 for (lyx::support::FileFilterList::size_type i = 0; i < filters.size(); ++i) {
87 typedef lyx::support::FileFilterList::Filter::glob_iterator glob_iterator;
88 glob_iterator it = filters[i].begin();
89 glob_iterator const end = filters[i].end();
93 Gtk::FileFilter filter;
94 filter.set_name(lyx::to_utf8(filters[i].description()));
95 for (; it != end; ++it)
96 filter.add_pattern(*it);
98 fileChooser_.add_filter(filter);
102 fileChooser_.set_current_folder(lyx::to_utf8(path));
103 if (!suggested.empty())
104 fileChooser_.set_current_name(lyx::to_utf8(suggested));
106 fileChooser_.set_default_response(Gtk::RESPONSE_OK);
108 result.first = FileDialog::Chosen;
109 if (fileChooser_.run() == Gtk::RESPONSE_OK)
110 result.second = lyx::from_utf8(fileChooser_.get_filename());
112 result.second = docstring();