2 /* This file is part of
3 * =================================================
5 * LyX, The Document Processor
6 * Copyright 1995-2000 The LyX Team.
8 * =================================================
14 #pragma implementation
18 #include "FileDialog.h"
20 #include "support/lstrings.h"
21 #include <gtk--/fileselection.h>
22 #include <gnome--/main.h>
23 #include <gtk/gtkbutton.h>
25 #include <sigc++/signal_system.h>
27 #include "LyXView.h" // This is only needed while we have the xforms part!
28 #include "bufferview_funcs.h"
29 // FileDialog::Private
31 class FileDialog::Private : public SigC::Object {
33 Private(string const & title);
35 void set_modal(bool modal) { modal_ = modal; }
36 void set_complete(const string & pattern) { sel_.complete(pattern); }
37 void set_filename(const string & filename) { sel_.set_filename(filename);}
41 void button_clicked(bool canceled);
42 void ok_clicked() { button_clicked(false); }
43 void cancel_clicked() { button_clicked(true); }
46 Gtk::FileSelection sel_;
51 FileDialog::Private::Private(string const & title)
52 : sel_(title), modal_(false)
54 sel_.get_ok_button()->clicked.connect(slot(this,
55 &FileDialog::Private::ok_clicked));
56 sel_.get_cancel_button()->clicked.connect(slot(this,
57 &FileDialog::Private::cancel_clicked));
60 string const FileDialog::Private::exec()
63 sel_.set_modal(modal_);
66 // Find if its canceled or oked and return as needed.
71 return sel_.get_filename();
74 void FileDialog::Private::button_clicked(bool canceled)
83 FileDialog::FileDialog(LyXView * lv, string const & title, kb_action a,
84 Button /*b1*/, Button /*b2*/)
85 : private_(new Private(title))
86 , lv_(lv), title_(title), success_(a)
88 private_->set_modal(LFUN_SELECT_FILE_SYNC == a);
92 FileDialog::~FileDialog()
98 FileDialog::Result const
99 FileDialog::Select(string const & path, string const & mask,
100 string const & suggested)
102 // For some reason we need to ignore the asynchronous method...
104 if (LFUN_SELECT_FILE_SYNC != success_) {
105 lyxerr << "Asynchronous file dialog." << std::endl;
108 return FileDialog::Result(Later, string());
111 lyxerr << "Synchronous file dialog." << std::endl;
113 lyxerr << "Path: " << path << "\nMask: " << mask << "\nSuggested: " << suggested << std::endl;
115 string filter = mask;
116 rsplit(mask, filter, '|');
117 private_->set_complete(mask);
118 private_->set_filename(path+suggested);
120 ProhibitInput(lv_->view());
121 string const filename = private_->exec();
122 AllowInput(lv_->view());
124 // Collect the info and return it for synchronous dialog.
125 return FileDialog::Result(Chosen, filename);