]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiIndex.cpp
Do not compute caret geometry when we are not ready to do so.
[lyx.git] / src / frontends / qt4 / GuiIndex.cpp
index 0607c3e9174020d563d0dab7dd5dc42d7ed52de9..0f25c93da72f4f3d32825e568e4d8857c8f444fd 100644 (file)
@@ -3,7 +3,9 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author John Levon
+ * \author Angus Leeming
+ * \author Martin Vermeer
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "GuiIndex.h"
 
-#include "ControlCommand.h"
-
-#include "debug.h"
 #include "qt_helpers.h"
 
-#include <QLabel>
-#include <QPushButton>
-#include <QLineEdit>
-#include <QCloseEvent>
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "FuncRequest.h"
+#include "IndicesList.h"
 
-using std::string;
+#include "insets/InsetIndex.h"
+
+#include <QPushButton>
 
+using namespace std;
 
 namespace lyx {
 namespace frontend {
 
-/////////////////////////////////////////////////////////////////
-//
-// Base implementation
-//
-/////////////////////////////////////////////////////////////////
-
-GuiIndexDialogBase::GuiIndexDialogBase(LyXView & lv,
-               docstring const & title, QString const & label, std::string const & name)
-       : GuiDialog(lv, name)
+GuiIndex::GuiIndex(GuiView & lv)
+       : GuiDialog(lv, "index", qt_("Index Entry Settings"))
 {
-       label_ = label;
        setupUi(this);
-       setViewTitle(title);
-       setController(new ControlCommand(*this, name, name));
 
        connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
-       connect(keywordED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-
-       setFocusProxy(keywordED);
-
-       keywordLA->setText(label_);
-
-       keywordED->setWhatsThis( qt_(
-               "The format of the entry in the index.\n"
-               "\n"
-               "An entry can be specified as a sub-entry of\n"
-               "another with \"!\":\n"
-               "\n"
-               "cars!mileage\n"
-               "\n"
-               "You can cross-refer to another entry like so:\n"
-               "\n"
-               "cars!mileage|see{economy}\n"
-               "\n"
-               "For further details refer to the local LaTeX\n"
-               "documentation.\n")
-       );
+       connect(cancelPB, SIGNAL(clicked()), this, SLOT(slotClose()));
+       connect(indicesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
 
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
        bc().setOK(okPB);
-       bc().setCancel(closePB);
-       bc().addReadOnly(keywordED);
+       bc().setCancel(cancelPB);
 }
 
 
-ControlCommand & GuiIndexDialogBase::controller() const
+void GuiIndex::change_adaptor()
 {
-       return static_cast<ControlCommand &>(Dialog::controller());
+       changed();
 }
 
 
-void GuiIndexDialogBase::change_adaptor()
+void GuiIndex::updateContents()
 {
-       changed();
-}
+       typedef IndicesList::const_iterator const_iterator;
 
+       IndicesList const & indiceslist = buffer().params().indiceslist();
+       docstring const cur_index = params_.index;
 
-void GuiIndexDialogBase::reject()
-{
-       slotClose();
-}
+       indicesCO->clear();
 
+       const_iterator const begin = indiceslist.begin();
+       const_iterator const end = indiceslist.end();
+       for (const_iterator it = begin; it != end; ++it)
+               indicesCO->addItem(toqstr(it->index()),
+                       QVariant(toqstr(it->shortcut())));
 
-void GuiIndexDialogBase::closeEvent(QCloseEvent * e)
-{
-       slotWMHide();
-       e->accept();
+       int const pos = indicesCO->findData(toqstr(cur_index));
+       indicesCO->setCurrentIndex(pos);
 }
 
 
-void GuiIndexDialogBase::update_contents()
+void GuiIndex::applyView()
 {
-       docstring const contents = controller().params()["name"];
-       keywordED->setText(toqstr(contents));
-       bc().setValid(!contents.empty());
+       QString const index = indicesCO->itemData(
+               indicesCO->currentIndex()).toString();
+       params_.index = qstring_to_ucs4(index);
 }
 
 
-void GuiIndexDialogBase::applyView()
+bool GuiIndex::initialiseParams(string const & data)
 {
-       controller().params()["name"] = qstring_to_ucs4(keywordED->text());
+       InsetIndex::string2params(data, params_);
+       return true;
 }
 
 
-bool GuiIndexDialogBase::isValid()
+void GuiIndex::clearParams()
 {
-       return !keywordED->text().isEmpty();
+       params_ = InsetIndexParams();
 }
 
 
-/////////////////////////////////////////////////////////////////
-//
-// Index Dialog
-//
-/////////////////////////////////////////////////////////////////
-
-
-GuiIndexDialog::GuiIndexDialog(LyXView & lv)
-       : GuiIndexDialogBase(lv, _("Index Entry"), qt_("&Keyword:"), "index") 
+void GuiIndex::dispatchParams()
 {
-       keywordED->setWhatsThis( qt_(
-               "The format of the entry in the index.\n"
-               "\n"
-               "An entry can be specified as a sub-entry of\n"
-               "another with \"!\":\n"
-               "\n"
-               "cars!mileage\n"
-               "\n"
-               "You can cross-refer to another entry like so:\n"
-               "\n"
-               "cars!mileage|see{economy}\n"
-               "\n"
-               "For further details refer to the local LaTeX\n"
-               "documentation.\n")
-       );
+       dispatch(FuncRequest(getLfun(), InsetIndex::params2string(params_)));
 }
 
 
-/////////////////////////////////////////////////////////////////
-//
-// Label Dialog
-//
-/////////////////////////////////////////////////////////////////
-
-GuiLabelDialog::GuiLabelDialog(LyXView & lv)
-       : GuiIndexDialogBase(lv, _("Label"), qt_("&Label:"), "label")
-{}
+Dialog * createGuiIndex(GuiView & lv) { return new GuiIndex(lv); }
 
 
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiIndex_moc.cpp"
+#include "moc_GuiIndex.cpp"