mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
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:
parent
8c7bc910ed
commit
164ae1584a
@ -87,6 +87,7 @@ Menuset
|
|||||||
End
|
End
|
||||||
|
|
||||||
Menu "file_export"
|
Menu "file_export"
|
||||||
|
Item "Export As...|A" "buffer-export-as"
|
||||||
ExportFormats
|
ExportFormats
|
||||||
Item "More Formats & Options...|O" "buffer-export custom"
|
Item "More Formats & Options...|O" "buffer-export custom"
|
||||||
End
|
End
|
||||||
|
@ -450,6 +450,7 @@ enum FuncCode
|
|||||||
LFUN_SCRIPT_INSERT, // gb, 20101123
|
LFUN_SCRIPT_INSERT, // gb, 20101123
|
||||||
// 350
|
// 350
|
||||||
|
|
||||||
|
LFUN_BUFFER_EXPORT_AS, // tommaso 20111006
|
||||||
LFUN_LASTACTION // end of the table
|
LFUN_LASTACTION // end of the table
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2977,6 +2977,14 @@ void LyXAction::init()
|
|||||||
* \endvar
|
* \endvar
|
||||||
*/
|
*/
|
||||||
{ LFUN_BUFFER_EXPORT_CUSTOM, "buffer-export-custom", ReadOnly, Buffer },
|
{ 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
|
* \var lyx::FuncCode lyx::LFUN_BUFFER_PRINT
|
||||||
* \li Action: Prints the current document.
|
* \li Action: Prints the current document.
|
||||||
|
@ -81,7 +81,8 @@ void FileDialog::setButton2(QString const & label, QString const & dir)
|
|||||||
|
|
||||||
|
|
||||||
FileDialog::Result FileDialog::save(QString const & path,
|
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
|
LYXERR(Debug::GUI, "Select with path \"" << path
|
||||||
<< "\", mask \"" << filters.join(";;")
|
<< "\", mask \"" << filters.join(";;")
|
||||||
@ -95,7 +96,7 @@ FileDialog::Result FileDialog::save(QString const & path,
|
|||||||
QString const name =
|
QString const name =
|
||||||
QFileDialog::getSaveFileName(qApp->focusWidget(),
|
QFileDialog::getSaveFileName(qApp->focusWidget(),
|
||||||
title_, startsWith, filters.join(";;"),
|
title_, startsWith, filters.join(";;"),
|
||||||
0, QFileDialog::DontConfirmOverwrite);
|
selectedFilter, QFileDialog::DontConfirmOverwrite);
|
||||||
if (name.isNull())
|
if (name.isNull())
|
||||||
result.first = FileDialog::Later;
|
result.first = FileDialog::Later;
|
||||||
else
|
else
|
||||||
@ -118,12 +119,21 @@ FileDialog::Result FileDialog::save(QString const & path,
|
|||||||
result.second = internalPath(dlg.selectedFiles()[0]);
|
result.second = internalPath(dlg.selectedFiles()[0]);
|
||||||
else
|
else
|
||||||
result.first = FileDialog::Later;
|
result.first = FileDialog::Later;
|
||||||
|
selectedFilter = dlg.selectedNameFilter();
|
||||||
dlg.hide();
|
dlg.hide();
|
||||||
#endif
|
#endif
|
||||||
return result;
|
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,
|
FileDialog::Result FileDialog::open(QString const & path,
|
||||||
QStringList const & filters, QString const & suggested)
|
QStringList const & filters, QString const & suggested)
|
||||||
{
|
{
|
||||||
|
@ -70,6 +70,10 @@ public:
|
|||||||
Result save(QString const & path, QStringList const & filters,
|
Result save(QString const & path, QStringList const & filters,
|
||||||
QString const & suggested = QString());
|
QString const & suggested = QString());
|
||||||
|
|
||||||
|
/// Also retrieve the selected filter.
|
||||||
|
Result save(QString const & path, QStringList const & filters,
|
||||||
|
QString const & suggested, QString & selectedFilter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Private;
|
class Private;
|
||||||
friend class Private;
|
friend class Private;
|
||||||
|
@ -1657,6 +1657,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case LFUN_BUFFER_WRITE_AS:
|
case LFUN_BUFFER_WRITE_AS:
|
||||||
|
case LFUN_BUFFER_EXPORT_AS:
|
||||||
enable = doc_buffer;
|
enable = doc_buffer;
|
||||||
break;
|
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) {
|
bool GuiView::saveBuffer(Buffer & b) {
|
||||||
return saveBuffer(b, FileName());
|
return saveBuffer(b, FileName());
|
||||||
}
|
}
|
||||||
@ -3158,6 +3217,11 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case LFUN_BUFFER_EXPORT_AS:
|
||||||
|
LASSERT(doc_buffer, break);
|
||||||
|
exportBufferAs(*doc_buffer);
|
||||||
|
break;
|
||||||
|
|
||||||
case LFUN_BUFFER_UPDATE: {
|
case LFUN_BUFFER_UPDATE: {
|
||||||
d.asyncBufferProcessing(argument,
|
d.asyncBufferProcessing(argument,
|
||||||
doc_buffer,
|
doc_buffer,
|
||||||
|
@ -353,6 +353,8 @@ private:
|
|||||||
///
|
///
|
||||||
void insertPlaintextFile(docstring const & fname,
|
void insertPlaintextFile(docstring const & fname,
|
||||||
bool asParagraph);
|
bool asParagraph);
|
||||||
|
///
|
||||||
|
bool exportBufferAs(Buffer & b);
|
||||||
|
|
||||||
/// Save a buffer as a new file.
|
/// Save a buffer as a new file.
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user