]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/LyXView.cpp
Get rid of a few warnings.
[lyx.git] / src / frontends / LyXView.cpp
index 095a351c799029d64ba11c040350c93672ec7f38..f2278c8662a6bd42fb87d99db16c08c6426657fe 100644 (file)
@@ -68,7 +68,7 @@ using std::string;
 
 using lyx::frontend::ControlCommandBuffer;
 
-string current_layout;
+docstring current_layout;
 
 
 LyXView::LyXView(int id)
@@ -133,20 +133,21 @@ void LyXView::setBuffer(Buffer * b, bool child_document)
        // parentfilename will be used in case when we switch to a child
        // document (hence when child_document is true)
        string parentfilename;
-       if (oldBuffer) {
+       if (oldBuffer)
                parentfilename = oldBuffer->fileName();
-               disconnectBuffer();
-       }
 
        if (!b && theBufferList().empty())
                getDialogs().hideBufferDependent();
 
-       work_area_->bufferView().setBuffer(b);
+       Buffer * newBuffer = work_area_->bufferView().setBuffer(b);
 
-       //FIXME This would be a little simpler if setBuffer returned the buffer.
-       Buffer * newBuffer = work_area_->bufferView().buffer();
        if (newBuffer) {
-               if (child_document && newBuffer->getMasterBuffer() != oldBuffer) {
+               //Are we closing an oldBuffer which was a child document?
+               if (!b && oldBuffer && oldBuffer->getMasterBuffer() != oldBuffer)
+                       // Update the labels and section numbering of its master Buffer.
+                       updateLabels(*oldBuffer->getMasterBuffer());
+               //Are we opening a new child document?
+               else if (child_document && newBuffer->getMasterBuffer() != oldBuffer) {
                        // 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.
@@ -154,20 +155,31 @@ void LyXView::setBuffer(Buffer * b, bool child_document)
                        // Update the labels and section numbering to the new master Buffer.
                        updateLabels(*newBuffer->getMasterBuffer());
                }
-
-               if (!b && oldBuffer && oldBuffer->getMasterBuffer() != oldBuffer)
-                       // We are closing oldBuffer which was a child document so we
-                       // must update the labels and section numbering of its master
-                       // Buffer.
-                       updateLabels(*oldBuffer->getMasterBuffer());
-
+               //Now that all the updating of the old buffer has been done, we can
+               //connect the new buffer. Note that this will also disconnect the old 
+               //buffer, if such there is.
+               //FIXME Is it clear that this should go right here? Or should it go
+               //earlier before the previous if (in which case we'd remove the "else")?
                connectBuffer(*newBuffer);
 
+               /* FIXME: We need to rebuild the Toc dialog before the others even
+               if it will be rebuilt again in the next line. This avoid a crash when
+               other dialogs are rebuilt before the Toc dialog. The reason is
+               that closing a Buffer triggers an update of all opened dialogs
+               when dispatching LFUN_DIALOG_UPDATE (hence the patch).
+               The path is as following:
+                       setBuffer() -> updateBufferDependent() -> RestoreButton() -> LFUN
+               The problem here is that the Toc dialog has not been
+               reconstructed (because it comes after in the list of dialogs). */
+               updateToc();
+
                // Buffer-dependent dialogs should be updated or
                // hidden. This should go here because some dialogs (eg ToC)
                // require bv_->text.
                getDialogs().updateBufferDependent(true);
-       }
+       } else
+               //Disconnect the old buffer...there's no new one.
+               disconnectBuffer();
 
        if (quitting)
                return;
@@ -194,6 +206,7 @@ bool LyXView::loadLyXFile(FileName const & filename, bool tolastfiles,
        if (oldBuffer)
                parentfilename = oldBuffer->fileName();
 
+       bool alreadyLoaded = checkIfLoaded(filename);
        Buffer * newBuffer = checkAndLoadLyXFile(filename);
 
        if (!newBuffer) {
@@ -217,33 +230,35 @@ bool LyXView::loadLyXFile(FileName const & filename, bool tolastfiles,
        updateLabels(*newBuffer->getMasterBuffer());
 
        bool const parse_error = !newBuffer->errorList("Parse").empty();
-       if (parse_error || !auto_open) {
+       bool const need_switch = parse_error || !auto_open;
+       if (need_switch) {
                setBuffer(newBuffer, child_document);
-               showErrorList("Parse");
-       }
-
-       // scroll to the position when the file was last closed
-       if (!auto_open && lyxrc.use_lastfilepos) {
-               pit_type pit;
-               pos_type pos;
-               boost::tie(pit, pos) = LyX::ref().session().lastFilePos().load(filename);
-               // if successfully move to pit (returned par_id is not zero),
-               // update metrics and reset font
-               if (work_area_->bufferView().moveToPosition(pit, pos, 0, 0).get<1>()) {
-                       if (work_area_->bufferView().fitCursor())
-                               work_area_->bufferView().updateMetrics(false);
-                       newBuffer->text().setCurrentFont(work_area_->bufferView().cursor());
-                       updateMenubar();
-                       updateToolbars();
-                       updateLayoutChoice();
-                       updateStatusBar();
-                       work_area_->redraw();
+               if (!alreadyLoaded) {
+                       if (parse_error)
+                               showErrorList("Parse");
+                       // scroll to the position when the file was last closed
+                       if (lyxrc.use_lastfilepos) {
+                               pit_type pit;
+                               pos_type pos;
+                               boost::tie(pit, pos) = LyX::ref().session().lastFilePos().load(filename);
+                               // if successfully move to pit (returned par_id is not zero),
+                               // update metrics and reset font
+                               if (work_area_->bufferView().moveToPosition(pit, pos, 0, 0).get<1>()) {
+                                       if (work_area_->bufferView().fitCursor())
+                                               work_area_->bufferView().updateMetrics(false);
+                                       newBuffer->text().setCurrentFont(work_area_->bufferView().cursor());
+                                       updateMenubar();
+                                       updateToolbars();
+                                       updateLayoutChoice();
+                                       updateStatusBar();
+                                       work_area_->redraw();
+                               }
+                       }
+               if (tolastfiles)
+                       LyX::ref().session().lastFiles().add(filename);
                }
        }
 
-       if (tolastfiles)
-               LyX::ref().session().lastFiles().add(filename);
-
        busy(false);
        return true;
 }
@@ -406,9 +421,9 @@ void LyXView::updateToolbars()
 }
 
 
-ToolbarInfo::Flags LyXView::getToolbarState(string const & name)
+ToolbarInfo * LyXView::getToolbarInfo(string const & name)
 {
-       return toolbars_->getToolbarState(name);
+       return toolbars_->getToolbarInfo(name);
 }
 
 
@@ -462,7 +477,7 @@ void LyXView::updateLayoutChoice()
        }
 
        BOOST_ASSERT(work_area_);
-       string const & layout = work_area_->bufferView().cursor().
+       docstring const & layout = work_area_->bufferView().cursor().
                innerParagraph().layout()->name();
 
        if (layout != current_layout) {