* 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.
*/
#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 <QLineEdit>
#include <QCheckBox>
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()));
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()),
connect(bufferCO, SIGNAL(activated(int)),
this, SLOT(updateClicked()));
- setFocusProxy(refsLW);
-
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
bc().setOK(okPB);
bc().setApply(applyPB);
bc().addReadOnly(bufferCO);
restored_buffer_ = -1;
+ active_buffer_ = -1;
}
}
-void GuiRef::sortToggled(bool on)
+void GuiRef::sortToggled()
{
- sort_ = on;
redoRefs();
}
}
+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;
{
slotClose();
reset_dialog();
- GuiDialog::closeEvent(e);
+ e->accept();
}
if (!typeAllowed())
typeCO->setCurrentIndex(0);
- sortCB->setChecked(sort_);
-
// insert buffer list
bufferCO->clear();
- vector<string> buffers = theBufferList().getFileNames();
- for (vector<string>::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);
refsLW->addItem(toqstr(*iter));
}
- if (sort_)
+ if (sortCB->isEnabled() && sortCB->isChecked())
refsLW->sortItems();
referenceED->setText(oldSelection);
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();
}
}
+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"