]> git.lyx.org Git - features.git/blob - src/frontends/gtk/FileDialogPrivate.C
Replace LString.h with support/std_string.h,
[features.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 #include <gtkmm.h>
13
14 #include "support/std_string.h"
15
16 #include "FileDialogPrivate.h"
17
18
19 FileDialog::Private::Private(string const & title,
20                              kb_action action,
21                              FileDialog::Button b1,
22                              FileDialog::Button b2) :
23         action_(action)
24 {
25         fileSelection_.set_title(title);
26         fileSelection_.get_button_area()->children().push_back(
27                 Gtk::Box_Helpers::Element(button1_));
28         fileSelection_.get_button_area()->children().push_back(
29                 Gtk::Box_Helpers::Element(button2_));
30         button1_.signal_clicked().connect(
31                 SigC::slot(*this, &FileDialog::Private::onButton1Clicked));
32         button2_.signal_clicked().connect(
33                 SigC::slot(*this, &FileDialog::Private::onButton2Clicked));
34         if (!b1.first.empty() && !b1.second.empty()) {
35                 string::size_type pos = b1.first.find('|');
36                 button1_.set_label(
37                         Glib::locale_to_utf8(b1.first.substr(0, pos)));
38                 dir1_ = b1.second;
39                 button1_.show();
40         }
41         if (!b2.first.empty() && !b2.second.empty()) {
42                 string::size_type pos = b2.first.find('|');
43                 button2_.set_label(
44                         Glib::locale_to_utf8(b2.first.substr(0, pos)));
45                 dir2_ = b2.second;
46                 button2_.show();
47         }
48 }
49
50
51 void FileDialog::Private::onButton1Clicked()
52 {
53         fileSelection_.set_filename(dir1_);
54 }
55
56
57 void FileDialog::Private::onButton2Clicked()
58 {
59         fileSelection_.set_filename(dir2_);
60 }
61
62
63 FileDialog::Result const FileDialog::Private::open(string const & path,
64                                                    string const & /*mask*/,
65                                                    string const & /*suggested*/)
66 {
67         fileSelection_.set_filename(path);
68         fileSelection_.get_file_list()->get_parent()->show();
69         Result result;
70         result.first = FileDialog::Chosen;
71         if (fileSelection_.run() == Gtk::RESPONSE_OK)
72                 result.second = fileSelection_.get_filename();
73         else
74                 result.second = string();
75         return result;
76 }
77
78
79 FileDialog::Result const FileDialog::Private::opendir(string const & path,
80                                                       string const & /*suggested*/)
81 {
82         fileSelection_.set_filename(path);
83         fileSelection_.get_file_list()->get_parent()->hide();
84         Result result;
85         result.first = FileDialog::Chosen;
86         if (fileSelection_.run() == Gtk::RESPONSE_OK)
87                 result.second = fileSelection_.get_filename();
88         else
89                 result.second = string();
90         return result;
91 }
92
93
94 FileDialog::Result const FileDialog::Private::save(string const & path,
95                                                    string const & mask,
96                                                    string const & suggested)
97 {
98         return open(path, mask, suggested);
99 }