]> git.lyx.org Git - lyx.git/blobdiff - src/LyXFunc.cpp
white space -> tabs
[lyx.git] / src / LyXFunc.cpp
index 04decddf8a080eb5dc2bf546c5e2ebcb303dd69f..f549847e39ace99b6ce4d1f42bc7ee95d9573961 100644 (file)
@@ -1410,23 +1410,34 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
 
                case LFUN_BUFFER_CHILD_OPEN: {
+                       // takes an optional argument, "|bool", at the end
+                       // indicating whether this file is being opened automatically
+                       // by LyX itself, in which case we will not want to switch
+                       // buffers after opening. The default is false, so in practice
+                       // it is used only when true.
                        BOOST_ASSERT(lyx_view_);
-                       FileName const filename =
+                       int const arglength = argument.length();
+                       FileName filename;
+                       bool autoOpen = false;
+                       if (argument.substr(arglength - 5, 5) == "|true") {
+                               autoOpen = true;
+                               filename = makeAbsPath(argument.substr(0, arglength - 5), 
+                                       lyx_view_->buffer()->filePath());
+                       } else if (argument.substr(arglength - 6, 6) == "|false") {
+                               filename = makeAbsPath(argument.substr(0, arglength - 6), 
+                                       lyx_view_->buffer()->filePath());
+                       } else filename = 
                                makeAbsPath(argument, lyx_view_->buffer()->filePath());
                        view()->saveBookmark(false);
-                       string const parentfilename = lyx_view_->buffer()->fileName();
-                       if (theBufferList().exists(filename.absFilename()))
-                               lyx_view_->setBuffer(theBufferList().getBuffer(filename.absFilename()));
-                       else
-                               if (lyx_view_->loadLyXFile(filename)) {
-                                       // Set the parent name of the child document.
-                                       // This makes insertion of citations and references in the child work,
-                                       // when the target is in the parent or another child document.
-                                       lyx_view_->buffer()->setParentName(parentfilename);
-                                       setMessage(bformat(_("Opening child document %1$s..."),
-                                                makeDisplayPath(filename.absFilename())));
-                               } else
-                                       setMessage(_("Document not loaded."));
+                       if (theBufferList().exists(filename.absFilename())) {
+                               Buffer * buf = theBufferList().getBuffer(filename.absFilename());
+                               if (!autoOpen)
+                                       lyx_view_->setBuffer(buf, true);
+                               else
+                                       buf->setParentName(lyx_view_->buffer()->fileName());
+                       } else
+                               lyx_view_->loadLyXFile(filename, true, true, autoOpen);
+
                        break;
                }