Add ignorelang option to file-insert

This is useful for inserted files with no real text content
This commit is contained in:
Juergen Spitzmueller 2019-03-26 10:09:55 +01:00
parent 2871b484a1
commit 2ed3b22a06
6 changed files with 23 additions and 9 deletions

View File

@ -51,6 +51,10 @@
* info-insert buffer vcs-*: renamed to info-insert vcs *
* file-insert: optional second parameter "ignorelang" to make the insertion
ignore the inserted file's main language (and rather adapt it to the insertion
context's language).
!!!The following LyX functions have been removed in 2.4:

View File

@ -2875,7 +2875,7 @@ void BufferView::updatePosCache()
}
void BufferView::insertLyXFile(FileName const & fname)
void BufferView::insertLyXFile(FileName const & fname, bool const ignorelang)
{
LASSERT(d->cursor_.inTexted(), return);
@ -2893,8 +2893,12 @@ void BufferView::insertLyXFile(FileName const & fname)
ErrorList & el = buffer_.errorList("Parse");
// Copy the inserted document error list into the current buffer one.
el = buf.errorList("Parse");
ParagraphList & pars = buf.paragraphs();
if (ignorelang)
// set main language of imported file to context language
buf.changeLanguage(buf.language(), d->cursor_.getFont().language());
buffer_.undo().recordUndo(d->cursor_);
cap::pasteParagraphList(d->cursor_, buf.paragraphs(),
cap::pasteParagraphList(d->cursor_, pars,
buf.params().documentClassPtr(), el);
res = _("Document %1$s inserted.");
} else {

View File

@ -340,7 +340,7 @@ public:
// Insert plain text file (if filename is empty, prompt for one)
void insertPlaintextFile(support::FileName const & f, bool asParagraph);
///
void insertLyXFile(support::FileName const & f);
void insertLyXFile(support::FileName const & f, bool const ignorelang = false);
/// save temporary bookmark for jump back navigation
void bookmarkEditPosition();
/// Find and return the inset associated with given dialog name.

View File

@ -1571,8 +1571,10 @@ void LyXAction::init()
/*!
* \var lyx::FuncCode lyx::LFUN_FILE_INSERT
* \li Action: Inserts another LyX file.
* \li Syntax: file-insert [<FILE>]
* \li Syntax: file-insert [<FILE>] [ignorelang]
* \li Params: <FILE>: Filename to be inserted.
* ignorelang: If given, the (main) language of the inserted file
* is ignored (the context language is used).
* \endvar
*/
{ LFUN_FILE_INSERT, "file-insert", Noop, Edit },

View File

@ -2605,7 +2605,7 @@ void GuiView::newDocument(string const & filename, string templatefile,
}
void GuiView::insertLyXFile(docstring const & fname)
void GuiView::insertLyXFile(docstring const & fname, bool ignorelang)
{
BufferView * bv = documentBufferView();
if (!bv)
@ -2644,7 +2644,7 @@ void GuiView::insertLyXFile(docstring const & fname)
}
}
bv->insertLyXFile(filename);
bv->insertLyXFile(filename, ignorelang);
bv->buffer().errors("Parse");
}
@ -4049,9 +4049,13 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
menu->exec(QCursor::pos());
break;
case LFUN_FILE_INSERT:
insertLyXFile(cmd.argument());
case LFUN_FILE_INSERT: {
if (cmd.getArg(1) == "ignorelang")
insertLyXFile(from_utf8(cmd.getArg(0)), true);
else
insertLyXFile(cmd.argument());
break;
}
case LFUN_FILE_INSERT_PLAINTEXT:
case LFUN_FILE_INSERT_PLAINTEXT_PARA: {

View File

@ -373,7 +373,7 @@ private:
///
void toggleFullScreen();
///
void insertLyXFile(docstring const & fname);
void insertLyXFile(docstring const & fname, bool ignorelang = false);
///
/// Open Export As ... dialog. \p iformat is the format the
/// filter is initially set to.