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(buttonBox, SIGNAL(clicked(QAbstractButton *)),
58 this, SLOT(slotButtonBox(QAbstractButton *)));
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(buttonBox->button(QDialogButtonBox::Cancel));
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", "bbx", "cbx" };
96 int const fitem = fileListLW->currentRow();
97 QStringList const & sdata = texdata_[activeStyle_];
98 QString file = sdata[fitem];
99 if (!pathCB->isChecked())
100 file = texFileFromList(sdata[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",
123 "bbxFiles.lst", "cbxFiles.lst"
126 QString const filename = filenames[type];
128 QStringList flist = texFileList(filename);
130 // build filelists of all available bst/cls/sty-files.
131 // Done through kpsewhich and an external script,
132 // saved in *Files.lst
134 flist = texFileList(filename);
137 if (!pathCB->isChecked()) {
138 for (int i = 0; i != flist.size(); ++i)
139 flist[i] = onlyFileName(flist[i]);
141 // sort on filename only (no path)
145 for(QString const & item : flist)
146 fileListLW->addItem(item);
149 texdata_[type] = flist;
153 void GuiTexInfo::updateStyles()
155 updateStyles(activeStyle_);
159 void GuiTexInfo::viewFile(QString const & filename) const
161 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + fromqstr(filename)));
165 /// get a class with full path from the list
167 string GuiTexInfo::classOptions(string const & classname) const
169 FileName const filename(texFileFromList(classname, "cls"));
170 if (filename.empty())
173 ifstream is(filename.toFilesystemEncoding().c_str());
177 if (contains(s, "DeclareOption")) {
178 s = s.substr(s.find("DeclareOption"));
179 s = split(s, '{'); // cut front
180 s = token(s, '}', 0); // cut end
181 optionList += (s + '\n');
189 Dialog * createGuiTexInfo(GuiView & lv) { return new GuiTexInfo(lv); }
192 } // namespace frontend
196 #include "moc_GuiTexinfo.cpp"