2001-03-12 12:47:07 +00:00
|
|
|
/**
|
2002-03-11 22:47:41 +00:00
|
|
|
* \file qt2/FileDialog.C
|
2001-03-12 12:47:07 +00:00
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <config.h>
|
2002-03-21 21:21:28 +00:00
|
|
|
#include <gettext.h>
|
2001-03-12 12:47:07 +00:00
|
|
|
#include <utility>
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-12 12:47:07 +00:00
|
|
|
#include "commandtags.h"
|
|
|
|
#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-08-25 20:53:39 +00:00
|
|
|
#include <qapplication.h>
|
|
|
|
|
2001-03-12 12:47:07 +00:00
|
|
|
using std::make_pair;
|
|
|
|
using std::pair;
|
|
|
|
using std::endl;
|
|
|
|
|
2002-08-25 20:53:39 +00:00
|
|
|
struct FileDialog::Private {
|
|
|
|
Button b1;
|
|
|
|
Button b2;
|
|
|
|
};
|
|
|
|
|
|
|
|
FileDialog::FileDialog(LyXView *lv, string const & t, kb_action s, Button b1, Button b2)
|
|
|
|
: private_(new FileDialog::Private()), lv_(lv), 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FileDialog::Result const FileDialog::Select(string const & path, string const & mask, string const & suggested)
|
|
|
|
{
|
|
|
|
string filter = mask;
|
|
|
|
if (mask.empty())
|
|
|
|
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);
|
2001-03-12 12:47:07 +00:00
|
|
|
lyxerr[Debug::GUI] << "Select with path \"" << path << "\", mask \"" << filter << "\", suggested \"" << suggested << endl;
|
|
|
|
|
|
|
|
if (!suggested.empty())
|
2002-08-25 20:53:39 +00:00
|
|
|
dlg.setSelection(suggested.c_str());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-25 20:53:39 +00:00
|
|
|
// This code relies on DestructiveClose which is broken
|
|
|
|
// in Qt < 3.0.5. So we just don't allow it for now.
|
|
|
|
//if (success_ == LFUN_SELECT_FILE_SYNC) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
#if 0
|
2001-03-12 12:47:07 +00:00
|
|
|
dlg->show();
|
|
|
|
return make_pair(FileDialog::Later, string());
|
2002-08-25 20:53:39 +00:00
|
|
|
#endif
|
2001-03-12 12:47:07 +00:00
|
|
|
}
|