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