]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FileDialog.C
File dialog fixes. Implement optional menu items
[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         if (!suggested.empty())
58                 dlg.setSelection(suggested.c_str());
59
60         // This code relies on DestructiveClose which is broken
61         // in Qt < 3.0.5. So we just don't allow it for now.
62         //if (success_ == LFUN_SELECT_FILE_SYNC) {
63  
64         FileDialog::Result result;
65         lyxerr[Debug::GUI] << "Synchronous FileDialog : " << endl;
66         result.first = FileDialog::Chosen;
67         int res = dlg.exec();
68         lyxerr[Debug::GUI] << "result " << res << endl;
69         if (res == QDialog::Accepted)
70                 result.second = string(dlg.selectedFile().data());
71         dlg.hide();
72         return result;
73 #if 0
74         dlg->show();
75         return make_pair(FileDialog::Later, string());
76 #endif
77 }