I thought fixing bug 5909 would be easy:
I modify InsertprintNomencl so that a when inserting the nomenclature list or left-clicking on it
opens a dialog where the nomenclature label width is specified.
So far the theory, but I failed to do so and don't know what I do wrong. Attached is a rough patch
without any LaTeX output nor correct command params handling, just to test the new dialog. But when
I click on a nomenclature list inset, still nothing happens and when inserting the list, LyX crashes
immediately.
I'm really stuck and must admit that I don't understand InsetCommand and need
help.
(For testing I quickly implemented the whole thing as InsetCollapsable with success. I thought I can
transfer the design from InsetCollabsable to InsetCommand but this doesn't work and there is no
documentation of InsetCommand in the code.)
thanks and regards
Uwe
Index: src/factory.cpp
===================================================================
--- src/factory.cpp (revision 29727)
+++ src/factory.cpp (working copy)
@@ -209,8 +209,11 @@
return new InsetPrintIndex(icp);
}
- case LFUN_NOMENCL_PRINT:
- return new InsetPrintNomencl(InsetCommandParams(NOMENCL_PRINT_CODE));
+ case LFUN_NOMENCL_PRINT: {
+ InsetCommandParams icp(NOMENCL_PRINT_CODE);
+ icp["widthvalue"] = cmd.argument();
+ return new InsetPrintNomencl(icp);
+ }
case LFUN_TOC_INSERT:
return new InsetTOC(InsetCommandParams(TOC_CODE));
Index: src/frontends/qt4/GuiPrintNomencl.cpp
===================================================================
--- src/frontends/qt4/GuiPrintNomencl.cpp (revision 0)
+++ src/frontends/qt4/GuiPrintNomencl.cpp (revision 0)
@@ -0,0 +1,125 @@
+/**
+ * \file GuiPrintNomencl.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Uwe Stöhr
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiPrintNomencl.h"
+
+#include "LengthCombo.h"
+#include "qt_helpers.h"
+#include "Validator.h"
+
+#include "Spacing.h"
+#include "FuncRequest.h"
+
+#include "insets/InsetNomencl.h"
+
+#include "support/gettext.h"
+#include "support/lstrings.h"
+
+#include <QLineEdit>
+#include <QPushButton>
+#include <QValidator>
+
+using namespace std;
+
+namespace lyx {
+namespace frontend {
+
+GuiPrintNomencl::GuiPrintNomencl(GuiView & lv)
+ : GuiDialog(lv, "printnomencl", qt_("Nomenclature label width")),
+ params_(insetCode("printnomencl"))
+{
+ setupUi(this);
+
+ connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
+ connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
+ connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
+
+ connect(valueLE, SIGNAL(textChanged(QString)),
+ this, SLOT(change_adaptor()));
+ connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(change_adaptor()));
+
+ valueLE->setValidator(unsignedLengthValidator(valueLE));
+
+ // Manage the ok, apply, restore and cancel/close buttons
+ bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
+ bc().setOK(okPB);
+ bc().setApply(applyPB);
+ bc().setCancel(closePB);
+
+ // disable for read-only documents
+ bc().addReadOnly(valueLE);
+ bc().addReadOnly(unitCO);
+
+ // initialize the length validator
+ bc().addCheckedLineEdit(valueLE, valueL);
+
+ // remove the %-items from the unit choice
+ unitCO->noPercents();
+}
+
+
+void GuiPrintNomencl::change_adaptor()
+{
+ changed();
+}
+
+
+void GuiPrintNomencl::reject()
+{
+ slotClose();
+}
+
+
+void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & /*icp*/)
+{
+ valueLE->setText(toqstr(params_["widthvalue"]));
+ //unitCO->setText(toqstr(params_["widthunit"]));
+
+ bc().setValid(isValid());
+}
+
+
+void GuiPrintNomencl::applyView()
+{
+ params_["widthvalue"] = qstring_to_ucs4(valueLE->text());
+ params_["widthunit"] = qstring_to_ucs4(unitCO->currentText());
+}
+
+
+bool GuiPrintNomencl::initialiseParams(std::string const & data)
+{
+ InsetCommand::string2params("printnomencl", data, params_);
+ paramsToDialog(params_);
+ return true;
+}
+
+
+void GuiPrintNomencl::dispatchParams()
+{
+ std::string const lfun = InsetCommand::params2string("printnomencl", params_);
+ dispatch(FuncRequest(getLfun(), lfun));
+}
+
+
+
+Dialog * createGuiPrintNomencl(GuiView & lv)
+{
+ return new GuiPrintNomencl(lv);
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+
+#include "moc_GuiPrintNomencl.cpp"
Property changes on: src\frontends\qt4\GuiPrintNomencl.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Index: src/frontends/qt4/GuiPrintNomencl.h
===================================================================
--- src/frontends/qt4/GuiPrintNomencl.h (revision 0)
+++ src/frontends/qt4/GuiPrintNomencl.h (revision 0)
@@ -0,0 +1,56 @@
+// -*- C++ -*-
+/**
+ * \file GuiPrintNomencl.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Uwe Stöhr
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef GUIPRINTNOMENCL_H
+#define GUIPRINTNOMENCL_H
+
+#include "GuiDialog.h"
+#include "ui_PrintNomenclUi.h"
+
+#include "insets/InsetCommandParams.h"
+
+
+namespace lyx {
+namespace frontend {
+
+class GuiPrintNomencl : public GuiDialog, public Ui::PrintNomenclUi
+{
+ Q_OBJECT
+
+public:
+ GuiPrintNomencl(GuiView & lv);
+
+private Q_SLOTS:
+ void change_adaptor();
+ void reject();
+
+private:
+ ///
+ void applyView();
+ ///
+ bool initialiseParams(std::string const & data);
+ ///
+ void paramsToDialog(InsetCommandParams const & icp);
+ ///
+ void clearParams() { params_.clear(); }
+ ///
+ void dispatchParams();
+ ///
+ bool isBufferDependent() const { return true; }
+
+ ///
+ InsetCommandParams params_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // GUIPRINTNOMENCL_H
Property changes on: src\frontends\qt4\GuiPrintNomencl.h
___________________________________________________________________
Added: svn:eol-style
+ native
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp (revision 29727)
+++ src/frontends/qt4/GuiView.cpp (working copy)
@@ -2420,9 +2420,9 @@
"findreplaceadv", "float", "graphics", "href", "include", "index",
"index_print", "info", "listings", "label", "log", "mathdelimiter",
"mathmatrix", "mathspace", "nomenclature", "note", "paragraph", "phantom",
-"prefs", "print", "ref", "sendto", "space", "spellchecker", "symbols",
-"tabular", "tabularcreate", "thesaurus", "texinfo", "toc", "view-source",
-"vspace", "wrap" };
+"prefs", "print", "printnomencl", "ref", "sendto", "space", "spellchecker",
+"symbols", "tabular", "tabularcreate", "thesaurus", "texinfo", "toc",
+"view-source", "vspace", "wrap" };
char const * const * const end_dialognames =
dialognames + (sizeof(dialognames) / sizeof(char *));
@@ -2611,6 +2611,7 @@
Dialog * createGuiPreferences(GuiView & lv);
Dialog * createGuiPrint(GuiView & lv);
Dialog * createGuiPrintindex(GuiView & lv);
+Dialog * createGuiPrintNomencl(GuiView & lv);
Dialog * createGuiRef(GuiView & lv);
Dialog * createGuiSearch(GuiView & lv);
Dialog * createGuiSearchAdv(GuiView & lv);
@@ -2696,6 +2697,8 @@
return createGuiPreferences(*this);
if (name == "print")
return createGuiPrint(*this);
+ if (name == "printnomencl")
+ return createGuiPrintNomencl(*this);
if (name == "ref")
return createGuiRef(*this);
if (name == "sendto")
Index: src/frontends/qt4/ui/PrintNomenclUi.ui
===================================================================
--- src/frontends/qt4/ui/PrintNomenclUi.ui (revision 0)
+++ src/frontends/qt4/ui/PrintNomenclUi.ui (revision 0)
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PrintNomenclUi</class>
+ <widget class="QDialog" name="PrintNomenclUi">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>259</width>
+ <height>75</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string/>
+ </property>
+ <property name="sizeGripEnabled">
+ <bool>true</bool>
+ </property>
+ <layout class="QGridLayout">
+ <item row="1" column="0" colspan="3">
+ <layout class="QHBoxLayout">
+ <item>
+ <widget class="QPushButton" name="okPB">
+ <property name="text">
+ <string>&OK</string>
+ </property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
+ <property name="default">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="applyPB">
+ <property name="text">
+ <string>&Apply</string>
+ </property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closePB">
+ <property name="text">
+ <string>&Close</string>
+ </property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="0" column="2">
+ <widget class="LengthCombo" name="unitCO"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="valueLE">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="toolTip">
+ <string>Custom value. Needs spacing type "Custom".</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="valueL">
+ <property name="text">
+ <string>&Value:</string>
+ </property>
+ <property name="buddy">
+ <cstring>valueLE</cstring>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>LengthCombo</class>
+ <extends>QComboBox</extends>
+ <header>LengthCombo.h</header>
+ </customwidget>
+ </customwidgets>
+ <tabstops>
+ <tabstop>valueLE</tabstop>
+ <tabstop>unitCO</tabstop>
+ <tabstop>okPB</tabstop>
+ <tabstop>applyPB</tabstop>
+ <tabstop>closePB</tabstop>
+ </tabstops>
+ <includes>
+ <include location="local">qt_i18n.h</include>
+ </includes>
+ <resources/>
+ <connections/>
+</ui>
Property changes on: src\frontends\qt4\ui\PrintNomenclUi.ui
___________________________________________________________________
Added: svn:eol-style
+ native
Index: src/insets/InsetNomencl.cpp
===================================================================
--- src/insets/InsetNomencl.cpp (revision 29727)
+++ src/insets/InsetNomencl.cpp (working copy)
@@ -116,7 +116,7 @@
/////////////////////////////////////////////////////////////////////
InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
- : InsetCommand(p, string())
+ : InsetCommand(p, "printnomencl")
{}
@@ -124,7 +124,8 @@
{
static ParamInfo param_info_;
if (param_info_.empty()) {
- param_info_.add("labelwidth", ParamInfo::LATEX_REQUIRED);
+ param_info_.add("widthvalue", ParamInfo::LATEX_REQUIRED);
+ param_info_.add("widthunit", ParamInfo::LATEX_REQUIRED);
}
return param_info_;
}
Index: src/LyXAction.cpp
===================================================================
--- src/LyXAction.cpp (revision 29728)
+++ src/LyXAction.cpp (working copy)
@@ -2528,9 +2528,9 @@
* \li Params: <NAME>: aboutlyx|bibitem|bibtex|box|branch|changes|character|citation|\n
document|errorlist|ert|external|file|findreplace|findreplaceadv|float|graphics|\n
href|include|index|index_print|info|label|listings|log|mathdelimiter|\n
- mathmatrix|mathspace|nomenclature|note|paragraph|phantom|prefs|print|ref|\n
- sendto|space|spellchecker|symbols|tabular|tabularcreate|thesaurus|texinfo|\n
- toc|view-source|vspace|wrap|<SPECIAL> \n
+ mathmatrix|mathspace|nomenclature|note|paragraph|phantom|prefs|print|\n
+ printnomencl|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n
+ thesaurus|texinfo|toc|view-source|vspace|wrap|<SPECIAL> \n
<SPECIAL>: latexlog|vclog \n
<DATA>: data, usually settings for the given dialog. Use debug mode for the
details.
Index: src/LyXFunc.cpp
===================================================================
--- src/LyXFunc.cpp (revision 29727)
+++ src/LyXFunc.cpp (working copy)
@@ -1129,6 +1129,7 @@
case INDEX_CODE:
case LABEL_CODE:
case NOMENCL_CODE:
+ case NOMENCL_PRINT_CODE:
case REF_CODE:
case TOC_CODE:
case HYPERLINK_CODE: {
Index: src/Text3.cpp
===================================================================
--- src/Text3.cpp (revision 29727)
+++ src/Text3.cpp (working copy)
@@ -1619,6 +1619,17 @@
break;
}
+ case LFUN_NOMENCL_PRINT: {
+ InsetCommandParams p(NOMENCL_PRINT_CODE);
+ if (cmd.argument().empty())
+ p["widthvalue"] = from_ascii("0");
+ else
+ p["widthvalue"] = cmd.argument();
+ string const data = InsetCommand::params2string("printnomencl", p);
+ bv->showDialog("printnomencl", data);
+ break;
+ }
+
case LFUN_INDEX_PRINT: {
InsetCommandParams p(INDEX_PRINT_CODE);
if (cmd.argument().empty())
@@ -1630,8 +1641,7 @@
dispatch(cur, fr);
break;
}
-
- case LFUN_NOMENCL_PRINT:
+
case LFUN_TOC_INSERT:
case LFUN_LINE_INSERT:
case LFUN_NEWPAGE_INSERT:
@@ -2127,6 +2137,8 @@
code = INDEX_PRINT_CODE;
else if (cmd.argument() == "nomenclature")
code = NOMENCL_CODE;
+ else if (cmd.argument() == "printnomencl")
+ code = NOMENCL_PRINT_CODE;
else if (cmd.argument() == "label")
code = LABEL_CODE;
else if (cmd.argument() == "note")