Added Export As... dialog, exploiting the new destination path that can

be specified when exporting.
This fixes #3402.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39805 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Tommaso Cucinotta 2011-10-06 13:47:42 +00:00
parent 8c7bc910ed
commit 164ae1584a
7 changed files with 92 additions and 2 deletions

View File

@ -87,6 +87,7 @@ Menuset
End
Menu "file_export"
Item "Export As...|A" "buffer-export-as"
ExportFormats
Item "More Formats & Options...|O" "buffer-export custom"
End

View File

@ -450,6 +450,7 @@ enum FuncCode
LFUN_SCRIPT_INSERT, // gb, 20101123
// 350
LFUN_BUFFER_EXPORT_AS, // tommaso 20111006
LFUN_LASTACTION // end of the table
};

View File

@ -2977,6 +2977,14 @@ void LyXAction::init()
* \endvar
*/
{ LFUN_BUFFER_EXPORT_CUSTOM, "buffer-export-custom", ReadOnly, Buffer },
/*!
* \var lyx::FuncCode lyx::LFUN_BUFFER_EXPORT_AS
* \li Action: Pops up a dialog for exporting the current buffer.
* \li Syntax: buffer-export
* \li Origin: tommaso, 6 Oct 2011
* \endvar
*/
{ LFUN_BUFFER_EXPORT_AS, "buffer-export-as", ReadOnly, Buffer },
/*!
* \var lyx::FuncCode lyx::LFUN_BUFFER_PRINT
* \li Action: Prints the current document.

View File

@ -81,7 +81,8 @@ void FileDialog::setButton2(QString const & label, QString const & dir)
FileDialog::Result FileDialog::save(QString const & path,
QStringList const & filters, QString const & suggested)
QStringList const & filters, QString const & suggested,
QString & selectedFilter)
{
LYXERR(Debug::GUI, "Select with path \"" << path
<< "\", mask \"" << filters.join(";;")
@ -95,7 +96,7 @@ FileDialog::Result FileDialog::save(QString const & path,
QString const name =
QFileDialog::getSaveFileName(qApp->focusWidget(),
title_, startsWith, filters.join(";;"),
0, QFileDialog::DontConfirmOverwrite);
selectedFilter, QFileDialog::DontConfirmOverwrite);
if (name.isNull())
result.first = FileDialog::Later;
else
@ -118,12 +119,21 @@ FileDialog::Result FileDialog::save(QString const & path,
result.second = internalPath(dlg.selectedFiles()[0]);
else
result.first = FileDialog::Later;
selectedFilter = dlg.selectedNameFilter();
dlg.hide();
#endif
return result;
}
FileDialog::Result FileDialog::save(QString const & path,
QStringList const & filters, QString const & suggested)
{
QString selectedFilter = 0;
return save(path, filters, suggested, selectedFilter);
}
FileDialog::Result FileDialog::open(QString const & path,
QStringList const & filters, QString const & suggested)
{

View File

@ -70,6 +70,10 @@ public:
Result save(QString const & path, QStringList const & filters,
QString const & suggested = QString());
/// Also retrieve the selected filter.
Result save(QString const & path, QStringList const & filters,
QString const & suggested, QString & selectedFilter);
private:
class Private;
friend class Private;

View File

@ -1657,6 +1657,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
}
case LFUN_BUFFER_WRITE_AS:
case LFUN_BUFFER_EXPORT_AS:
enable = doc_buffer;
break;
@ -2313,6 +2314,64 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
}
bool GuiView::exportBufferAs(Buffer & b)
{
FileName fname = b.fileName();
FileName const oldname = fname;
FileDialog dlg(qt_("Choose a filename to export the document as"));
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
QStringList types;
types << "Any supported format (*.*)";
Formats::const_iterator it = formats.begin();
for (; it != formats.end(); ++it)
if (it->documentFormat())
types << toqstr(it->name() + " (*." + it->extension() + ")");
QString filter;
FileDialog::Result result =
dlg.save(toqstr(fname.onlyPath().absFileName()),
types,
toqstr(fname.onlyFileName()),
filter);
if (result.first != FileDialog::Chosen)
return false;
string s = fromqstr(filter);
size_t pos = s.find(" (");
LASSERT(pos != string::npos, /**/);
string fmt_name = s.substr(0, pos);
fname.set(fromqstr(result.second));
if (fmt_name == "Any supported format")
fmt_name = formats.getFormatFromExtension(fname.extension());
LYXERR(Debug::FILES, "fmt_name=" << fmt_name << ", fname=" << fname.absFileName());
if (fname.empty())
return false;
// fname is now the new Buffer location.
if (FileName(fname).exists()) {
docstring const file = makeDisplayPath(fname.absFileName(), 30);
docstring text = bformat(_("The document %1$s already "
"exists.\n\nDo you want to "
"overwrite that document?"),
file);
int const ret = Alert::prompt(_("Overwrite document?"),
text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel"));
switch (ret) {
case 0: break;
case 1: return exportBufferAs(b);
case 2: return false;
}
}
FuncRequest cmd(LFUN_BUFFER_EXPORT, fmt_name + " " + fname.absFileName());
DispatchResult dr;
dispatch(cmd, dr);
return dr.dispatched();
}
bool GuiView::saveBuffer(Buffer & b) {
return saveBuffer(b, FileName());
}
@ -3158,6 +3217,11 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break;
}
case LFUN_BUFFER_EXPORT_AS:
LASSERT(doc_buffer, break);
exportBufferAs(*doc_buffer);
break;
case LFUN_BUFFER_UPDATE: {
d.asyncBufferProcessing(argument,
doc_buffer,

View File

@ -353,6 +353,8 @@ private:
///
void insertPlaintextFile(docstring const & fname,
bool asParagraph);
///
bool exportBufferAs(Buffer & b);
/// Save a buffer as a new file.
/**