]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FileDialog.C
the string -> char patch
[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 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <config.h>
16 #include "FileDialog.h"
17 #include "debug.h"
18 #include "support/lstrings.h"
19 #include <gtk--/fileselection.h>
20 #include <gnome--/main.h>
21 #include <gtk/gtkbutton.h>
22
23 #include <sigc++/signal_system.h>
24
25 #include "frontends/LyXView.h" // This is only needed while we have the xforms part!
26 #include "bufferview_funcs.h"
27 // FileDialog::Private
28
29 class FileDialog::Private : public SigC::Object {
30 public:
31         Private(string const & title);
32
33         void set_modal(bool modal) { modal_ = modal; }
34         void set_complete(const string & pattern) { sel_.complete(pattern); }
35         void set_filename(const string & filename) { sel_.set_filename(filename);}
36
37         string const exec();
38
39         void button_clicked(bool canceled);
40         void ok_clicked()     { button_clicked(false); }
41         void cancel_clicked() { button_clicked(true); }
42
43 private:
44         Gtk::FileSelection sel_;
45         bool modal_;
46         bool canceled_;
47 };
48
49 FileDialog::Private::Private(string const & title)
50         : sel_(title), modal_(false)
51 {
52         sel_.get_ok_button()->clicked.connect(slot(this,
53                         &FileDialog::Private::ok_clicked));
54         sel_.get_cancel_button()->clicked.connect(slot(this,
55                         &FileDialog::Private::cancel_clicked));
56 }
57
58 string const FileDialog::Private::exec()
59 {
60         canceled_ = false;
61         sel_.set_modal(modal_);
62         sel_.show();
63         Gnome::Main::run();
64         // Find if its canceled or oked and return as needed.
65
66         if (canceled_)
67                 return string();
68         else
69                 return sel_.get_filename();
70 }
71
72 void FileDialog::Private::button_clicked(bool canceled)
73 {
74         canceled_ = canceled;
75         sel_.hide();
76         Gnome::Main::quit();
77 }
78
79 // FileDialog
80
81 FileDialog::FileDialog(LyXView * lv, string const & title, kb_action a,
82                 Button /*b1*/, Button /*b2*/)
83         : private_(new Private(title))
84         , lv_(lv), title_(title), success_(a)
85 {
86                 private_->set_modal(LFUN_SELECT_FILE_SYNC == a);
87 }
88
89
90 FileDialog::~FileDialog()
91 {
92         delete private_;
93 }
94
95
96 FileDialog::Result const
97 FileDialog::Select(string const & path, string const & mask,
98                 string const & suggested)
99 {
100         // For some reason we need to ignore the asynchronous method...
101 #if 0
102         if (LFUN_SELECT_FILE_SYNC != success_) {
103                 lyxerr << "Asynchronous file dialog." << std::endl;
104                 private_->show();
105
106                 return FileDialog::Result(Later, string());
107         }
108 #endif
109         lyxerr << "Synchronous file dialog." << std::endl;
110
111         lyxerr << "Path: " << path << "\nMask: " << mask << "\nSuggested: " << suggested << std::endl;
112
113         string filter = mask;
114         rsplit(mask, filter, '|');
115         private_->set_complete(mask);
116         private_->set_filename(path+suggested);
117
118         lv_->prohibitInput();
119         string const filename = private_->exec();
120         lv_->allowInput();
121
122         // Collect the info and return it for synchronous dialog.
123         return FileDialog::Result(Chosen, filename);
124 }