]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrintindex.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiPrintindex.cpp
1 /**
2  * \file GuiPrintindex.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Martin Vermeer
8  * \author Jürgen Spitzmüller
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiPrintindex.h"
16
17 #include "qt_helpers.h"
18
19 #include "Buffer.h"
20 #include "BufferParams.h"
21 #include "FuncRequest.h"
22 #include "IndicesList.h"
23
24 #include "support/lstrings.h"
25
26 #include "insets/InsetCommand.h"
27
28 #include <QPushButton>
29
30 using namespace std;
31 using namespace lyx::support;
32
33 namespace lyx {
34 namespace frontend {
35
36 GuiPrintindex::GuiPrintindex(GuiView & lv)
37         : GuiDialog(lv, "index_print", qt_("Index Settings")),
38           params_(insetCode("index_print"))
39 {
40         setupUi(this);
41
42         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
43         connect(cancelPB, SIGNAL(clicked()), this, SLOT(slotClose()));
44         connect(indicesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
45         connect(subindexCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
46
47         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
48         bc().setOK(okPB);
49         bc().setCancel(cancelPB);
50 }
51
52
53 void GuiPrintindex::change_adaptor()
54 {
55         changed();
56 }
57
58
59 void GuiPrintindex::updateContents()
60 {
61         typedef IndicesList::const_iterator const_iterator;
62
63         IndicesList const & indiceslist = buffer().params().indiceslist();
64         docstring const cur_index = suffixIs(params_.getCmdName(), '*') ?
65                 from_ascii("printall") : params_["type"];
66
67         indicesCO->clear();
68
69         indicesCO->addItem(qt_("<All indexes>"),
70                         QVariant(QString("printall")));
71
72         const_iterator const begin = indiceslist.begin();
73         const_iterator const end = indiceslist.end();
74         for (const_iterator it = begin; it != end; ++it)
75                 indicesCO->addItem(toqstr(it->index()),
76                         QVariant(toqstr(it->shortcut())));
77
78         int const pos = indicesCO->findData(toqstr(cur_index));
79         indicesCO->setCurrentIndex(pos);
80         subindexCB->setChecked(params_.getCmdName() == "printsubindex");
81 }
82
83
84 void GuiPrintindex::applyView()
85 {
86         QString const index = indicesCO->itemData(
87                 indicesCO->currentIndex()).toString();
88         string cmd = "printindex";
89         if (subindexCB->isChecked())
90                 cmd = "printsubindex";
91         if (index == QString("printall"))
92                 cmd += '*';
93         params_.setCmdName(cmd);
94         if (index == QString("printall"))
95                 params_["type"] = docstring();
96         else
97                 params_["type"] = qstring_to_ucs4(index);
98 }
99
100
101 void GuiPrintindex::paramsToDialog(InsetCommandParams const & /*icp*/)
102 {
103         int const pos = suffixIs(params_.getCmdName(), '*') ?
104                 indicesCO->findData(QString("printall")) :
105                 indicesCO->findData(toqstr(params_["type"]));
106         subindexCB->setChecked(params_.getCmdName() == "printsubindex");
107         indicesCO->setCurrentIndex(pos);
108         bc().setValid(isValid());
109 }
110
111
112 bool GuiPrintindex::initialiseParams(string const & data)
113 {
114         // The name passed with LFUN_INSET_APPLY is also the name
115         // used to identify the mailer.
116         InsetCommand::string2params("index_print", data, params_);
117         paramsToDialog(params_);
118         return true;
119 }
120
121
122 void GuiPrintindex::dispatchParams()
123 {
124         std::string const lfun = InsetCommand::params2string("index_print", params_);
125         dispatch(FuncRequest(getLfun(), lfun));
126 }
127
128
129 Dialog * createGuiPrintindex(GuiView & lv) { return new GuiPrintindex(lv); }
130
131
132 } // namespace frontend
133 } // namespace lyx
134
135 #include "moc_GuiPrintindex.cpp"