]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiNomencl.cpp
Fix also nomenclature dialog which was refered in #3852
[lyx.git] / src / frontends / qt4 / GuiNomencl.cpp
1 /**
2  * \file GuiNomencl.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author O. U. Baran
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiNomencl.h"
15
16 #include "qt_helpers.h"
17 #include "FuncRequest.h"
18
19 #include "insets/InsetCommand.h"
20
21 #include "support/debug.h"
22
23 #include <QLabel>
24 #include <QLineEdit>
25
26 using namespace std;
27
28 namespace lyx {
29 namespace frontend {
30
31 GuiNomenclature::GuiNomenclature(GuiView & lv)
32         : GuiDialog(lv, "nomenclature", qt_("Nomenclature")),
33           params_(insetCode("nomenclature"))
34 {
35         setupUi(this);
36
37         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
38         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
39         connect(symbolED, SIGNAL(textChanged(QString)),
40                 this, SLOT(change_adaptor()));
41         connect(descriptionTE, SIGNAL(textChanged()),
42                 this, SLOT(change_adaptor()));
43
44         setFocusProxy(descriptionTE);
45
46         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
47         bc().setOK(okPB);
48         bc().setCancel(closePB);
49         bc().addReadOnly(symbolED);
50         bc().addReadOnly(descriptionTE);
51         bc().addReadOnly(prefixED);
52 }
53
54
55 void GuiNomenclature::change_adaptor()
56 {
57         changed();
58 }
59
60
61 void GuiNomenclature::reject()
62 {
63         slotClose();
64 }
65
66
67 void GuiNomenclature::paramsToDialog(InsetCommandParams const & /*icp*/)
68 {
69         prefixED->setText(toqstr(params_["prefix"]));
70         symbolED->setText(toqstr(params_["symbol"]));
71         QString description = toqstr(params_["description"]);
72         description.replace("\\\\","\n");
73         descriptionTE->setPlainText(description);
74         descriptionTE->setFocus();
75
76         bc().setValid(isValid());
77 }
78
79
80 void GuiNomenclature::applyView()
81 {
82         params_["prefix"] = qstring_to_ucs4(prefixED->text());
83         params_["symbol"] = qstring_to_ucs4(symbolED->text());
84         QString description = descriptionTE->toPlainText();
85         description.replace('\n',"\\\\");
86         params_["description"] = qstring_to_ucs4(description);
87 }
88
89
90 bool GuiNomenclature::isValid()
91 {
92         QString const description = descriptionTE->toPlainText();
93         return !symbolED->text().isEmpty() && !description.isEmpty();
94 }
95
96
97 bool GuiNomenclature::initialiseParams(std::string const & data)
98 {
99         InsetCommand::string2params("nomenclature", data, params_);
100         paramsToDialog(params_);
101         return true;
102 }
103
104
105 void GuiNomenclature::dispatchParams()
106 {
107         std::string const lfun = InsetCommand::params2string("nomenclature", params_);
108         dispatch(FuncRequest(getLfun(), lfun));
109 }
110
111
112
113 Dialog * createGuiNomenclature(GuiView & lv)
114 {
115         return new GuiNomenclature(lv);
116 }
117
118
119 } // namespace frontend
120 } // namespace lyx
121
122 #include "moc_GuiNomencl.cpp"