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"
29 FileDialog::Private::Private(string const & title,
31 FileDialog::Button /*b1*/,
32 FileDialog::Button /*b2*/) :
34 fileChooser_("You shouldn't see this", Gtk::FILE_CHOOSER_ACTION_OPEN)
36 fileChooser_.set_title(title);
40 FileDialog::Result const
41 FileDialog::Private::open(string const & path,
42 lyx::support::FileFilterList const & filters,
43 string const & suggested)
45 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_OPEN);
46 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
47 fileChooser_.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
49 return showChooser(path, filters, suggested);
53 FileDialog::Result const FileDialog::Private::opendir(string const & path,
54 string const & suggested)
56 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
57 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
58 fileChooser_.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
60 return showChooser(path, lyx::support::FileFilterList(), suggested);
64 FileDialog::Result const FileDialog::Private::save(string const & path,
65 lyx::support::FileFilterList const & filters,
66 string const & suggested)
68 fileChooser_.set_action(Gtk::FILE_CHOOSER_ACTION_SAVE);
69 fileChooser_.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
70 fileChooser_.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
72 return showChooser(path, filters, suggested);
76 FileDialog::Result const FileDialog::Private::showChooser(string const & path,
77 lyx::support::FileFilterList const & filters,
78 string const & suggested)
80 lyxerr[Debug::GUI] << "File Dialog with path \"" << path
81 << "\", mask \"" << filters.as_string()
82 << "\", suggested \"" << suggested << "\"\n";
84 for (lyx::support::FileFilterList::size_type i = 0; i < filters.size(); ++i) {
85 typedef lyx::support::FileFilterList::Filter::glob_iterator glob_iterator;
86 glob_iterator it = filters[i].begin();
87 glob_iterator const end = filters[i].end();
91 Gtk::FileFilter filter;
92 filter.set_name(filters[i].description());
93 for (; it != end; ++it)
94 filter.add_pattern(*it);
96 fileChooser_.add_filter(filter);
100 fileChooser_.set_current_folder(path);
101 if (!suggested.empty())
102 fileChooser_.set_current_name(suggested);
104 fileChooser_.set_default_response(Gtk::RESPONSE_OK);
106 result.first = FileDialog::Chosen;
107 if (fileChooser_.run() == Gtk::RESPONSE_OK)
108 result.second = fileChooser_.get_filename();
110 result.second = string();