]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FileDialog.C
qtabular skeleton
[lyx.git] / src / frontends / qt2 / FileDialog.C
1 /**
2  * \file qt2/FileDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <config.h>
16
17 #include "commandtags.h"
18 #include "LString.h"
19 #include "frontends/FileDialog.h"
20 #include "FileDialog_private.h"
21 #include "debug.h"
22 #include "gettext.h"
23
24 #include <qapplication.h>
25
26 #include <utility>
27
28 using std::make_pair;
29 using std::pair;
30 using std::endl;
31
32
33 struct FileDialog::Private {
34         Button b1;
35         Button b2;
36 };
37
38
39 FileDialog::FileDialog(LyXView * lv, string const & t,
40                        kb_action s, Button b1, Button b2)
41         : private_(new FileDialog::Private), lv_(lv), title_(t), success_(s)
42 {
43         private_->b1 = b1;
44         private_->b2 = b2;
45 }
46
47
48 FileDialog::~FileDialog()
49 {
50         delete private_;
51 }
52
53
54 FileDialog::Result const FileDialog::Select(string const & path,
55                                             string const & mask,
56                                             string const & suggested)
57 {
58         string filter(mask);
59         if (mask.empty())
60                 filter = _("*|All files");
61
62         LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
63         lyxerr[Debug::GUI] << "Select with path \"" << path
64                            << "\", mask \"" << filter
65                            << "\", suggested \"" << suggested << endl;
66
67         dlg.setMode(QFileDialog::AnyFile);
68
69         if (!suggested.empty())
70                 dlg.setSelection(suggested.c_str());
71
72         // This code relies on DestructiveClose which is broken
73         // in Qt < 3.0.5. So we just don't allow it for now.
74         //if (success_ == LFUN_SELECT_FILE_SYNC) {
75
76         FileDialog::Result result;
77         lyxerr[Debug::GUI] << "Synchronous FileDialog : " << endl;
78         result.first = FileDialog::Chosen;
79         int res = dlg.exec();
80         lyxerr[Debug::GUI] << "result " << res << endl;
81         if (res == QDialog::Accepted)
82                 result.second = string(dlg.selectedFile().data());
83         dlg.hide();
84         return result;
85 #if 0
86         dlg->show();
87         return make_pair(FileDialog::Later, string());
88 #endif
89 }