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