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", "bbx", "cbx" };
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",
122 "bbxFiles.lst", "cbxFiles.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 for(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"