From c85e24b0669936e15b35bf0f9b705ca6951b8297 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Wed, 18 Feb 2009 23:45:00 +0000 Subject: [PATCH] Fix bug 5785: http://bugzilla.lyx.org/show_bug.cgi?id=5785. Reference dialog update crash for read-only documents. Comments: * -1 is a valid return of bufferCO->currentIndex() so we need to test for it. * set the correct enabling of the button in case no call to updateContents follows. * remove unneeded call to setFocusProxy. The widget is either disabled or the focus proxy is set in updateRefs. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28547 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiRef.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/frontends/qt4/GuiRef.cpp b/src/frontends/qt4/GuiRef.cpp index 40da7f7431..b1144e3726 100644 --- a/src/frontends/qt4/GuiRef.cpp +++ b/src/frontends/qt4/GuiRef.cpp @@ -55,6 +55,12 @@ GuiRef::GuiRef(GuiView & lv) bufferCO->setEnabled(false); bufferCO->hide(); + // Enabling is set in updateRefs. Disable for now in case no + // call to updateContents follows (e.g. read-only documents). + sortCB->setEnabled(false); + refsLW->setEnabled(false); + gotoPB->setEnabled(false); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); @@ -82,8 +88,6 @@ GuiRef::GuiRef(GuiView & lv) connect(bufferCO, SIGNAL(activated(int)), this, SLOT(updateClicked())); - setFocusProxy(refsLW); - bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); bc().setOK(okPB); bc().setApply(applyPB); @@ -361,9 +365,12 @@ void GuiRef::redoRefs() void GuiRef::updateRefs() { refs_.clear(); - FileName const & name = theBufferList().fileNames()[bufferCO->currentIndex()]; - Buffer const * buf = theBufferList().getBuffer(name); - buf->getLabelList(refs_); + int const the_buffer = bufferCO->currentIndex(); + if (the_buffer != -1) { + FileName const & name = theBufferList().fileNames()[the_buffer]; + Buffer const * buf = theBufferList().getBuffer(name); + buf->getLabelList(refs_); + } sortCB->setEnabled(!refs_.empty()); refsLW->setEnabled(!refs_.empty()); // refsLW should only be the focus proxy when it is enabled