]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/FileDialogPrivate.C
partial compile fix
[lyx.git] / src / frontends / gtk / FileDialogPrivate.C
1 /**
2  * \file FileDialogPrivate.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Huang Ying
7  * \author John Spray
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 // Too hard to make concept checks work with this file
15 #ifdef _GLIBCXX_CONCEPT_CHECKS
16 #undef _GLIBCXX_CONCEPT_CHECKS
17 #endif
18 #ifdef _GLIBCPP_CONCEPT_CHECKS
19 #undef _GLIBCPP_CONCEPT_CHECKS
20 #endif
21
22 #include "FileDialogPrivate.h"
23
24 #include "support/filefilterlist.h"
25 #include "debug.h"
26
27 using lyx::docstring;
28
29 using std::string;
30
31 FileDialog::Private::Private(docstring const & title,
32                              kb_action action,
33                              FileDialog::Button /*b1*/,
34                              FileDialog::Button /*b2*/) :
35         action_(action),
36         fileChooser_("You shouldn't see this", Gtk::FILE_CHOOSER_ACTION_OPEN)
37 {
38         fileChooser_.set_title(lyx::to_utf8(title));
39 }
40
41
42 FileDialog::Result const
43 FileDialog::Private::open(docstring const & path,
44                           lyx::support::FileFilterList const & filters,
45                           docstring const & suggested)
46 {
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);
50
51         return showChooser(path, filters, suggested);
52 }
53
54
55 FileDialog::Result const FileDialog::Private::opendir(docstring const & path,
56                                                       docstring const & suggested)
57 {
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);
61
62         return showChooser(path, lyx::support::FileFilterList(), suggested);
63 }
64
65
66 FileDialog::Result const FileDialog::Private::save(docstring const & path,
67                                                    lyx::support::FileFilterList const & filters,
68                                                    docstring const & suggested)
69 {
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);
73
74         return showChooser(path, filters, suggested);
75 }
76
77
78 FileDialog::Result const FileDialog::Private::showChooser(docstring const & path,
79                           lyx::support::FileFilterList const & filters,
80                           docstring const & suggested)
81 {
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";
85
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();
90                 if (it == end)
91                         continue;
92
93                 Gtk::FileFilter filter;
94                 filter.set_name(lyx::to_utf8(filters[i].description()));
95                 for (; it != end; ++it)
96                         filter.add_pattern(*it);
97
98                 fileChooser_.add_filter(filter);
99         }
100
101         if (!path.empty())
102                 fileChooser_.set_current_folder(lyx::to_utf8(path));
103         if (!suggested.empty())
104                 fileChooser_.set_current_name(lyx::to_utf8(suggested));
105
106         fileChooser_.set_default_response(Gtk::RESPONSE_OK);
107         Result result;
108         result.first = FileDialog::Chosen;
109         if (fileChooser_.run() == Gtk::RESPONSE_OK)
110                 result.second = lyx::from_utf8(fileChooser_.get_filename());
111         else
112                 result.second = docstring();
113         return result;
114 }