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 <gtkmm/fileselection.h>
20 #include <gtk/gtkbutton.h>
22 #include "frontends/LyXView.h" // This is only needed while we have the xforms part!
23 #include "bufferview_funcs.h"
24 // FileDialog::Private
26 class FileDialog::Private : public SigC::Object {
28 Private(string const & title);
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);}
36 void button_clicked(bool canceled);
37 void ok_clicked() { button_clicked(false); }
38 void cancel_clicked() { button_clicked(true); }
41 Gtk::FileSelection sel_;
46 FileDialog::Private::Private(string const & title)
47 : sel_(title), modal_(false)
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));
55 string const FileDialog::Private::exec()
58 sel_.set_modal(modal_);
62 // Find if its canceled or oked and return as needed.
67 return sel_.get_filename();
70 void FileDialog::Private::button_clicked(bool canceled)
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)
83 private_->set_modal(LFUN_SELECT_FILE_SYNC == a);
87 FileDialog::~FileDialog()
93 FileDialog::Result const
94 FileDialog::open(string const & path, string const & mask,
95 string const & suggested)
97 // For some reason we need to ignore the asynchronous method...
99 if (LFUN_SELECT_FILE_SYNC != success_) {
100 lyxerr << "Asynchronous file dialog." << std::endl;
103 return FileDialog::Result(Later, string());
106 lyxerr << "Synchronous file dialog." << std::endl;
108 lyxerr << "Path: " << path << "\nMask: " << mask << "\nSuggested: " << suggested << std::endl;
110 string filter = mask;
111 rsplit(mask, filter, '|');
112 private_->set_complete(mask);
113 private_->set_filename(path+suggested);
115 lv_->prohibitInput();
116 string const filename = private_->exec();
119 // Collect the info and return it for synchronous dialog.
120 return FileDialog::Result(Chosen, filename);
123 FileDialog::Result const
124 FileDialog::opendir(string const & path,
125 string const & suggested)
127 return open(path, "*/", suggested);
130 FileDialog::Result const FileDialog::save(string const & path, string const & mask, string const & suggested)
132 return open(path, mask, suggested);