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/FileName.h"
21 #include "qt_helpers.h"
24 #include <QListWidget>
25 #include <QPushButton>
26 #include <QStringList>
29 using namespace lyx::support;
34 static QString texFileFromList(QString const & file, QString const & type)
36 QString lstfile = type + "Files.lst";
37 FileName const abslstfile = libFileSearch(QString(), lstfile);
38 if (abslstfile.empty())
40 QString cs = toqstr(abslstfile.fileContents("UTF-8"));
42 QStringList const result = cs.split("\n").filter(file);
49 GuiTexInfo::GuiTexInfo(GuiView & lv)
50 : GuiDialog(lv, "texinfo", qt_("TeX Information"))
54 warningPosted_ = false;
55 activeStyle_ = ClsType;
57 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
59 connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
60 connect(whatStyleCO, SIGNAL(activated(QString)),
61 this, SLOT(enableViewPB()));
62 connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(updateView()));
63 connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(updateView()));
64 connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB()));
65 connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked()));
66 connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)),
67 this, SLOT(enableViewPB()));
68 connect(fileListLW, SIGNAL(itemSelectionChanged()),
69 this, SLOT(enableViewPB()));
71 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
72 bc().setCancel(closePB);
76 void GuiTexInfo::change_adaptor()
82 void GuiTexInfo::rescanClicked()
84 // build new *Files.lst
91 void GuiTexInfo::viewClicked()
93 // takes advantage of enum order
94 static QString const ext[] = { "cls", "sty", "bst", "bib" };
95 int const fitem = fileListLW->currentRow();
96 QStringList const & data = texdata_[activeStyle_];
97 QString file = data[fitem];
98 if (!pathCB->isChecked())
99 file = texFileFromList(data[fitem], ext[activeStyle_]);
104 void GuiTexInfo::updateView()
106 // takes advantage of enum order
107 updateStyles(static_cast<TexFileType>(whatStyleCO->currentIndex()));
112 void GuiTexInfo::enableViewPB()
114 viewPB->setEnabled(fileListLW->currentRow() > -1);
118 void GuiTexInfo::updateStyles(TexFileType type)
120 static QString const filenames[] = {
121 "clsFiles.lst", "styFiles.lst", "bstFiles.lst", "bibFiles.lst"
124 QString const filename = filenames[type];
126 QStringList data = texFileList(filename);
128 // build filelists of all availabe bst/cls/sty-files.
129 // Done through kpsewhich and an external script,
130 // saved in *Files.lst
132 data = texFileList(filename);
135 if (!pathCB->isChecked()) {
136 for (int i = 0; i != data.size(); ++i)
137 data[i] = onlyFileName(data[i]);
139 // sort on filename only (no path)
143 for(QString const & item : data)
144 fileListLW->addItem(item);
147 texdata_[type] = data;
151 void GuiTexInfo::updateStyles()
153 updateStyles(activeStyle_);
157 void GuiTexInfo::viewFile(QString const & filename) const
159 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + fromqstr(filename)));
163 /// get a class with full path from the list
165 string GuiTexInfo::classOptions(string const & classname) const
167 FileName const filename(texFileFromList(classname, "cls"));
168 if (filename.empty())
171 ifstream is(filename.toFilesystemEncoding().c_str());
175 if (contains(s, "DeclareOption")) {
176 s = s.substr(s.find("DeclareOption"));
177 s = split(s, '{'); // cut front
178 s = token(s, '}', 0); // cut end
179 optionList += (s + '\n');
187 Dialog * createGuiTexInfo(GuiView & lv) { return new GuiTexInfo(lv); }
190 } // namespace frontend
194 #include "moc_GuiTexinfo.cpp"