]> git.lyx.org Git - features.git/commitdiff
Add ignorelang option to file-insert
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 26 Mar 2019 09:09:55 +0000 (10:09 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:21 +0000 (15:48 +0200)
This is useful for inserted files with no real text content

lib/RELEASE-NOTES
src/BufferView.cpp
src/BufferView.h
src/LyXAction.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h

index 9d52b53c48d2f60b66192484291f47414567162c..7fee69a461743b4a3bda40861056543cd25bafa6 100644 (file)
 
 * 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:
 
index 900207c23871e6e684e3896ef6ac68e7471e627b..ba8c768ca4b1d0120eae5a35b54fd45b57b2f2f8 100644 (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 {
index 5bad57ca0ece1d8d88c4017fe9ffd516cb99dc07..520ecdb0d571b76b328a7e2c43996fd9125d79f4 100644 (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.
index 92734a202a5d4e9d97f73cef0e130abde9671362..969ef64be0b265de85fbe491b80e678a6ecdfb12 100644 (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 },
index dfab5d7230e5da6144b7677b3732f0a17fbf122f..98dba1dfa5544be735f2d36e1ee2bfb0b1de8f8d 100644 (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: {
index 493b070b252eef190ea1a09abed82e87fcdc39de..fa36f7ff8b79406883897e6ca3c02c9d1a7e19c0 100644 (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.