2001-03-12 12:47:07 +00:00
|
|
|
/**
|
2002-03-11 22:47:41 +00:00
|
|
|
* \file qt2/FileDialog.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
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-03-12 12:47:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2003-03-19 17:15:32 +00:00
|
|
|
#include "lfuns.h"
|
2001-03-12 12:47:07 +00:00
|
|
|
#include "LString.h"
|
|
|
|
#include "frontends/FileDialog.h"
|
2002-03-21 21:21:28 +00:00
|
|
|
#include "FileDialog_private.h"
|
2001-03-12 12:47:07 +00:00
|
|
|
#include "debug.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2003-01-04 21:42:59 +00:00
|
|
|
#include "gettext.h"
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2002-08-25 20:53:39 +00:00
|
|
|
#include <qapplication.h>
|
2002-10-19 10:32:57 +00:00
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
2001-03-12 12:47:07 +00:00
|
|
|
using std::make_pair;
|
|
|
|
using std::pair;
|
|
|
|
using std::endl;
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-10-19 10:32:57 +00:00
|
|
|
struct FileDialog::Private {
|
2002-08-25 20:53:39 +00:00
|
|
|
Button b1;
|
|
|
|
Button b2;
|
|
|
|
};
|
2002-10-19 10:32:57 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
FileDialog::FileDialog(string const & t,
|
2002-10-20 01:48:28 +00:00
|
|
|
kb_action s, Button b1, Button b2)
|
2003-02-21 12:22:25 +00:00
|
|
|
: private_(new FileDialog::Private), title_(t), success_(s)
|
2001-03-12 12:47:07 +00:00
|
|
|
{
|
2002-08-25 20:53:39 +00:00
|
|
|
private_->b1 = b1;
|
|
|
|
private_->b2 = b2;
|
2001-03-12 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FileDialog::~FileDialog()
|
|
|
|
{
|
2002-08-25 20:53:39 +00:00
|
|
|
delete private_;
|
2001-03-12 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-17 08:32:09 +00:00
|
|
|
FileDialog::Result const FileDialog::save(string const & path,
|
2002-10-20 01:48:28 +00:00
|
|
|
string const & mask,
|
|
|
|
string const & suggested)
|
2001-03-12 12:47:07 +00:00
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
string filter(mask);
|
2001-03-12 12:47:07 +00:00
|
|
|
if (mask.empty())
|
2003-01-04 21:42:59 +00:00
|
|
|
filter = _("All files (*)");
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-25 20:53:39 +00:00
|
|
|
LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
|
2002-10-20 01:48:28 +00:00
|
|
|
lyxerr[Debug::GUI] << "Select with path \"" << path
|
|
|
|
<< "\", mask \"" << filter
|
|
|
|
<< "\", suggested \"" << suggested << endl;
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2002-09-16 15:41:12 +00:00
|
|
|
dlg.setMode(QFileDialog::AnyFile);
|
2002-10-19 10:32:57 +00:00
|
|
|
|
2001-03-12 12:47:07 +00:00
|
|
|
if (!suggested.empty())
|
2002-12-17 20:37:13 +00:00
|
|
|
dlg.setSelection(toqstr(suggested));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-11-17 08:32:09 +00:00
|
|
|
FileDialog::Result result;
|
2003-01-06 14:02:24 +00:00
|
|
|
lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
|
2002-11-17 08:32:09 +00:00
|
|
|
result.first = FileDialog::Chosen;
|
|
|
|
int res = dlg.exec();
|
|
|
|
lyxerr[Debug::GUI] << "result " << res << endl;
|
|
|
|
if (res == QDialog::Accepted)
|
|
|
|
result.second = string(dlg.selectedFile().data());
|
|
|
|
dlg.hide();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-11-17 08:32:09 +00:00
|
|
|
FileDialog::Result const FileDialog::open(string const & path,
|
|
|
|
string const & mask,
|
|
|
|
string const & suggested)
|
|
|
|
{
|
|
|
|
string filter(mask);
|
|
|
|
if (mask.empty())
|
2003-01-14 21:51:34 +00:00
|
|
|
filter = _("All files (*)");
|
2002-11-17 08:32:09 +00:00
|
|
|
|
|
|
|
LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
|
|
|
|
lyxerr[Debug::GUI] << "Select with path \"" << path
|
|
|
|
<< "\", mask \"" << filter
|
|
|
|
<< "\", suggested \"" << suggested << endl;
|
|
|
|
|
|
|
|
if (!suggested.empty())
|
2002-12-17 20:37:13 +00:00
|
|
|
dlg.setSelection(toqstr(suggested));
|
2002-10-19 10:32:57 +00:00
|
|
|
|
2002-08-25 20:53:39 +00:00
|
|
|
FileDialog::Result result;
|
2003-01-06 14:02:24 +00:00
|
|
|
lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
|
2002-08-25 20:53:39 +00:00
|
|
|
result.first = FileDialog::Chosen;
|
|
|
|
int res = dlg.exec();
|
|
|
|
lyxerr[Debug::GUI] << "result " << res << endl;
|
|
|
|
if (res == QDialog::Accepted)
|
|
|
|
result.second = string(dlg.selectedFile().data());
|
|
|
|
dlg.hide();
|
|
|
|
return result;
|
2001-03-12 12:47:07 +00:00
|
|
|
}
|
2003-01-14 21:51:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
FileDialog::Result const FileDialog::opendir(string const & path,
|
|
|
|
string const & suggested)
|
|
|
|
{
|
|
|
|
string filter = _("Directories");
|
|
|
|
|
|
|
|
LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
|
|
|
|
lyxerr[Debug::GUI] << "Select with path \"" << path
|
|
|
|
<< "\", suggested \"" << suggested << endl;
|
|
|
|
|
|
|
|
dlg.setMode(QFileDialog::DirectoryOnly);
|
|
|
|
|
|
|
|
if (!suggested.empty())
|
|
|
|
dlg.setSelection(toqstr(suggested));
|
|
|
|
|
|
|
|
FileDialog::Result result;
|
|
|
|
lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
|
|
|
|
result.first = FileDialog::Chosen;
|
|
|
|
int res = dlg.exec();
|
|
|
|
lyxerr[Debug::GUI] << "result " << res << endl;
|
|
|
|
if (res == QDialog::Accepted)
|
|
|
|
result.second = string(dlg.selectedFile().data());
|
|
|
|
dlg.hide();
|
|
|
|
return result;
|
2003-02-21 12:22:25 +00:00
|
|
|
}
|