mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-11 21:49:51 +00:00
6c300f72a2
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15422 a592a061-630c-0410-9148-cb99ea01b6c8
176 lines
4.6 KiB
C
176 lines
4.6 KiB
C
/**
|
|
* \file qt4/FileDialog.C
|
|
* This file is part of LyX, the document processor.
|
|
* Licence details can be found in the file COPYING.
|
|
*
|
|
* \author John Levon
|
|
* \author Jean-Marc Lasgouttes
|
|
*
|
|
* Full author contact details are available in file CREDITS.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "frontends/FileDialog.h"
|
|
|
|
#include "FileDialog_private.h"
|
|
#include "qt_helpers.h"
|
|
|
|
#include "debug.h"
|
|
#include "gettext.h"
|
|
|
|
#include "support/filefilterlist.h"
|
|
|
|
/** when this is defined, the code will use
|
|
* QFileDialog::getOpenFileName and friends to create filedialogs.
|
|
* Effects:
|
|
* - the dialog does not use the quick directory buttons (Button
|
|
* parameters);
|
|
* - with Qt/Mac or Qt/Win, the dialogs native to the environment are used.
|
|
*
|
|
* Therefore there is a tradeoff in enabling or disabling this (JMarc)
|
|
*/
|
|
#ifdef Q_WS_MACX
|
|
#define USE_NATIVE_FILEDIALOG 1
|
|
#endif
|
|
|
|
#ifdef USE_NATIVE_FILEDIALOG
|
|
#include <qapplication.h>
|
|
#include "support/filetools.h"
|
|
|
|
using lyx::support::makeAbsPath;
|
|
#endif
|
|
|
|
namespace lyx {
|
|
|
|
using support::FileFilterList;
|
|
using std::endl;
|
|
|
|
|
|
class FileDialog::Private {
|
|
public:
|
|
Button b1;
|
|
Button b2;
|
|
};
|
|
|
|
|
|
FileDialog::FileDialog(docstring 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(docstring const & path,
|
|
FileFilterList const & filters,
|
|
docstring const & suggested)
|
|
{
|
|
lyxerr[Debug::GUI] << "Select with path \"" << lyx::to_utf8(path)
|
|
<< "\", mask \"" << lyx::to_utf8(filters.as_string())
|
|
<< "\", suggested \"" << lyx::to_utf8(suggested) << '"' << endl;
|
|
FileDialog::Result result;
|
|
result.first = FileDialog::Chosen;
|
|
|
|
#ifdef USE_NATIVE_FILEDIALOG
|
|
docstring const startsWith
|
|
= lyx::from_utf8(makeAbsPath(lyx::to_utf8(suggested), lyx::to_utf8(path)));
|
|
result.second = qstring_to_ucs4(QFileDialog::getSaveFileName(
|
|
qApp->focusWidget(),
|
|
toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) ));
|
|
#else
|
|
LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
|
|
dlg.setFileMode(QFileDialog::AnyFile);
|
|
dlg.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
|
if (!suggested.empty())
|
|
dlg.selectFile(toqstr(suggested));
|
|
|
|
lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
|
|
int res = dlg.exec();
|
|
lyxerr[Debug::GUI] << "result " << res << endl;
|
|
if (res == QDialog::Accepted)
|
|
result.second = qstring_to_ucs4(dlg.selectedFiles()[0]);
|
|
dlg.hide();
|
|
#endif
|
|
return result;
|
|
}
|
|
|
|
|
|
FileDialog::Result const FileDialog::open(docstring const & path,
|
|
FileFilterList const & filters,
|
|
docstring const & suggested)
|
|
{
|
|
lyxerr[Debug::GUI] << "Select with path \"" << lyx::to_utf8(path)
|
|
<< "\", mask \"" << lyx::to_utf8(filters.as_string())
|
|
<< "\", suggested \"" << lyx::to_utf8(suggested) << '"' << endl;
|
|
FileDialog::Result result;
|
|
result.first = FileDialog::Chosen;
|
|
|
|
#ifdef USE_NATIVE_FILEDIALOG
|
|
docstring const startsWith =
|
|
lyx::from_utf8(makeAbsPath(lyx::to_utf8(suggested), lyx::to_utf8(path)));
|
|
result.second = qstring_to_ucs4(QFileDialog::getOpenFileName(
|
|
qApp->focusWidget(),
|
|
toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) ));
|
|
#else
|
|
LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
|
|
|
|
if (!suggested.empty())
|
|
dlg.selectFile(toqstr(suggested));
|
|
|
|
lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
|
|
int res = dlg.exec();
|
|
lyxerr[Debug::GUI] << "result " << res << endl;
|
|
if (res == QDialog::Accepted)
|
|
result.second = qstring_to_ucs4(dlg.selectedFiles()[0]);
|
|
dlg.hide();
|
|
#endif
|
|
return result;
|
|
}
|
|
|
|
|
|
FileDialog::Result const FileDialog::opendir(docstring const & path,
|
|
docstring const & suggested)
|
|
{
|
|
lyxerr[Debug::GUI] << "Select with path \"" << lyx::to_utf8(path)
|
|
<< "\", suggested \"" << lyx::to_utf8(suggested) << '"' << endl;
|
|
FileDialog::Result result;
|
|
result.first = FileDialog::Chosen;
|
|
|
|
#ifdef USE_NATIVE_FILEDIALOG
|
|
docstring const startsWith
|
|
= lyx::from_utf8(makeAbsPath(lyx::to_utf8(suggested), lyx::to_utf8(path)));
|
|
result.second = qstring_to_ucs4(QFileDialog::getExistingDirectory(
|
|
qApp->focusWidget(),
|
|
toqstr(title_),toqstr(startsWith) ));
|
|
#else
|
|
FileFilterList const filter(_("Directories"));
|
|
|
|
LyXFileDialog dlg(title_, path, filter, private_->b1, private_->b2);
|
|
|
|
dlg.setFileMode(QFileDialog::DirectoryOnly);
|
|
|
|
if (!suggested.empty())
|
|
dlg.selectFile(toqstr(suggested));
|
|
|
|
lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
|
|
int res = dlg.exec();
|
|
lyxerr[Debug::GUI] << "result " << res << endl;
|
|
if (res == QDialog::Accepted)
|
|
result.second = qstring_to_ucs4(dlg.selectedFiles()[0]);
|
|
dlg.hide();
|
|
#endif
|
|
return result;
|
|
}
|
|
|
|
|
|
} // namespace lyx
|