2001-03-12 12:47:07 +00:00
|
|
|
/**
|
|
|
|
* \file FileDialog_private.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-03-12 12:47:07 +00:00
|
|
|
*
|
|
|
|
* \author John Levon
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-03-12 12:47:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2002-10-19 10:32:57 +00:00
|
|
|
#include "FileDialog_private.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2002-10-19 10:32:57 +00:00
|
|
|
|
2004-01-05 16:49:38 +00:00
|
|
|
#include "support/globbing.h"
|
2002-09-24 13:57:09 +00:00
|
|
|
#include "support/lstrings.h"
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2002-10-19 10:32:57 +00:00
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qtoolbutton.h>
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::split;
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2002-10-19 10:32:57 +00:00
|
|
|
|
2002-08-25 20:53:39 +00:00
|
|
|
namespace {
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
/// return the Qt form of the label
|
|
|
|
string const getLabel(string const & str) {
|
|
|
|
string label;
|
|
|
|
string sc(split(str, label, '|'));
|
|
|
|
if (sc.length() < 2)
|
2002-08-25 20:53:39 +00:00
|
|
|
return label;
|
2002-10-20 01:48:28 +00:00
|
|
|
string::size_type pos = label.find(sc[1]);
|
|
|
|
if (pos == string::npos)
|
|
|
|
return label;
|
2002-11-27 10:30:28 +00:00
|
|
|
label.insert(pos, 1, '&');
|
2002-10-20 01:48:28 +00:00
|
|
|
return label;
|
2002-08-25 20:53:39 +00:00
|
|
|
}
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
2002-10-19 10:32:57 +00:00
|
|
|
|
2004-01-08 10:59:51 +00:00
|
|
|
LyXFileDialog::LyXFileDialog(string const & p,
|
|
|
|
lyx::support::FileFilterList const & filters,
|
2002-10-19 10:32:57 +00:00
|
|
|
string const & t,
|
2004-01-08 10:59:51 +00:00
|
|
|
FileDialog::Button const & b1,
|
|
|
|
FileDialog::Button const & b2)
|
|
|
|
: QFileDialog(toqstr(p), toqstr(filters.str(true)),
|
2002-12-17 20:37:13 +00:00
|
|
|
qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget(), toqstr(t), true),
|
2002-08-25 20:53:39 +00:00
|
|
|
b1_(0), b2_(0)
|
2001-03-12 12:47:07 +00:00
|
|
|
{
|
2002-12-17 20:37:13 +00:00
|
|
|
setCaption(toqstr(t));
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
if (!b1.first.empty()) {
|
2002-08-25 20:53:39 +00:00
|
|
|
b1_dir_ = b1.second;
|
|
|
|
b1_ = new QToolButton(this);
|
|
|
|
connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
2002-12-17 20:37:13 +00:00
|
|
|
b1_->setText(toqstr(getLabel(b1.first)));
|
2002-08-25 20:53:39 +00:00
|
|
|
addToolButton(b1_, true);
|
|
|
|
}
|
2001-03-26 19:34:45 +00:00
|
|
|
|
2002-08-25 20:53:39 +00:00
|
|
|
if (!b2.first.empty()) {
|
|
|
|
b2_dir_ = b2.second;
|
|
|
|
b2_ = new QToolButton(this);
|
|
|
|
connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
2002-12-17 20:37:13 +00:00
|
|
|
b2_->setText(toqstr(getLabel(b2.first)));
|
2002-08-25 20:53:39 +00:00
|
|
|
addToolButton(b2_);
|
2002-01-16 23:56:25 +00:00
|
|
|
}
|
2002-08-25 20:53:39 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-07 08:11:41 +00:00
|
|
|
|
2002-08-25 20:53:39 +00:00
|
|
|
void LyXFileDialog::buttonClicked()
|
|
|
|
{
|
|
|
|
if (sender() == b1_)
|
2002-12-17 20:37:13 +00:00
|
|
|
setDir(toqstr(b1_dir_));
|
2002-08-25 20:53:39 +00:00
|
|
|
else if (sender() == b2_)
|
2002-12-17 20:37:13 +00:00
|
|
|
setDir(toqstr(b2_dir_));
|
2001-03-12 12:47:07 +00:00
|
|
|
}
|