3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "GuiTexinfo.h"
16 #include "FuncRequest.h"
18 #include "support/filetools.h"
19 #include "support/foreach.h"
20 #include "support/FileName.h"
22 #include "qt_helpers.h"
25 #include <QListWidget>
26 #include <QPushButton>
27 #include <QStringList>
30 using namespace lyx::support;
35 static QString texFileFromList(QString const & file, QString const & type)
37 QString lstfile = type + "Files.lst";
38 FileName const abslstfile = libFileSearch(QString(), lstfile);
39 if (abslstfile.empty())
41 QString cs = toqstr(abslstfile.fileContents("UTF-8"));
43 QStringList const result = cs.split("\n").filter(file);
50 GuiTexInfo::GuiTexInfo(GuiView & lv)
51 : GuiDialog(lv, "texinfo", qt_("TeX Information"))
55 warningPosted_ = false;
56 activeStyle_ = ClsType;
58 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
60 connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
61 connect(whatStyleCO, SIGNAL(activated(QString)),
62 this, SLOT(enableViewPB()));
63 connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(updateView()));
64 connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(updateView()));
65 connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB()));
66 connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked()));
67 connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)),
68 this, SLOT(enableViewPB()));
69 connect(fileListLW, SIGNAL(itemSelectionChanged()),
70 this, SLOT(enableViewPB()));
72 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
73 bc().setCancel(closePB);
77 void GuiTexInfo::change_adaptor()
83 void GuiTexInfo::rescanClicked()
85 // build new *Files.lst
92 void GuiTexInfo::viewClicked()
94 // takes advantage of enum order
95 static QString const ext[] = { "cls", "sty", "bst", "bib" };
96 int const fitem = fileListLW->currentRow();
97 QStringList const & data = texdata_[activeStyle_];
98 QString file = data[fitem];
99 if (!pathCB->isChecked())
100 file = texFileFromList(data[fitem], ext[activeStyle_]);
105 void GuiTexInfo::updateView()
107 // takes advantage of enum order
108 updateStyles(static_cast<TexFileType>(whatStyleCO->currentIndex()));
113 void GuiTexInfo::enableViewPB()
115 viewPB->setEnabled(fileListLW->currentRow() > -1);
119 void GuiTexInfo::updateStyles(TexFileType type)
121 static QString const filenames[] = {
122 "clsFiles.lst", "styFiles.lst", "bstFiles.lst", "bibFiles.lst"
125 QString const filename = filenames[type];
127 QStringList data = texFileList(filename);
129 // build filelists of all availabe bst/cls/sty-files.
130 // Done through kpsewhich and an external script,
131 // saved in *Files.lst
133 data = texFileList(filename);
136 if (!pathCB->isChecked()) {
137 for (int i = 0; i != data.size(); ++i)
138 data[i] = onlyFileName(data[i]);
140 // sort on filename only (no path)
144 foreach (QString const & item, data)
145 fileListLW->addItem(item);
148 texdata_[type] = data;
152 void GuiTexInfo::updateStyles()
154 updateStyles(activeStyle_);
158 void GuiTexInfo::viewFile(QString const & filename) const
160 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + fromqstr(filename)));
164 /// get a class with full path from the list
166 string GuiTexInfo::classOptions(string const & classname) const
168 FileName const filename(texFileFromList(classname, "cls"));
169 if (filename.empty())
172 ifstream is(filename.toFilesystemEncoding().c_str());
176 if (contains(s, "DeclareOption")) {
177 s = s.substr(s.find("DeclareOption"));
178 s = split(s, '{'); // cut front
179 s = token(s, '}', 0); // cut end
180 optionList += (s + '\n');
188 Dialog * createGuiTexInfo(GuiView & lv) { return new GuiTexInfo(lv); }
191 } // namespace frontend
195 #include "moc_GuiTexinfo.cpp"