Some fixes to the SaveAs dialog

LFUN_BUFFER_SAVE_AS has an optional argument where an initial format can be preset

This fixes:

* The remainder of bug #3402: Open Export As dialog when attempting to export to read-only directories
* Bug #8886: 'export as' should default to the default document output format
This commit is contained in:
Juergen Spitzmueller 2013-11-15 09:20:07 +01:00
parent ed268ac9f7
commit e014f3fabf
4 changed files with 33 additions and 11 deletions

View File

@ -3075,8 +3075,15 @@ void LyXAction::init()
{ 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 * \var lyx::FuncCode lyx::LFUN_BUFFER_EXPORT_AS
* \li Action: Pops up a dialog for exporting the current buffer. * \li Action: Opens a dialog for exporting the current buffer.
* \li Syntax: buffer-export-as * \li Syntax: buffer-export-as [<FORMAT>]
* \li Params: <FORMAT> is the export format initially selected in the dialog.
* You can pass any of the formats which you can find in
* Tools->Preferences->File formats->Format, provided it
* has the "document" flag set. If no format is specified
* the dialog will start with the default output format of
* the current document.
* \li Sample: buffer-export-as pdf2
* \li Origin: tommaso, 6 Oct 2011 * \li Origin: tommaso, 6 Oct 2011
* \endvar * \endvar
*/ */

View File

@ -106,6 +106,8 @@ FileDialog::Result FileDialog::save(QString const & path,
dlg.setFileMode(QFileDialog::AnyFile); dlg.setFileMode(QFileDialog::AnyFile);
dlg.setAcceptMode(QFileDialog::AcceptSave); dlg.setAcceptMode(QFileDialog::AcceptSave);
dlg.setConfirmOverwrite(false); dlg.setConfirmOverwrite(false);
if (selectedFilter != 0 && !selectedFilter->isEmpty())
dlg.selectNameFilter(*selectedFilter);
if (!suggested.isEmpty()) if (!suggested.isEmpty())
dlg.selectFile(suggested); dlg.selectFile(suggested);

View File

@ -2376,7 +2376,7 @@ struct PrettyNameComparator
}; };
bool GuiView::exportBufferAs(Buffer & b) bool GuiView::exportBufferAs(Buffer & b, docstring const & iformat)
{ {
FileName fname = b.fileName(); FileName fname = b.fileName();
@ -2395,6 +2395,8 @@ bool GuiView::exportBufferAs(Buffer & b)
sort(export_formats.begin(), export_formats.end(), cmp); sort(export_formats.begin(), export_formats.end(), cmp);
vector<Format const *>::const_iterator fit = export_formats.begin(); vector<Format const *>::const_iterator fit = export_formats.begin();
map<QString, string> fmap; map<QString, string> fmap;
QString filter;
string ext;
for (; fit != export_formats.end(); ++fit) { for (; fit != export_formats.end(); ++fit) {
docstring const loc_prettyname = docstring const loc_prettyname =
translateIfPossible(from_utf8((*fit)->prettyname())); translateIfPossible(from_utf8((*fit)->prettyname()));
@ -2403,12 +2405,18 @@ bool GuiView::exportBufferAs(Buffer & b)
from_ascii((*fit)->extension()))); from_ascii((*fit)->extension())));
types << loc_filter; types << loc_filter;
fmap[loc_filter] = (*fit)->name(); fmap[loc_filter] = (*fit)->name();
if (from_ascii((*fit)->name()) == iformat) {
filter = loc_filter;
ext = (*fit)->extension();
} }
QString filter; }
string ofname = fname.onlyFileName();
if (!ext.empty())
ofname = support::changeExtension(ofname, ext);
FileDialog::Result result = FileDialog::Result result =
dlg.save(toqstr(fname.onlyPath().absFileName()), dlg.save(toqstr(fname.onlyPath().absFileName()),
types, types,
toqstr(fname.onlyFileName()), toqstr(ofname),
&filter); &filter);
if (result.first != FileDialog::Chosen) if (result.first != FileDialog::Chosen)
return false; return false;
@ -2436,7 +2444,7 @@ bool GuiView::exportBufferAs(Buffer & b)
text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel")); text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel"));
switch (ret) { switch (ret) {
case 0: break; case 0: break;
case 1: return exportBufferAs(b); case 1: return exportBufferAs(b, from_ascii(fmt_name));
case 2: return false; case 2: return false;
} }
} }
@ -3315,7 +3323,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break; break;
} }
if (!target_dir.isDirWritable()) { if (!target_dir.isDirWritable()) {
exportBufferAs(*doc_buffer); exportBufferAs(*doc_buffer, cmd.argument());
break; break;
} }
/* TODO/Review: Is it a problem to also export the children? /* TODO/Review: Is it a problem to also export the children?
@ -3330,10 +3338,14 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break; break;
} }
case LFUN_BUFFER_EXPORT_AS: case LFUN_BUFFER_EXPORT_AS: {
LASSERT(doc_buffer, break); LASSERT(doc_buffer, break);
exportBufferAs(*doc_buffer); docstring f = cmd.argument();
if (f.empty())
f = from_ascii(doc_buffer->params().getDefaultOutputFormat());
exportBufferAs(*doc_buffer, f);
break; break;
}
case LFUN_BUFFER_UPDATE: { case LFUN_BUFFER_UPDATE: {
d.asyncBufferProcessing(argument, d.asyncBufferProcessing(argument,

View File

@ -354,8 +354,9 @@ private:
/// ///
void insertPlaintextFile(docstring const & fname, void insertPlaintextFile(docstring const & fname,
bool asParagraph); bool asParagraph);
/// /// Open Export As ... dialog. \p iformat is the format the
bool exportBufferAs(Buffer & b); /// filter is initially set to.
bool exportBufferAs(Buffer & b, docstring const & iformat);
/// ///
enum RenameKind { LV_WRITE_AS, LV_VC_RENAME, LV_VC_COPY }; enum RenameKind { LV_WRITE_AS, LV_VC_RENAME, LV_VC_COPY };