]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FileDialog.C
implement getLabelList
[lyx.git] / src / frontends / gnome / FileDialog.C
1 // -*- C++ -*-
2 /* This file is part of
3  * =================================================
4  * 
5  *          LyX, The Document Processor
6  *          Copyright 1995-2000 The LyX Team.
7  *
8  * ================================================= 
9  *
10  * \author Baruch Even 
11  **/
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include <config.h>
18 #include "FileDialog.h"
19 #include "debug.h"
20 #include "support/lstrings.h"
21 #include <gtk--/fileselection.h>
22 #include <gnome--/main.h>
23 #include <gtk/gtkbutton.h>
24
25 #include <sigc++/signal_system.h>
26
27 #include "LyXView.h" // This is only needed while we have the xforms part!
28 #include "bufferview_funcs.h"
29 // FileDialog::Private
30
31 class FileDialog::Private : public SigC::Object {
32 public:
33         Private(string const & title);
34
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);}
38
39         string const exec();
40
41         void button_clicked(bool canceled);
42         void ok_clicked()     { button_clicked(false); }
43         void cancel_clicked() { button_clicked(true); }
44         
45 private:
46         Gtk::FileSelection sel_;
47         bool modal_;
48         bool canceled_;
49 };
50
51 FileDialog::Private::Private(string const & title)
52         : sel_(title), modal_(false) 
53 {
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));
58 }
59
60 string const FileDialog::Private::exec()
61 {
62         canceled_ = false;
63         sel_.set_modal(modal_);
64         sel_.show();
65         Gnome::Main::run();
66         // Find if its canceled or oked and return as needed.
67         
68         if (canceled_)
69                 return string();
70         else
71                 return sel_.get_filename();
72 }
73
74 void FileDialog::Private::button_clicked(bool canceled)
75 {
76         canceled_ = canceled;
77         sel_.hide();
78         Gnome::Main::quit();
79 }
80
81 // FileDialog
82
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)
87 {
88                 private_->set_modal(LFUN_SELECT_FILE_SYNC == a);
89 }
90
91
92 FileDialog::~FileDialog()
93 {
94         delete private_;
95 }
96
97
98 FileDialog::Result const 
99 FileDialog::Select(string const & path, string const & mask, 
100                 string const & suggested)
101 {
102         // For some reason we need to ignore the asynchronous method...
103 #if 0
104         if (LFUN_SELECT_FILE_SYNC != success_) {
105                 lyxerr << "Asynchronous file dialog." << std::endl;
106                 private_->show();
107
108                 return FileDialog::Result(Later, string());
109         }
110 #endif
111         lyxerr << "Synchronous file dialog." << std::endl;
112         
113         lyxerr << "Path: " << path << "\nMask: " << mask << "\nSuggested: " << suggested << std::endl;
114         
115         string filter = mask;
116         rsplit(mask, filter, '|');
117         private_->set_complete(mask);
118         private_->set_filename(path+suggested);
119         
120         ProhibitInput(lv_->view());
121         string const filename = private_->exec();
122         AllowInput(lv_->view());
123
124         // Collect the info and return it for synchronous dialog.
125         return FileDialog::Result(Chosen, filename);
126 }