]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FileDialog.C
Minipage is no more (long live the box inset)
[lyx.git] / src / frontends / gnome / FileDialog.C
1 /**
2  * \file gnome/FileDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Baruch Even
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11
12 #include <config.h>
13 #include "FileDialog.h"
14 #include "debug.h"
15 #include "support/lstrings.h"
16 #include <gtkmm/fileselection.h>
17 #include <gtk/gtkbutton.h>
18
19 #include "frontends/LyXView.h" // This is only needed while we have the xforms part!
20 #include "bufferview_funcs.h"
21 // FileDialog::Private
22
23 class FileDialog::Private : public SigC::Object {
24 public:
25         Private(string const & title);
26
27         void set_modal(bool modal) { modal_ = modal; }
28         void set_complete(string const & pattern) { sel_.complete(pattern); }
29         void set_filename(string const & filename) { sel_.set_filename(filename);}
30
31         string const exec();
32
33         void button_clicked(bool canceled);
34         void ok_clicked()     { button_clicked(false); }
35         void cancel_clicked() { button_clicked(true); }
36
37 private:
38         Gtk::FileSelection sel_;
39         bool modal_;
40         bool canceled_;
41 };
42
43 FileDialog::Private::Private(string const & title)
44         : sel_(title), modal_(false)
45 {
46         sel_.get_ok_button()->signal_clicked().connect(slot(*this,
47                         &FileDialog::Private::ok_clicked));
48         sel_.get_cancel_button()->signal_clicked().connect(slot(*this,
49                         &FileDialog::Private::cancel_clicked));
50 }
51
52 string const FileDialog::Private::exec()
53 {
54         canceled_ = false;
55         sel_.set_modal(modal_);
56         sel_.show();
57
58         sel_.run();
59         // Find if its canceled or oked and return as needed.
60
61         if (canceled_)
62                 return string();
63         else
64                 return sel_.get_filename();
65 }
66
67 void FileDialog::Private::button_clicked(bool canceled)
68 {
69         canceled_ = canceled;
70         sel_.hide();
71 }
72
73 // FileDialog
74
75 FileDialog::FileDialog(string const & title, kb_action a,
76                 Button /*b1*/, Button /*b2*/)
77         : private_(new Private(title))
78         , title_(title), success_(a)
79 {
80                 private_->set_modal(LFUN_SELECT_FILE_SYNC == a);
81 }
82
83
84 FileDialog::~FileDialog()
85 {
86         delete private_;
87 }
88
89
90 FileDialog::Result const
91 FileDialog::open(string const & path, string const & mask,
92                 string const & suggested)
93 {
94         // For some reason we need to ignore the asynchronous method...
95 #if 0
96         if (LFUN_SELECT_FILE_SYNC != success_) {
97                 lyxerr << "Asynchronous file dialog." << std::endl;
98                 private_->show();
99
100                 return FileDialog::Result(Later, string());
101         }
102 #endif
103         lyxerr << "Synchronous file dialog." << std::endl;
104
105         lyxerr << "Path: " << path << "\nMask: " << mask << "\nSuggested: " << suggested << std::endl;
106
107         string filter = mask;
108         rsplit(mask, filter, '|');
109         private_->set_complete(mask);
110         private_->set_filename(path+suggested);
111
112         string const filename = private_->exec();
113
114         // Collect the info and return it for synchronous dialog.
115         return FileDialog::Result(Chosen, filename);
116 }
117
118 FileDialog::Result const
119 FileDialog::opendir(string const & path,
120                 string const & suggested)
121 {
122         return open(path, "*/", suggested);
123 }
124
125 FileDialog::Result const FileDialog::save(string const & path, string const & mask, string const & suggested)
126 {
127         return open(path, mask, suggested);
128 }