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.
8 * Full author contact details are available in file CREDITS
12 #pragma implementation
16 #include "FileDialog.h"
18 #include "support/lstrings.h"
19 #include <gtk--/fileselection.h>
20 #include <gnome--/main.h>
21 #include <gtk/gtkbutton.h>
23 #include <sigc++/signal_system.h>
25 #include "frontends/LyXView.h" // This is only needed while we have the xforms part!
26 #include "bufferview_funcs.h"
27 // FileDialog::Private
29 class FileDialog::Private : public SigC::Object {
31 Private(string const & title);
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);}
39 void button_clicked(bool canceled);
40 void ok_clicked() { button_clicked(false); }
41 void cancel_clicked() { button_clicked(true); }
44 Gtk::FileSelection sel_;
49 FileDialog::Private::Private(string const & title)
50 : sel_(title), modal_(false)
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));
58 string const FileDialog::Private::exec()
61 sel_.set_modal(modal_);
64 // Find if its canceled or oked and return as needed.
69 return sel_.get_filename();
72 void FileDialog::Private::button_clicked(bool canceled)
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)
86 private_->set_modal(LFUN_SELECT_FILE_SYNC == a);
90 FileDialog::~FileDialog()
96 FileDialog::Result const
97 FileDialog::Select(string const & path, string const & mask,
98 string const & suggested)
100 // For some reason we need to ignore the asynchronous method...
102 if (LFUN_SELECT_FILE_SYNC != success_) {
103 lyxerr << "Asynchronous file dialog." << std::endl;
106 return FileDialog::Result(Later, string());
109 lyxerr << "Synchronous file dialog." << std::endl;
111 lyxerr << "Path: " << path << "\nMask: " << mask << "\nSuggested: " << suggested << std::endl;
113 string filter = mask;
114 rsplit(mask, filter, '|');
115 private_->set_complete(mask);
116 private_->set_filename(path+suggested);
118 lv_->prohibitInput();
119 string const filename = private_->exec();
122 // Collect the info and return it for synchronous dialog.
123 return FileDialog::Result(Chosen, filename);