]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FileDialog.C
Lots and lots of little trivial bits.
[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 #include <gettext.h>
17 #include <utility>
18
19 #include "commandtags.h"
20 #include "LString.h"
21 #include "frontends/FileDialog.h"
22 #include "FileDialog_private.h"
23 #include "debug.h"
24
25 #include <qapplication.h>
26  
27 using std::make_pair;
28 using std::pair;
29 using std::endl;
30
31 struct FileDialog::Private { 
32         Button b1;
33         Button b2;
34 };
35  
36 FileDialog::FileDialog(LyXView *lv, string const & t, kb_action s, Button b1, Button b2)
37         : private_(new FileDialog::Private()), lv_(lv), title_(t), success_(s)
38 {
39         private_->b1 = b1;
40         private_->b2 = b2;
41 }
42
43
44 FileDialog::~FileDialog()
45 {
46         delete private_;
47 }
48
49
50 FileDialog::Result const FileDialog::Select(string const & path, string const & mask, string const & suggested)
51 {
52         string filter = mask;
53         if (mask.empty())
54                 filter = _("*|All files");
55
56         LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
57         lyxerr[Debug::GUI] << "Select with path \"" << path << "\", mask \"" << filter << "\", suggested \"" << suggested << endl;
58
59         dlg.setMode(QFileDialog::AnyFile);
60  
61         if (!suggested.empty())
62                 dlg.setSelection(suggested.c_str());
63
64         // This code relies on DestructiveClose which is broken
65         // in Qt < 3.0.5. So we just don't allow it for now.
66         //if (success_ == LFUN_SELECT_FILE_SYNC) {
67  
68         FileDialog::Result result;
69         lyxerr[Debug::GUI] << "Synchronous FileDialog : " << endl;
70         result.first = FileDialog::Chosen;
71         int res = dlg.exec();
72         lyxerr[Debug::GUI] << "result " << res << endl;
73         if (res == QDialog::Accepted)
74                 result.second = string(dlg.selectedFile().data());
75         dlg.hide();
76         return result;
77 #if 0
78         dlg->show();
79         return make_pair(FileDialog::Later, string());
80 #endif
81 }