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"
34 FileDialog::Private::Private(docstring const & title,
36 FileDialog::Button /*b1*/,
37 FileDialog::Button /*b2*/) :
39 fileChooser_("You shouldn't see this", Gtk::FILE_CHOOSER_ACTION_OPEN)
41 fileChooser_.set_title(lyx::to_utf8(title));
45 FileDialog::Result const
46 FileDialog::Private::open(docstring const & path,
47 lyx::support::FileFilterList const & filters,
48 docstring const & suggested)
50 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_OPEN);
51 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
52 fileChooser_.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
54 return showChooser(path, filters, suggested);
58 FileDialog::Result const FileDialog::Private::opendir(docstring const & path,
59 docstring const & suggested)
61 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
62 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
63 fileChooser_.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
65 return showChooser(path, lyx::support::FileFilterList(), suggested);
69 FileDialog::Result const FileDialog::Private::save(docstring const & path,
70 lyx::support::FileFilterList const & filters,
71 docstring const & suggested)
73 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_SAVE);
74 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
75 fileChooser_.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
77 return showChooser(path, filters, suggested);
81 FileDialog::Result const FileDialog::Private::showChooser(docstring const & path,
82 lyx::support::FileFilterList const & filters,
83 docstring const & suggested)
85 lyxerr[Debug::GUI] << "File Dialog with path \"" << lyx::to_utf8(path)
86 << "\", mask \"" << lyx::to_utf8(filters.as_string())
87 << "\", suggested \"" << lyx::to_utf8(suggested) << "\"\n";
89 for (lyx::support::FileFilterList::size_type i = 0; i < filters.size(); ++i) {
90 typedef lyx::support::FileFilterList::Filter::glob_iterator glob_iterator;
91 glob_iterator it = filters[i].begin();
92 glob_iterator const end = filters[i].end();
96 Gtk::FileFilter filter;
97 filter.set_name(lyx::to_utf8(filters[i].description()));
98 for (; it != end; ++it)
99 filter.add_pattern(*it);
101 fileChooser_.add_filter(filter);
105 fileChooser_.set_current_folder(lyx::to_utf8(path));
106 if (!suggested.empty())
107 fileChooser_.set_current_name(lyx::to_utf8(suggested));
109 fileChooser_.set_default_response(Gtk::RESPONSE_OK);
111 result.first = FileDialog::Chosen;
112 if (fileChooser_.run() == Gtk::RESPONSE_OK)
113 result.second = lyx::from_utf8(fileChooser_.get_filename());
115 result.second = docstring();