]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/FileDialogPrivate.C
Change glob() API to accept a dir parameter.
[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  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCPP_CONCEPT_CHECKS
15 #undef _GLIBCPP_CONCEPT_CHECKS
16 #endif
17
18 #include "FileDialogPrivate.h"
19
20 using std::string;
21
22
23 FileDialog::Private::Private(string const & title,
24                              kb_action action,
25                              FileDialog::Button /*b1*/,
26                              FileDialog::Button /*b2*/) :
27         action_(action)
28 {
29         fileSelection_.set_title(title);
30 /*      fileSelection_.get_button_area()->children().push_back(
31                 Gtk::Box_Helpers::Element(button1_));
32         fileSelection_.get_button_area()->children().push_back(
33                 Gtk::Box_Helpers::Element(button2_));
34         button1_.signal_clicked().connect(
35                 sigc::mem_fun(*this, &FileDialog::Private::onButton1Clicked));
36         button2_.signal_clicked().connect(
37         sigc::mem_fun(*this, &FileDialog::Private::onButton2Clicked));
38         if (!b1.first.empty() && !b1.second.empty()) {
39                 string::size_type pos = b1.first.find('|');
40                 button1_.set_label(
41                         Glib::locale_to_utf8(b1.first.substr(0, pos)));
42                 dir1_ = b1.second;
43                 button1_.show();
44         }
45         if (!b2.first.empty() && !b2.second.empty()) {
46                 string::size_type pos = b2.first.find('|');
47                 button2_.set_label(
48                         Glib::locale_to_utf8(b2.first.substr(0, pos)));
49                 dir2_ = b2.second;
50                 button2_.show();
51         }*/
52 }
53
54
55 void FileDialog::Private::onButton1Clicked()
56 {
57         fileSelection_.set_filename(dir1_);
58 }
59
60
61 void FileDialog::Private::onButton2Clicked()
62 {
63         fileSelection_.set_filename(dir2_);
64 }
65
66
67 FileDialog::Result const
68 FileDialog::Private::open(string const & path,
69                           lyx::support::FileFilterList const & /*filters*/,
70                           string const & /*suggested*/)
71 {
72         fileSelection_.set_filename(path);
73         fileSelection_.get_file_list()->get_parent()->show();
74         Result result;
75         result.first = FileDialog::Chosen;
76         if (fileSelection_.run() == Gtk::RESPONSE_OK)
77                 result.second = fileSelection_.get_filename();
78         else
79                 result.second = string();
80         return result;
81 }
82
83
84 FileDialog::Result const FileDialog::Private::opendir(string const & path,
85                                                       string const & /*suggested*/)
86 {
87         fileSelection_.set_filename(path);
88         fileSelection_.get_file_list()->get_parent()->hide();
89         Result result;
90         result.first = FileDialog::Chosen;
91         if (fileSelection_.run() == Gtk::RESPONSE_OK)
92                 result.second = fileSelection_.get_filename();
93         else
94                 result.second = string();
95         return result;
96 }
97
98
99 FileDialog::Result const FileDialog::Private::save(string const & path,
100                                                    lyx::support::FileFilterList const & filters,
101                                                    string const & suggested)
102 {
103         return open(path, filters, suggested);
104 }