X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiRef.cpp;h=d98a507b371d61ece7744b14900f688276016624;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=759b668d01fc695115b1b4bd202192e18b1cf831;hpb=9f3c7cf1ea1851cd77bd07b369a602a9608c265d;p=lyx.git diff --git a/src/frontends/qt4/GuiRef.cpp b/src/frontends/qt4/GuiRef.cpp index 759b668d01..d98a507b37 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,18 +40,26 @@ namespace lyx { namespace frontend { GuiRef::GuiRef(GuiView & lv) - : GuiCommand(lv, "ref", qt_("Cross-reference")) + : GuiDialog(lv, "ref", qt_("Cross-reference")), + params_(insetCode("ref")) { setupUi(this); - sort_ = false; at_ref_ = false; + // Enabling is set in updateRefs. Disable for now in case no + // call to updateContents follows (e.g. read-only documents). + sortCB->setEnabled(false); + caseSensitiveCB->setEnabled(false); + caseSensitiveCB->setChecked(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(closePB, SIGNAL(clicked()), this, SLOT(resetDialog())); + connect(this, SIGNAL(rejected()), this, SLOT(dialogRejected())); connect(typeCO, SIGNAL(activated(int)), this, SLOT(changed_adaptor())); @@ -62,10 +71,12 @@ GuiRef::GuiRef(GuiView & lv) this, SLOT(refHighlighted(QListWidgetItem *))); connect(refsLW, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged())); - connect(refsLW, SIGNAL(itemActivated(QListWidgetItem *)), + connect(refsLW, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(refSelected(QListWidgetItem *))); - connect(sortCB, SIGNAL(clicked(bool)), - this, SLOT(sortToggled(bool))); + connect(sortCB, SIGNAL(clicked()), + this, SLOT(sortToggled())); + connect(caseSensitiveCB, SIGNAL(clicked()), + this, SLOT(caseSensitiveToggled())); connect(gotoPB, SIGNAL(clicked()), this, SLOT(gotoClicked())); connect(updatePB, SIGNAL(clicked()), @@ -73,20 +84,20 @@ GuiRef::GuiRef(GuiView & lv) connect(bufferCO, SIGNAL(activated(int)), this, SLOT(updateClicked())); - setFocusProxy(refsLW); - bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); bc().setOK(okPB); bc().setApply(applyPB); bc().setCancel(closePB); bc().addReadOnly(refsLW); bc().addReadOnly(sortCB); + bc().addReadOnly(caseSensitiveCB); bc().addReadOnly(nameED); bc().addReadOnly(referenceED); bc().addReadOnly(typeCO); bc().addReadOnly(bufferCO); restored_buffer_ = -1; + active_buffer_ = -1; } @@ -156,9 +167,15 @@ void GuiRef::refSelected(QListWidgetItem * sel) } -void GuiRef::sortToggled(bool on) +void GuiRef::sortToggled() +{ + caseSensitiveCB->setEnabled(sortCB->isChecked()); + redoRefs(); +} + + +void GuiRef::caseSensitiveToggled() { - sort_ = on; redoRefs(); } @@ -169,7 +186,16 @@ void GuiRef::updateClicked() } -void GuiRef::reset_dialog() +void GuiRef::dialogRejected() +{ + resetDialog(); + // 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::resetDialog() { at_ref_ = false; setGotoRef(); @@ -179,7 +205,7 @@ void GuiRef::reset_dialog() void GuiRef::closeEvent(QCloseEvent * e) { slotClose(); - reset_dialog(); + resetDialog(); e->accept(); } @@ -202,24 +228,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); @@ -283,6 +311,11 @@ void GuiRef::gotoRef() at_ref_ = !at_ref_; } +inline bool caseInsensitiveLessThan(QString const & s1, QString const & s2) +{ + return s1.toLower() < s2.toLower(); +} + void GuiRef::redoRefs() { @@ -298,13 +331,20 @@ void GuiRef::redoRefs() // the first item inserted QString const oldSelection(referenceED->text()); - for (vector::const_iterator iter = refs_.begin(); - iter != refs_.end(); ++iter) { - refsLW->addItem(toqstr(*iter)); + QStringList refsStrings; + vector::const_iterator iter; + for (iter = refs_.begin(); iter != refs_.end(); ++iter) + refsStrings.append(toqstr(*iter)); + + if (sortCB->isEnabled() && sortCB->isChecked()) { + if(caseSensitiveCB->isEnabled() && caseSensitiveCB->isChecked()) + qSort(refsStrings.begin(), refsStrings.end()); + else + qSort(refsStrings.begin(), refsStrings.end(), + caseInsensitiveLessThan /*defined above*/); } - if (sort_) - refsLW->sortItems(); + refsLW->addItems(refsStrings); referenceED->setText(oldSelection); @@ -338,11 +378,17 @@ 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()); + caseSensitiveCB->setEnabled(sortCB->isEnabled() && sortCB->isChecked()); 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(); } @@ -367,10 +413,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"