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.
13 #include "FileDialog.h"
15 #include "support/lstrings.h"
16 #include <gtkmm/fileselection.h>
17 #include <gtk/gtkbutton.h>
19 #include "frontends/LyXView.h" // This is only needed while we have the xforms part!
20 #include "bufferview_funcs.h"
21 // FileDialog::Private
23 class FileDialog::Private : public SigC::Object {
25 Private(string const & title);
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);}
33 void button_clicked(bool canceled);
34 void ok_clicked() { button_clicked(false); }
35 void cancel_clicked() { button_clicked(true); }
38 Gtk::FileSelection sel_;
43 FileDialog::Private::Private(string const & title)
44 : sel_(title), modal_(false)
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));
52 string const FileDialog::Private::exec()
55 sel_.set_modal(modal_);
59 // Find if its canceled or oked and return as needed.
64 return sel_.get_filename();
67 void FileDialog::Private::button_clicked(bool canceled)
75 FileDialog::FileDialog(string const & title, kb_action a,
76 Button /*b1*/, Button /*b2*/)
77 : private_(new Private(title))
78 , title_(title), success_(a)
80 private_->set_modal(LFUN_SELECT_FILE_SYNC == a);
84 FileDialog::~FileDialog()
90 FileDialog::Result const
91 FileDialog::open(string const & path, string const & mask,
92 string const & suggested)
94 // For some reason we need to ignore the asynchronous method...
96 if (LFUN_SELECT_FILE_SYNC != success_) {
97 lyxerr << "Asynchronous file dialog." << std::endl;
100 return FileDialog::Result(Later, string());
103 lyxerr << "Synchronous file dialog." << std::endl;
105 lyxerr << "Path: " << path << "\nMask: " << mask << "\nSuggested: " << suggested << std::endl;
107 string filter = mask;
108 rsplit(mask, filter, '|');
109 private_->set_complete(mask);
110 private_->set_filename(path+suggested);
112 string const filename = private_->exec();
114 // Collect the info and return it for synchronous dialog.
115 return FileDialog::Result(Chosen, filename);
118 FileDialog::Result const
119 FileDialog::opendir(string const & path,
120 string const & suggested)
122 return open(path, "*/", suggested);
125 FileDialog::Result const FileDialog::save(string const & path, string const & mask, string const & suggested)
127 return open(path, mask, suggested);