1 /* This file is part of
2 * =================================================
4 * LyX, The Document Processor
5 * Copyright 1995-2000 The LyX Team.
7 * =================================================
13 #pragma implementation
17 #include "FileDialog.h"
19 #include "support/lstrings.h"
20 #include <gtk--/fileselection.h>
21 #include <gnome--/main.h>
22 #include <gtk/gtkbutton.h>
24 #include <sigc++/signal_system.h>
26 #include "LyXView.h" // This is only needed while we have the xforms part!
27 #include "bufferview_funcs.h"
28 // FileDialog::Private
30 class FileDialog::Private : public SigC::Object {
32 Private(string const & title);
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);}
40 void button_clicked(bool canceled);
41 void ok_clicked() { button_clicked(false); }
42 void cancel_clicked() { button_clicked(true); }
45 Gtk::FileSelection sel_;
50 FileDialog::Private::Private(string const & title)
51 : sel_(title), modal_(false)
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));
59 string const FileDialog::Private::exec()
62 sel_.set_modal(modal_);
65 // Find if its canceled or oked and return as needed.
70 return sel_.get_filename();
73 void FileDialog::Private::button_clicked(bool canceled)
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)
87 private_->set_modal(LFUN_SELECT_FILE_SYNC == a);
91 FileDialog::~FileDialog()
97 FileDialog::Result const
98 FileDialog::Select(string const & path, string const & mask,
99 string const & suggested)
101 // For some reason we need to ignore the asynchronous method...
103 if (LFUN_SELECT_FILE_SYNC != success_) {
104 lyxerr << "Asynchronous file dialog." << std::endl;
107 return FileDialog::Result(Later, string());
110 lyxerr << "Synchronous file dialog." << std::endl;
112 lyxerr << "Path: " << path << "\nMask: " << mask << "\nSuggested: " << suggested << std::endl;
114 string filter = mask;
115 rsplit(mask, filter, '|');
116 private_->set_complete(mask);
117 private_->set_filename(path+suggested);
119 lv_->prohibitInput();
120 string const filename = private_->exec();
123 // Collect the info and return it for synchronous dialog.
124 return FileDialog::Result(Chosen, filename);