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