#include <config.h>
#include "GuiRef.h"
+
+#include "Buffer.h"
+#include "BufferList.h"
+#include "FuncRequest.h"
+
#include "qt_helpers.h"
#include "insets/InsetRef.h"
+#include "support/FileName.h"
+#include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
+
#include <QLineEdit>
#include <QCheckBox>
#include <QListWidget>
#include <QToolTip>
#include <QCloseEvent>
-
-using std::vector;
-using std::string;
-
+using namespace std;
+using namespace lyx::support;
namespace lyx {
namespace frontend {
-/////////////////////////////////////////////////////////////////////
-//
-// GuiRefDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-GuiRefDialog::GuiRefDialog(GuiRef * form)
- : form_(form)
+GuiRef::GuiRef(GuiView & lv)
+ : GuiCommand(lv, "ref", qt_("Cross-reference"))
{
setupUi(this);
- connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
- connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
- connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
+ sort_ = false;
+ at_ref_ = 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(typeCO, SIGNAL(activated(int)),
this, SLOT(changed_adaptor()));
- connect(referenceED, SIGNAL(textChanged(const QString &)),
+ connect(referenceED, SIGNAL(textChanged(QString)),
this, SLOT(changed_adaptor()));
- connect(nameED, SIGNAL(textChanged(const QString &)),
+ connect(nameED, SIGNAL(textChanged(QString)),
this, SLOT(changed_adaptor()));
connect(refsLW, SIGNAL(itemClicked(QListWidgetItem *)),
this, SLOT(refHighlighted(QListWidgetItem *)));
this, SLOT(updateClicked()));
setFocusProxy(refsLW);
-}
-void GuiRefDialog::show()
-{
- QDialog::show();
+ bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
+ bc().setOK(okPB);
+ bc().setApply(applyPB);
+ bc().setCancel(closePB);
+ bc().addReadOnly(refsLW);
+ bc().addReadOnly(sortCB);
+ bc().addReadOnly(nameED);
+ bc().addReadOnly(referenceED);
+ bc().addReadOnly(typeCO);
+ bc().addReadOnly(bufferCO);
+
+ restored_buffer_ = -1;
}
-void GuiRefDialog::changed_adaptor()
+void GuiRef::changed_adaptor()
{
- form_->changed();
+ changed();
}
-void GuiRefDialog::gotoClicked()
+void GuiRef::gotoClicked()
{
- form_->gotoRef();
+ gotoRef();
}
-void GuiRefDialog::selectionChanged()
+
+void GuiRef::selectionChanged()
{
- if (form_->readOnly())
+ if (isBufferReadonly())
return;
QList<QListWidgetItem *> selections = refsLW->selectedItems();
}
-void GuiRefDialog::refHighlighted(QListWidgetItem * sel)
+void GuiRef::refHighlighted(QListWidgetItem * sel)
{
- if (form_->readOnly())
+ if (isBufferReadonly())
return;
/* int const cur_item = refsLW->currentRow();
if (cur_item_selected)
referenceED->setText(sel->text());
- if (form_->at_ref_)
- form_->gotoRef();
+ if (at_ref_)
+ gotoRef();
gotoPB->setEnabled(true);
- if (form_->typeAllowed())
+ if (typeAllowed())
typeCO->setEnabled(true);
- if (form_->nameAllowed())
+ if (nameAllowed())
nameED->setEnabled(true);
}
-void GuiRefDialog::refSelected(QListWidgetItem * sel)
+void GuiRef::refSelected(QListWidgetItem * sel)
{
- if (form_->readOnly())
+ if (isBufferReadonly())
return;
/* int const cur_item = refsLW->currentRow();
if (cur_item_selected)
referenceED->setText(sel->text());
// <enter> or double click, inserts ref and closes dialog
- form_->slotOK();
+ slotOK();
}
-void GuiRefDialog::sortToggled(bool on)
+void GuiRef::sortToggled(bool on)
{
- form_->sort_ = on;
- form_->redoRefs();
+ sort_ = on;
+ redoRefs();
}
-void GuiRefDialog::updateClicked()
+void GuiRef::updateClicked()
{
- form_->updateRefs();
+ updateRefs();
}
-void GuiRefDialog::reset_dialog() {
- form_->at_ref_ = false;
- form_->setGotoRef();
+void GuiRef::reset_dialog()
+{
+ at_ref_ = false;
+ setGotoRef();
}
-void GuiRefDialog::closeEvent(QCloseEvent * e)
+void GuiRef::closeEvent(QCloseEvent * e)
{
- form_->slotWMHide();
+ slotClose();
reset_dialog();
e->accept();
}
-/////////////////////////////////////////////////////////////////////
-//
-// GuiRef
-//
-/////////////////////////////////////////////////////////////////////
-
-
-GuiRef::GuiRef(GuiDialog & parent)
- : GuiView<GuiRefDialog>(parent, _("Cross-reference")),
- sort_(false), at_ref_(false)
-{
-}
-
-
-void GuiRef::build_dialog()
-{
- dialog_.reset(new GuiRefDialog(this));
-
- bc().setOK(dialog_->okPB);
- bc().setApply(dialog_->applyPB);
- bc().setCancel(dialog_->closePB);
- bc().addReadOnly(dialog_->refsLW);
- bc().addReadOnly(dialog_->sortCB);
- bc().addReadOnly(dialog_->nameED);
- bc().addReadOnly(dialog_->referenceED);
- bc().addReadOnly(dialog_->typeCO);
- bc().addReadOnly(dialog_->bufferCO);
-
- restored_buffer_ = -1;
-}
-
-
-void GuiRef::update_contents()
+void GuiRef::updateContents()
{
- InsetCommandParams const & params = controller().params();
-
- int orig_type = dialog_->typeCO->currentIndex();
+ int orig_type = typeCO->currentIndex();
- dialog_->referenceED->setText(toqstr(params["reference"]));
+ referenceED->setText(toqstr(params_["reference"]));
- dialog_->nameED->setText(toqstr(params["name"]));
- dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
+ nameED->setText(toqstr(params_["name"]));
+ nameED->setReadOnly(!nameAllowed() && !isBufferReadonly());
// restore type settings for new insets
- if (params["reference"].empty())
- dialog_->typeCO->setCurrentIndex(orig_type);
+ if (params_["reference"].empty())
+ typeCO->setCurrentIndex(orig_type);
else
- dialog_->typeCO->setCurrentIndex(InsetRef::getType(params.getCmdName()));
- dialog_->typeCO->setEnabled(typeAllowed() && !readOnly());
+ typeCO->setCurrentIndex(InsetRef::getType(params_.getCmdName()));
+ typeCO->setEnabled(typeAllowed() && !isBufferReadonly());
if (!typeAllowed())
- dialog_->typeCO->setCurrentIndex(0);
+ typeCO->setCurrentIndex(0);
- dialog_->sortCB->setChecked(sort_);
+ sortCB->setChecked(sort_);
// insert buffer list
- dialog_->bufferCO->clear();
- vector<string> const buffers = controller().getBufferList();
- for (vector<string>::const_iterator it = buffers.begin();
- it != buffers.end(); ++it) {
- dialog_->bufferCO->addItem(toqstr(*it));
+ bufferCO->clear();
+ vector<string> buffers = theBufferList().getFileNames();
+ for (vector<string>::iterator it = buffers.begin();
+ it != buffers.end(); ++it) {
+ bufferCO->addItem(toqstr(lyx::to_utf8(makeDisplayPath(*it))));
}
+
// restore the buffer combo setting for new insets
- if (params["reference"].empty() && restored_buffer_ != -1
- && restored_buffer_ < dialog_->bufferCO->count())
- dialog_->bufferCO->setCurrentIndex(restored_buffer_);
- else
- dialog_->bufferCO->setCurrentIndex(controller().getBufferNum());
+ if (params_["reference"].empty() && restored_buffer_ != -1
+ && restored_buffer_ < bufferCO->count())
+ bufferCO->setCurrentIndex(restored_buffer_);
+ else {
+ int num = theBufferList().bufferNum(buffer().absFileName());
+ bufferCO->setCurrentIndex(num);
+ }
updateRefs();
bc().setValid(false);
}
-void GuiRef::apply()
+void GuiRef::applyView()
{
- InsetCommandParams & params = controller().params();
+ last_reference_ = referenceED->text();
- last_reference_ = dialog_->referenceED->text();
+ params_.setCmdName(InsetRef::getName(typeCO->currentIndex()));
+ params_["reference"] = qstring_to_ucs4(last_reference_);
+ params_["name"] = qstring_to_ucs4(nameED->text());
- params.setCmdName(InsetRef::getName(dialog_->typeCO->currentIndex()));
- params["reference"] = qstring_to_ucs4(last_reference_);
- params["name"] = qstring_to_ucs4(dialog_->nameED->text());
-
- restored_buffer_ = dialog_->bufferCO->currentIndex();
+ restored_buffer_ = bufferCO->currentIndex();
}
bool GuiRef::nameAllowed()
{
- Kernel::DocType const doc_type = kernel().docType();
- return doc_type != Kernel::LATEX &&
- doc_type != Kernel::LITERATE;
+ KernelDocType const doc_type = docType();
+ return doc_type != LATEX && doc_type != LITERATE;
}
bool GuiRef::typeAllowed()
{
- Kernel::DocType const doc_type = kernel().docType();
- return doc_type != Kernel::DOCBOOK;
+ return docType() != DOCBOOK;
}
void GuiRef::setGoBack()
{
- dialog_->gotoPB->setText(qt_("&Go Back"));
- dialog_->gotoPB->setToolTip("");
- dialog_->gotoPB->setToolTip(qt_("Jump back"));
+ gotoPB->setText(qt_("&Go Back"));
+ gotoPB->setToolTip("");
+ gotoPB->setToolTip(qt_("Jump back"));
}
void GuiRef::setGotoRef()
{
- dialog_->gotoPB->setText(qt_("&Go to Label"));
- dialog_->gotoPB->setToolTip("");
- dialog_->gotoPB->setToolTip(qt_("Jump to label"));
+ gotoPB->setText(qt_("&Go to Label"));
+ gotoPB->setToolTip("");
+ gotoPB->setToolTip(qt_("Jump to label"));
}
void GuiRef::gotoRef()
{
- string ref(fromqstr(dialog_->referenceED->text()));
+ string ref = fromqstr(referenceED->text());
if (at_ref_) {
// go back
setGotoRef();
- controller().gotoBookmark();
+ gotoBookmark();
} else {
// go to the ref
setGoBack();
- controller().gotoRef(ref);
+ gotoRef(ref);
}
at_ref_ = !at_ref_;
}
{
// Prevent these widgets from emitting any signals whilst
// we modify their state.
- dialog_->refsLW->blockSignals(true);
- dialog_->referenceED->blockSignals(true);
- dialog_->refsLW->setUpdatesEnabled(false);
+ refsLW->blockSignals(true);
+ referenceED->blockSignals(true);
+ refsLW->setUpdatesEnabled(false);
- dialog_->refsLW->clear();
+ refsLW->clear();
// need this because Qt will send a highlight() here for
// the first item inserted
- QString const oldSelection(dialog_->referenceED->text());
+ QString const oldSelection(referenceED->text());
- for (std::vector<docstring>::const_iterator iter = refs_.begin();
+ for (vector<docstring>::const_iterator iter = refs_.begin();
iter != refs_.end(); ++iter) {
- dialog_->refsLW->addItem(toqstr(*iter));
+ refsLW->addItem(toqstr(*iter));
}
if (sort_)
- dialog_->refsLW->sortItems();
+ refsLW->sortItems();
- dialog_->referenceED->setText(oldSelection);
+ referenceED->setText(oldSelection);
// restore the last selection or, for new insets, highlight
// the previous selection
if (!oldSelection.isEmpty() || !last_reference_.isEmpty()) {
bool const newInset = oldSelection.isEmpty();
QString textToFind = newInset ? last_reference_ : oldSelection;
- bool foundItem = false;
- for (int i = 0; !foundItem && i < dialog_->refsLW->count(); ++i) {
- QListWidgetItem * item = dialog_->refsLW->item(i);
+ last_reference_.clear();
+ for (int i = 0; i != refsLW->count(); ++i) {
+ QListWidgetItem * item = refsLW->item(i);
if (textToFind == item->text()) {
- dialog_->refsLW->setCurrentItem(item);
- dialog_->refsLW->setItemSelected(item, !newInset);
+ refsLW->setCurrentItem(item);
+ refsLW->setItemSelected(item, !newInset);
//Make sure selected item is visible
- dialog_->refsLW->scrollToItem(item);
- foundItem = true;
+ refsLW->scrollToItem(item);
+ last_reference_ = textToFind;
+ break;
}
}
- if (foundItem)
- last_reference_ = textToFind;
- else last_reference_ = "";
}
- dialog_->refsLW->setUpdatesEnabled(true);
- dialog_->refsLW->update();
+ refsLW->setUpdatesEnabled(true);
+ refsLW->update();
// Re-activate the emission of signals by these widgets.
- dialog_->refsLW->blockSignals(false);
- dialog_->referenceED->blockSignals(false);
+ refsLW->blockSignals(false);
+ referenceED->blockSignals(false);
}
void GuiRef::updateRefs()
{
refs_.clear();
- string const name = controller().getBufferName(dialog_->bufferCO->currentIndex());
- refs_ = controller().getLabelList(name);
- dialog_->sortCB->setEnabled(!refs_.empty());
- dialog_->refsLW->setEnabled(!refs_.empty());
- dialog_->gotoPB->setEnabled(!refs_.empty());
+ string const name = theBufferList().getFileNames()[bufferCO->currentIndex()];
+ Buffer const * buf = theBufferList().getBuffer(makeAbsPath(name).absFilename());
+ buf->getLabelList(refs_);
+ sortCB->setEnabled(!refs_.empty());
+ refsLW->setEnabled(!refs_.empty());
+ gotoPB->setEnabled(!refs_.empty());
redoRefs();
}
+
bool GuiRef::isValid()
{
- return !dialog_->referenceED->text().isEmpty();
+ return !referenceED->text().isEmpty();
}
+
+void GuiRef::gotoRef(string const & ref)
+{
+ dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
+ dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
+}
+
+
+void GuiRef::gotoBookmark()
+{
+ dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
+}
+
+
+Dialog * createGuiRef(GuiView & lv) { return new GuiRef(lv); }
+
+
} // namespace frontend
} // namespace lyx