2 * \file LyXFileDialog.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "LyXFileDialog.h"
15 #include "qt_helpers.h"
17 #include "support/FileFilterList.h"
18 #include "support/lstrings.h"
20 #include <QApplication>
21 #include <QToolButton>
22 #include <QHBoxLayout>
25 using namespace lyx::support;
29 /// return the Qt form of the label
30 static QString getLabel(QString const & qstr)
32 // FIXME UNICODE (or "qt-ify")
33 string str = fromqstr(qstr);
35 string sc = split(str, label, '|');
38 size_t pos = label.find(sc[1]);
39 if (pos != string::npos)
40 label.insert(pos, 1, '&');
45 LyXFileDialog::LyXFileDialog(QString const & title,
47 support::FileFilterList const & filters,
48 FileDialog::Button const & b1,
49 FileDialog::Button const & b2)
50 // FIXME replace that with guiApp->currentView()
51 : QFileDialog(qApp->focusWidget(), title, path, toqstr(filters.as_string()))
54 // FIXME: workaround for a bug in qt which makes LyX crash
55 // with hidden paths (bug 4513). Recheck with recent Qt versions.
56 if (path.contains("/."))
57 dir.setFilter(QDir::Hidden);
59 setWindowTitle(title);
61 QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
63 if (!b1.first.isEmpty()) {
65 QToolButton * tb = new QToolButton(this);
66 connect(tb, SIGNAL(clicked()), this, SLOT(button1Clicked()));
67 tb->setText(getLabel(b1.first));
68 layout.at(0)->addWidget(tb);
71 if (!b2.first.isEmpty()) {
73 QToolButton * tb = new QToolButton(this);
74 connect(tb, SIGNAL(clicked()), this, SLOT(button2Clicked()));
75 tb->setText(getLabel(b2.first));
76 layout.at(0)->addWidget(tb);
81 void LyXFileDialog::button1Clicked()
83 setDirectory(b1_dir_);
87 void LyXFileDialog::button2Clicked()
89 setDirectory(b2_dir_);
94 #include "LyXFileDialog_moc.cpp"