From e014f3fabf717c37c88a8747d8f8a128f63c564d Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Fri, 15 Nov 2013 09:20:07 +0100 Subject: [PATCH] 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 --- src/LyXAction.cpp | 11 +++++++++-- src/frontends/qt4/FileDialog.cpp | 2 ++ src/frontends/qt4/GuiView.cpp | 26 +++++++++++++++++++------- src/frontends/qt4/GuiView.h | 5 +++-- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index d0a67ed8eb..3a8de5fa2e 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -3075,8 +3075,15 @@ void LyXAction::init() { 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-as + * \li Action: Opens a dialog for exporting the current buffer. + * \li Syntax: buffer-export-as [] + * \li Params: 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 * \endvar */ diff --git a/src/frontends/qt4/FileDialog.cpp b/src/frontends/qt4/FileDialog.cpp index 0d6abdc5b6..988a8d006b 100644 --- a/src/frontends/qt4/FileDialog.cpp +++ b/src/frontends/qt4/FileDialog.cpp @@ -106,6 +106,8 @@ FileDialog::Result FileDialog::save(QString const & path, dlg.setFileMode(QFileDialog::AnyFile); dlg.setAcceptMode(QFileDialog::AcceptSave); dlg.setConfirmOverwrite(false); + if (selectedFilter != 0 && !selectedFilter->isEmpty()) + dlg.selectNameFilter(*selectedFilter); if (!suggested.isEmpty()) dlg.selectFile(suggested); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 4d769c189c..b9f14a33ce 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -2376,7 +2376,7 @@ struct PrettyNameComparator }; -bool GuiView::exportBufferAs(Buffer & b) +bool GuiView::exportBufferAs(Buffer & b, docstring const & iformat) { FileName fname = b.fileName(); @@ -2395,6 +2395,8 @@ bool GuiView::exportBufferAs(Buffer & b) sort(export_formats.begin(), export_formats.end(), cmp); vector::const_iterator fit = export_formats.begin(); map fmap; + QString filter; + string ext; for (; fit != export_formats.end(); ++fit) { docstring const loc_prettyname = translateIfPossible(from_utf8((*fit)->prettyname())); @@ -2403,12 +2405,18 @@ bool GuiView::exportBufferAs(Buffer & b) from_ascii((*fit)->extension()))); types << loc_filter; 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 = dlg.save(toqstr(fname.onlyPath().absFileName()), types, - toqstr(fname.onlyFileName()), + toqstr(ofname), &filter); if (result.first != FileDialog::Chosen) return false; @@ -2436,7 +2444,7 @@ bool GuiView::exportBufferAs(Buffer & b) text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel")); switch (ret) { case 0: break; - case 1: return exportBufferAs(b); + case 1: return exportBufferAs(b, from_ascii(fmt_name)); case 2: return false; } } @@ -3315,7 +3323,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr) break; } if (!target_dir.isDirWritable()) { - exportBufferAs(*doc_buffer); + exportBufferAs(*doc_buffer, cmd.argument()); break; } /* TODO/Review: Is it a problem to also export the children? @@ -3330,10 +3338,14 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr) break; } - case LFUN_BUFFER_EXPORT_AS: + case LFUN_BUFFER_EXPORT_AS: { 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; + } case LFUN_BUFFER_UPDATE: { d.asyncBufferProcessing(argument, diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 9220538f7e..17e60df7dd 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -354,8 +354,9 @@ private: /// void insertPlaintextFile(docstring const & fname, bool asParagraph); - /// - bool exportBufferAs(Buffer & b); + /// Open Export As ... dialog. \p iformat is the format the + /// filter is initially set to. + bool exportBufferAs(Buffer & b, docstring const & iformat); /// enum RenameKind { LV_WRITE_AS, LV_VC_RENAME, LV_VC_COPY };