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/FileName.h"
21 #include "support/lstrings.h"
23 #include "qt_helpers.h"
26 #include <QListWidget>
27 #include <QPushButton>
33 using namespace lyx::support;
39 static string texFileFromList(string const & file, string const & type)
42 // do we need to add the suffix?
43 if (!(getExtension(file) == type))
46 lyxerr << "Searching for file " << file_ << endl;
48 string lstfile = type + "Files.lst";
50 lstfile = "clsFiles.lst";
51 else if (type == "sty")
52 lstfile = "styFiles.lst";
53 else if (type == "bst")
54 lstfile = "bstFiles.lst";
55 else if (type == "bib")
56 lstfile = "bibFiles.lst";
57 FileName const abslstfile = libFileSearch(string(), lstfile);
58 if (abslstfile.empty()) {
59 lyxerr << "File `'" << lstfile << "' not found." << endl;
63 string const allClasses = to_utf8(abslstfile.fileContents("UTF-8"));
65 string classfile = token(allClasses, '\n', entries);
67 while ((!contains(classfile, file) ||
68 (onlyFilename(classfile) != file)) &&
70 classfile = token(allClasses, '\n', ++entries);
73 // now we have filename with full path
74 lyxerr << "with full path: " << classfile << endl;
80 GuiTexInfo::GuiTexInfo(GuiView & lv)
81 : GuiDialog(lv, "texinfo", qt_("TeX Information"))
85 warningPosted = false;
86 activeStyle = ClsType;
88 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
90 connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
91 connect(whatStyleCO, SIGNAL(activated(QString)),
92 this, SLOT(enableViewPB()));
93 connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(updateView()));
94 connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(updateView()));
95 connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB()));
96 connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked()));
97 connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)),
98 this, SLOT(enableViewPB()));
99 connect(fileListLW, SIGNAL(itemSelectionChanged()),
100 this, SLOT(enableViewPB()));
102 updateStyles(ClsType);
104 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
105 bc().setCancel(closePB);
109 void GuiTexInfo::change_adaptor()
115 void GuiTexInfo::rescanClicked()
117 // build new *Files.lst
124 void GuiTexInfo::viewClicked()
126 size_t const fitem = fileListLW->currentRow();
127 vector<string> const & data = texdata_[activeStyle];
128 string file = data[fitem];
129 if (!pathCB->isChecked())
130 file = texFileFromList(data[fitem], fileType(activeStyle));
135 void GuiTexInfo::updateView()
137 // takes advantage of enum order
138 updateStyles(static_cast<TexFileType>(whatStyleCO->currentIndex()));
143 void GuiTexInfo::enableViewPB()
145 viewPB->setEnabled(fileListLW->currentRow() > -1);
149 void GuiTexInfo::updateStyles(TexFileType type)
151 ContentsType & data = texdata_[type];
153 static string filenames[] = { "clsFile.lst", "styFiles.lst", "bstFiles.lst" };
154 string filename = filenames[type];
156 getTexFileList(filename, data);
158 // build filelists of all availabe bst/cls/sty-files.
159 // Done through kpsewhich and an external script,
160 // saved in *Files.lst
162 getTexFileList(filename, data);
164 bool const withFullPath = pathCB->isChecked();
167 vector<string>::iterator it1 = data.begin();
168 vector<string>::iterator end1 = data.end();
169 for (; it1 != end1; ++it1)
170 *it1 = onlyFilename(*it1);
172 // sort on filename only (no path)
173 sort(data.begin(), data.end());
176 ContentsType::const_iterator it = data.begin();
177 ContentsType::const_iterator end = data.end();
178 for (; it != end; ++it)
179 fileListLW->addItem(toqstr(*it));
185 void GuiTexInfo::updateStyles()
187 updateStyles(activeStyle);
191 void GuiTexInfo::viewFile(string const & filename) const
193 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + filename));
197 /// get a class with full path from the list
198 string GuiTexInfo::classOptions(string const & classname) const
200 FileName const filename(texFileFromList(classname, "cls"));
201 if (filename.empty())
204 ifstream is(filename.toFilesystemEncoding().c_str());
208 if (contains(s, "DeclareOption")) {
209 s = s.substr(s.find("DeclareOption"));
210 s = split(s, '{'); // cut front
211 s = token(s, '}', 0); // cut end
212 optionList += (s + '\n');
219 string GuiTexInfo::fileType(TexFileType type) const
221 // takes advantage of enum order
222 static string const ext[] = { "cls", "sty", "bst" };
227 Dialog * createGuiTexInfo(GuiView & lv) { return new GuiTexInfo(lv); }
230 } // namespace frontend
234 #include "GuiTexinfo_moc.cpp"