2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file FileDialog_private.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "FileDialog_private.h"
|
2006-08-17 08:45:48 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "support/filefilterlist.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QToolButton>
|
2006-05-07 10:20:43 +00:00
|
|
|
#include <QHBoxLayout>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
using lyx::support::split;
|
2006-10-09 16:33:20 +00:00
|
|
|
using lyx::docstring;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// return the Qt form of the label
|
2006-10-09 16:33:20 +00:00
|
|
|
docstring const getLabel(docstring const & ucs4str) {
|
|
|
|
// FIXME UNICOE
|
|
|
|
string str = lyx::to_utf8(ucs4str);
|
2006-03-05 17:24:44 +00:00
|
|
|
string label;
|
|
|
|
string sc(split(str, label, '|'));
|
|
|
|
if (sc.length() < 2)
|
2006-10-09 16:33:20 +00:00
|
|
|
return lyx::from_utf8(label);
|
2006-03-05 17:24:44 +00:00
|
|
|
string::size_type pos = label.find(sc[1]);
|
|
|
|
if (pos == string::npos)
|
2006-10-09 16:33:20 +00:00
|
|
|
return lyx::from_utf8(label);
|
2006-03-05 17:24:44 +00:00
|
|
|
label.insert(pos, 1, '&');
|
2006-10-09 16:33:20 +00:00
|
|
|
return lyx::from_utf8(label);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2006-10-09 16:33:20 +00:00
|
|
|
LyXFileDialog::LyXFileDialog(docstring const & t,
|
|
|
|
docstring const & p,
|
2006-03-05 17:24:44 +00:00
|
|
|
lyx::support::FileFilterList const & filters,
|
|
|
|
FileDialog::Button const & b1,
|
|
|
|
FileDialog::Button const & b2)
|
2006-08-17 08:45:48 +00:00
|
|
|
// FIXME replace that with theApp->gui()->currentView()
|
|
|
|
: QFileDialog(qApp->focusWidget(),
|
2006-05-07 10:20:43 +00:00
|
|
|
toqstr(t), toqstr(p), toqstr(filters.as_string())),
|
|
|
|
b1_(0), b2_(0)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-17 08:45:48 +00:00
|
|
|
setWindowTitle(toqstr(t));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-05-07 10:20:43 +00:00
|
|
|
QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
if (!b1.first.empty()) {
|
|
|
|
b1_dir_ = b1.second;
|
|
|
|
b1_ = new QToolButton(this);
|
|
|
|
connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
|
|
|
b1_->setText(toqstr(getLabel(b1.first)));
|
2006-05-07 10:20:43 +00:00
|
|
|
layout.at(0)->addWidget(b1_);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!b2.first.empty()) {
|
|
|
|
b2_dir_ = b2.second;
|
|
|
|
b2_ = new QToolButton(this);
|
|
|
|
connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
|
|
|
b2_->setText(toqstr(getLabel(b2.first)));
|
2006-05-07 10:20:43 +00:00
|
|
|
layout.at(0)->addWidget(b2_);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXFileDialog::buttonClicked()
|
|
|
|
{
|
|
|
|
if (sender() == b1_)
|
2006-08-17 08:45:48 +00:00
|
|
|
setDirectory(toqstr(b1_dir_));
|
2006-03-05 17:24:44 +00:00
|
|
|
else if (sender() == b2_)
|
2006-08-17 08:45:48 +00:00
|
|
|
setDirectory(toqstr(b2_dir_));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
|
|
#include "FileDialog_private_moc.cpp"
|