work_area_->bufferView().setBuffer(b);
- //FIXME This would be a little simpler if setBuffer returned the buffer.
+ //FIXME This would be a little simpler if setBuffer returned the buffer.
Buffer * newBuffer = work_area_->bufferView().buffer();
if (newBuffer) {
- if (child_document && newBuffer != oldBuffer) {
+ 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.
newBuffer->setParentName(parentfilename);
- // updateLabels() will emit Buffer::structureChanged() so better
- // connect it before.
- connectBuffer(*newBuffer);
- // Update the labels and section numbering.
+ // Update the labels and section numbering to the new master Buffer.
updateLabels(*newBuffer->getMasterBuffer());
- } else
- connectBuffer(*newBuffer);
+ }
+
+ 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());
+
+ 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)
if (oldBuffer)
parentfilename = oldBuffer->fileName();
- Buffer * newBuffer =
- work_area_->bufferView().loadLyXFile(filename, auto_open);
+ Buffer * newBuffer = checkAndLoadLyXFile(filename);
- if (!newBuffer) {
+ if (!newBuffer) {
message(_("Document not loaded."));
- updateStatusBar();
- busy(false);
- work_area_->redraw();
- return false;
- }
-
- if (!auto_open) {
- disconnectBuffer();
- connectBuffer(*newBuffer);
- }
-
- showErrorList("Parse");
-
- if (child_document && newBuffer != 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.
- newBuffer->setParentName(parentfilename);
- message(bformat(_("Opening child document %1$s..."),
- makeDisplayPath(filename.absFilename())));
- }
-
- // Update the labels and section numbering.
- updateLabels(*newBuffer->getMasterBuffer());
-
- // 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());
- }
- }
-
- if (tolastfiles)
- LyX::ref().session().lastFiles().add(filename);
-
- // FIXME We definitely don't have to do all of this if auto_open...
- // The question is: What do we have to do here if we've loaded a new
- // file but haven't switched buffers? I'm guessing we can skip the
- // layout bit and the title.
- // and if we have already switched buffers...won't all of this have been
- // done already in setBuffer()? So why does it also need doing here?
- // In fact, won't a lot of what's above already have been done? E.g.,
- // the connecting and disconnecting of buffers will have been done
- // already in setBuffer().
- // This bit of cleanup is post-1.5.0....
- updateMenubar();
- updateToolbars();
- updateLayoutChoice();
- updateWindowTitle();
- updateTab();
- updateStatusBar();
+ updateStatusBar();
+ busy(false);
+ work_area_->redraw();
+ return false;
+ }
+
+ if (child_document && newBuffer != 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.
+ newBuffer->setParentName(parentfilename);
+ message(bformat(_("Opening child document %1$s..."),
+ makeDisplayPath(filename.absFilename())));
+ }
+
+ // Update the labels and section numbering.
+ updateLabels(*newBuffer->getMasterBuffer());
+
+ bool const parse_error = !newBuffer->errorList("Parse").empty();
+ if (parse_error || !auto_open) {
+ 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 (tolastfiles)
+ LyX::ref().session().lastFiles().add(filename);
+
busy(false);
- work_area_->redraw();
return true;
}
}
-ToolbarInfo::Flags LyXView::getToolbarState(string const & name)
+ToolbarInfo * LyXView::getToolbarInfo(string const & name)
{
- return toolbars_->getToolbarState(name);
+ return toolbars_->getToolbarInfo(name);
}