mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-04 22:32:19 +00:00
80db139a76
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6223 a592a061-630c-0410-9148-cb99ea01b6c8
134 lines
3.1 KiB
C
134 lines
3.1 KiB
C
/**
|
|
* \file qt2/FileDialog.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 "commandtags.h"
|
|
#include "LString.h"
|
|
#include "frontends/FileDialog.h"
|
|
#include "FileDialog_private.h"
|
|
#include "debug.h"
|
|
#include "qt_helpers.h"
|
|
#include "gettext.h"
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <utility>
|
|
|
|
using std::make_pair;
|
|
using std::pair;
|
|
using std::endl;
|
|
|
|
|
|
struct FileDialog::Private {
|
|
Button b1;
|
|
Button b2;
|
|
};
|
|
|
|
|
|
FileDialog::FileDialog(string const & t,
|
|
kb_action s, Button b1, Button b2)
|
|
: private_(new FileDialog::Private), title_(t), success_(s)
|
|
{
|
|
private_->b1 = b1;
|
|
private_->b2 = b2;
|
|
}
|
|
|
|
|
|
FileDialog::~FileDialog()
|
|
{
|
|
delete private_;
|
|
}
|
|
|
|
|
|
FileDialog::Result const FileDialog::save(string const & path,
|
|
string const & mask,
|
|
string const & suggested)
|
|
{
|
|
string filter(mask);
|
|
if (mask.empty())
|
|
filter = _("All files (*)");
|
|
|
|
LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
|
|
lyxerr[Debug::GUI] << "Select with path \"" << path
|
|
<< "\", mask \"" << filter
|
|
<< "\", suggested \"" << suggested << endl;
|
|
|
|
dlg.setMode(QFileDialog::AnyFile);
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
FileDialog::Result const FileDialog::open(string const & path,
|
|
string const & mask,
|
|
string const & suggested)
|
|
{
|
|
string filter(mask);
|
|
if (mask.empty())
|
|
filter = _("All files (*)");
|
|
|
|
LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
|
|
lyxerr[Debug::GUI] << "Select with path \"" << path
|
|
<< "\", mask \"" << filter
|
|
<< "\", suggested \"" << suggested << endl;
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
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;
|
|
}
|