]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiTexinfo.cpp
GuiWrap.cpp: disconnect the widgets that are by default disabled from readonly
[lyx.git] / src / frontends / qt4 / GuiTexinfo.cpp
1 /**
2  * \file GuiTexinfo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiTexinfo.h"
14
15 #include "ControlTexinfo.h"
16 #include "qt_helpers.h"
17
18 #include "support/filetools.h"
19
20 #include <QCloseEvent>
21 #include <QCheckBox>
22 #include <QListWidget>
23 #include <QPushButton>
24
25 #include <algorithm>
26
27 using std::string;
28 using std::vector;
29
30
31 namespace lyx {
32 namespace frontend {
33
34 GuiTexinfoDialog::GuiTexinfoDialog(LyXView & lv)
35         : GuiDialog(lv, "texinfo")
36 {
37         setupUi(this);
38         setViewTitle(_("TeX Information"));
39         setController(new ControlTexinfo(*this));
40
41         warningPosted = false;
42         activeStyle = ControlTexinfo::cls;
43
44         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
45
46         connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
47         connect(whatStyleCO, SIGNAL(activated(const QString &)),
48                 this, SLOT(enableViewPB()));
49         connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(updateView()));
50         connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(updateView()));
51         connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB()));
52         connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked()));
53         connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)),
54                 this, SLOT(enableViewPB()));
55         connect(fileListLW, SIGNAL(itemSelectionChanged()),
56                 this, SLOT(enableViewPB()));
57
58         updateStyles(ControlTexinfo::cls);
59
60         bc().setPolicy(ButtonPolicy::OkCancelPolicy);
61         bc().setCancel(closePB);
62 }
63
64
65 ControlTexinfo & GuiTexinfoDialog::controller()
66 {
67         return static_cast<ControlTexinfo &>(GuiDialog::controller());
68 }
69
70
71 void GuiTexinfoDialog::change_adaptor()
72 {
73         changed();
74 }
75
76
77 void GuiTexinfoDialog::closeEvent(QCloseEvent * e)
78 {
79         slotClose();
80         e->accept();
81 }
82
83
84 void GuiTexinfoDialog::rescanClicked()
85 {
86         // build new *Files.lst
87         rescanTexStyles();
88         updateStyles();
89         enableViewPB();
90 }
91
92
93 void GuiTexinfoDialog::viewClicked()
94 {
95         size_t const fitem = fileListLW->currentRow();
96         vector<string> const & data = texdata_[activeStyle];
97         string file = data[fitem];
98         if (!pathCB->isChecked())
99                 file = getTexFileFromList(data[fitem],
100                         controller().getFileType(activeStyle));
101         controller().viewFile(file);
102 }
103
104
105 void GuiTexinfoDialog::updateView()
106 {
107         switch (whatStyleCO->currentIndex()) {
108                 case 0:
109                         updateStyles(ControlTexinfo::cls);
110                         break;
111                 case 1:
112                         updateStyles(ControlTexinfo::sty);
113                         break;
114                 case 2:
115                         updateStyles(ControlTexinfo::bst);
116                         break;
117                 default:
118                         break;
119         }
120
121         enableViewPB();
122 }
123
124
125 void GuiTexinfoDialog::enableViewPB()
126 {
127         viewPB->setEnabled(fileListLW->currentRow() > -1);
128 }
129
130
131 void GuiTexinfoDialog::updateStyles(ControlTexinfo::texFileSuffix type)
132 {
133         ContentsType & data = texdata_[type];
134
135         string filename;
136         switch (type) {
137         case ControlTexinfo::bst:
138                 filename = "bstFiles.lst";
139                 break;
140         case ControlTexinfo::cls:
141                 filename = "clsFiles.lst";
142                 break;
143         case ControlTexinfo::sty:
144                 filename = "styFiles.lst";
145                 break;
146         }
147         getTexFileList(filename, data);
148         if (data.empty()) {
149                 // build filelists of all availabe bst/cls/sty-files.
150                 // Done through kpsewhich and an external script,
151                 // saved in *Files.lst
152                 rescanTexStyles();
153                 getTexFileList(filename, data);
154         }
155         bool const withFullPath = pathCB->isChecked();
156         if (withFullPath)
157                 return;
158         vector<string>::iterator it1  = data.begin();
159         vector<string>::iterator end1 = data.end();
160         for (; it1 != end1; ++it1)
161                 *it1 = support::onlyFilename(*it1);
162
163         // sort on filename only (no path)
164         std::sort(data.begin(), data.end());
165
166         fileListLW->clear();
167         ContentsType::const_iterator it  = data.begin();
168         ContentsType::const_iterator end = data.end();
169         for (; it != end; ++it)
170                 fileListLW->addItem(toqstr(*it));
171
172         activeStyle = type;
173 }
174
175
176 void GuiTexinfoDialog::updateStyles()
177 {
178         updateStyles(activeStyle);
179 }
180
181 } // namespace frontend
182 } // namespace lyx
183
184
185 #include "GuiTexinfo_moc.cpp"