mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
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:
parent
ed268ac9f7
commit
e014f3fabf
@ -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 [<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
|
||||
* \endvar
|
||||
*/
|
||||
|
@ -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);
|
||||
|
@ -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<Format const *>::const_iterator fit = export_formats.begin();
|
||||
map<QString, string> 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,
|
||||
|
@ -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 };
|
||||
|
Loading…
Reference in New Issue
Block a user