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/debug.h"
19 #include "support/filetools.h"
20 #include "support/foreach.h"
21 #include "support/FileName.h"
22 #include "support/lstrings.h"
24 #include "qt_helpers.h"
27 #include <QListWidget>
28 #include <QPushButton>
29 #include <QStringList>
35 using namespace lyx::support;
40 static QString texFileFromList(QString const & file, QString const & type)
42 QString lstfile = type + "Files.lst";
43 FileName const abslstfile = libFileSearch(QString(), lstfile);
44 if (abslstfile.empty())
46 QString cs = toqstr(abslstfile.fileContents("UTF-8"));
48 QStringList const result = cs.split("\n").filter(file);
55 GuiTexInfo::GuiTexInfo(GuiView & lv)
56 : GuiDialog(lv, "texinfo", qt_("TeX Information"))
60 warningPosted_ = false;
61 activeStyle_ = ClsType;
63 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
65 connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
66 connect(whatStyleCO, SIGNAL(activated(QString)),
67 this, SLOT(enableViewPB()));
68 connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(updateView()));
69 connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(updateView()));
70 connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB()));
71 connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked()));
72 connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)),
73 this, SLOT(enableViewPB()));
74 connect(fileListLW, SIGNAL(itemSelectionChanged()),
75 this, SLOT(enableViewPB()));
77 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
78 bc().setCancel(closePB);
82 void GuiTexInfo::change_adaptor()
88 void GuiTexInfo::rescanClicked()
90 // build new *Files.lst
97 void GuiTexInfo::viewClicked()
99 // takes advantage of enum order
100 static QString const ext[] = { "cls", "sty", "bst" };
101 int const fitem = fileListLW->currentRow();
102 QStringList const & data = texdata_[activeStyle_];
103 QString file = data[fitem];
104 if (!pathCB->isChecked())
105 file = texFileFromList(data[fitem], ext[activeStyle_]);
110 void GuiTexInfo::updateView()
112 // takes advantage of enum order
113 updateStyles(static_cast<TexFileType>(whatStyleCO->currentIndex()));
118 void GuiTexInfo::enableViewPB()
120 viewPB->setEnabled(fileListLW->currentRow() > -1);
124 void GuiTexInfo::updateStyles(TexFileType type)
126 static QString const filenames[] = {
127 "clsFiles.lst", "styFiles.lst", "bstFiles.lst"
130 QString const filename = filenames[type];
132 QStringList data = texFileList(filename);
134 // build filelists of all availabe bst/cls/sty-files.
135 // Done through kpsewhich and an external script,
136 // saved in *Files.lst
138 data = texFileList(filename);
141 if (!pathCB->isChecked()) {
142 for (int i = 0; i != data.size(); ++i)
143 data[i] = onlyFilename(data[i]);
145 // sort on filename only (no path)
149 foreach (QString const & item, data)
150 fileListLW->addItem(item);
153 texdata_[type] = data;
157 void GuiTexInfo::updateStyles()
159 updateStyles(activeStyle_);
163 void GuiTexInfo::viewFile(QString const & filename) const
165 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + fromqstr(filename)));
169 /// get a class with full path from the list
171 string GuiTexInfo::classOptions(string const & classname) const
173 FileName const filename(texFileFromList(classname, "cls"));
174 if (filename.empty())
177 ifstream is(filename.toFilesystemEncoding().c_str());
181 if (contains(s, "DeclareOption")) {
182 s = s.substr(s.find("DeclareOption"));
183 s = split(s, '{'); // cut front
184 s = token(s, '}', 0); // cut end
185 optionList += (s + '\n');
193 Dialog * createGuiTexInfo(GuiView & lv) { return new GuiTexInfo(lv); }
196 } // namespace frontend
200 #include "GuiTexinfo_moc.cpp"