X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiRef.cpp;h=d344ab64faaa77255f82ef56983b4a238cb9e2c5;hb=3373aa588cbd2d2e463dd1369cbdb4316764ee21;hp=6c3b554b680e4ce88b11575dda036c6085df9498;hpb=9439b6e6e0cf950aafe8ce8d76d380c543110db7;p=lyx.git diff --git a/src/frontends/qt4/GuiRef.cpp b/src/frontends/qt4/GuiRef.cpp index 6c3b554b68..d344ab64fa 100644 --- a/src/frontends/qt4/GuiRef.cpp +++ b/src/frontends/qt4/GuiRef.cpp @@ -4,7 +4,7 @@ * Licence details can be found in the file COPYING. * * \author John Levon - * \author Jürgen Spitzmüller + * \author Jürgen Spitzmüller * * Full author contact details are available in file CREDITS. */ @@ -22,7 +22,8 @@ #include "insets/InsetRef.h" #include "support/FileName.h" -#include "support/filetools.h" // MakeAbsPath, MakeDisplayPath +#include "support/FileNameList.h" +#include "support/filetools.h" // makeAbsPath, makeDisplayPath #include #include @@ -39,19 +40,31 @@ namespace lyx { namespace frontend { GuiRef::GuiRef(GuiView & lv) - : GuiCommand(lv, "ref") + : GuiDialog(lv, "ref", qt_("Cross-reference")), + params_(insetCode("ref")) { setupUi(this); - setViewTitle(_("Cross-reference")); - sort_ = false; at_ref_ = false; + //FIXME: when/if we support the xr package for cross-reference + //between independant files. Those can be re-enabled. + refsL->setEnabled(false); + refsL->hide(); + 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())); connect(closePB, SIGNAL(clicked()), this, SLOT(reset_dialog())); - connect(this, SIGNAL(rejected()), this, SLOT(reset_dialog())); + connect(this, SIGNAL(rejected()), this, SLOT(dialog_rejected())); connect(typeCO, SIGNAL(activated(int)), this, SLOT(changed_adaptor())); @@ -65,8 +78,8 @@ GuiRef::GuiRef(GuiView & lv) this, SLOT(selectionChanged())); connect(refsLW, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(refSelected(QListWidgetItem *))); - connect(sortCB, SIGNAL(clicked(bool)), - this, SLOT(sortToggled(bool))); + connect(sortCB, SIGNAL(clicked()), + this, SLOT(sortToggled())); connect(gotoPB, SIGNAL(clicked()), this, SLOT(gotoClicked())); connect(updatePB, SIGNAL(clicked()), @@ -74,8 +87,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); @@ -88,6 +99,7 @@ GuiRef::GuiRef(GuiView & lv) bc().addReadOnly(bufferCO); restored_buffer_ = -1; + active_buffer_ = -1; } @@ -157,9 +169,8 @@ void GuiRef::refSelected(QListWidgetItem * sel) } -void GuiRef::sortToggled(bool on) +void GuiRef::sortToggled() { - sort_ = on; redoRefs(); } @@ -170,6 +181,15 @@ void GuiRef::updateClicked() } +void GuiRef::dialog_rejected() +{ + reset_dialog(); + // We have to do this manually, instead of calling slotClose(), because + // the dialog has already been made invisible before rejected() triggers. + Dialog::disconnect(); +} + + void GuiRef::reset_dialog() { at_ref_ = false; @@ -181,7 +201,7 @@ void GuiRef::closeEvent(QCloseEvent * e) { slotClose(); reset_dialog(); - GuiDialog::closeEvent(e); + e->accept(); } @@ -203,24 +223,26 @@ void GuiRef::updateContents() if (!typeAllowed()) typeCO->setCurrentIndex(0); - sortCB->setChecked(sort_); - // insert buffer list bufferCO->clear(); - vector buffers = theBufferList().getFileNames(); - for (vector::iterator it = buffers.begin(); + FileNameList const & buffers = theBufferList().fileNames(); + for (FileNameList::const_iterator it = buffers.begin(); it != buffers.end(); ++it) { - bufferCO->addItem(toqstr(lyx::to_utf8(makeDisplayPath(*it)))); + bufferCO->addItem(toqstr(makeDisplayPath(it->absFilename()))); } + int const thebuffer = theBufferList().bufferNum(buffer().fileName()); // restore the buffer combo setting for new insets if (params_["reference"].empty() && restored_buffer_ != -1 - && restored_buffer_ < bufferCO->count()) + && restored_buffer_ < bufferCO->count() && thebuffer == active_buffer_) bufferCO->setCurrentIndex(restored_buffer_); else { - int num = theBufferList().bufferNum(buffer().absFileName()); + int const num = theBufferList().bufferNum(buffer().fileName()); bufferCO->setCurrentIndex(num); + if (thebuffer != active_buffer_) + restored_buffer_ = num; } + active_buffer_ = thebuffer; updateRefs(); bc().setValid(false); @@ -304,7 +326,7 @@ void GuiRef::redoRefs() refsLW->addItem(toqstr(*iter)); } - if (sort_) + if (sortCB->isEnabled() && sortCB->isChecked()) refsLW->sortItems(); referenceED->setText(oldSelection); @@ -339,11 +361,16 @@ void GuiRef::redoRefs() void GuiRef::updateRefs() { refs_.clear(); - string const name = theBufferList().getFileNames()[bufferCO->currentIndex()]; - Buffer const * buf = theBufferList().getBuffer(makeAbsPath(name).absFilename()); - 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 + setFocusProxy(refs_.empty() ? 0 : refsLW); gotoPB->setEnabled(!refs_.empty()); redoRefs(); } @@ -368,10 +395,25 @@ void GuiRef::gotoBookmark() } +bool GuiRef::initialiseParams(std::string const & data) +{ + InsetCommand::string2params("ref", data, params_); + return true; +} + + +void GuiRef::dispatchParams() +{ + std::string const lfun = InsetCommand::params2string("ref", params_); + dispatch(FuncRequest(getLfun(), lfun)); +} + + + Dialog * createGuiRef(GuiView & lv) { return new GuiRef(lv); } } // namespace frontend } // namespace lyx -#include "GuiRef_moc.cpp" +#include "moc_GuiRef.cpp"