2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiTexinfo.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
2007-10-06 08:47:08 +00:00
|
|
|
* \author Herbert Voß
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiTexinfo.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "debug.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include "support/filetools.h"
|
2007-10-06 08:47:08 +00:00
|
|
|
#include "support/FileName.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#include <QCloseEvent>
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QPushButton>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
#include <fstream>
|
2007-09-17 23:00:53 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
using std::string;
|
2007-04-24 15:10:14 +00:00
|
|
|
using std::vector;
|
2007-10-06 08:47:08 +00:00
|
|
|
using std::endl;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
using support::FileName;
|
|
|
|
using support::contains;
|
|
|
|
using support::split;
|
|
|
|
using support::token;
|
|
|
|
using support::getExtension;
|
|
|
|
using support::libFileSearch;
|
|
|
|
using support::onlyFilename;
|
|
|
|
|
|
|
|
static string texFileFromList(string const & file, string const & type)
|
|
|
|
{
|
|
|
|
string file_ = file;
|
|
|
|
// do we need to add the suffix?
|
|
|
|
if (!(getExtension(file) == type))
|
|
|
|
file_ += '.' + type;
|
|
|
|
|
|
|
|
lyxerr << "Searching for file " << file_ << endl;
|
|
|
|
|
|
|
|
string lstfile = type + "Files.lst";
|
|
|
|
if (type == "cls")
|
|
|
|
lstfile = "clsFiles.lst";
|
|
|
|
else if (type == "sty")
|
|
|
|
lstfile = "styFiles.lst";
|
|
|
|
else if (type == "bst")
|
|
|
|
lstfile = "bstFiles.lst";
|
|
|
|
else if (type == "bib")
|
|
|
|
lstfile = "bibFiles.lst";
|
|
|
|
FileName const abslstfile = libFileSearch(string(), lstfile);
|
|
|
|
if (abslstfile.empty()) {
|
|
|
|
lyxerr << "File `'" << lstfile << "' not found." << endl;
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
string const allClasses = getFileContents(abslstfile);
|
|
|
|
int entries = 0;
|
|
|
|
string classfile = token(allClasses, '\n', entries);
|
|
|
|
int count = 0;
|
|
|
|
while ((!contains(classfile, file) ||
|
|
|
|
(onlyFilename(classfile) != file)) &&
|
|
|
|
(++count < 1000)) {
|
|
|
|
classfile = token(allClasses, '\n', ++entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
// now we have filename with full path
|
|
|
|
lyxerr << "with full path: " << classfile << endl;
|
|
|
|
|
|
|
|
return classfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GuiTexInfo::GuiTexInfo(LyXView & lv)
|
2007-10-09 19:34:27 +00:00
|
|
|
: GuiDialog(lv, "texinfo")
|
2007-04-24 15:10:14 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
setViewTitle(_("TeX Information"));
|
2007-04-24 15:10:14 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
warningPosted = false;
|
2007-10-06 08:47:08 +00:00
|
|
|
activeStyle = ClsType;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
2007-04-24 15:10:14 +00:00
|
|
|
|
|
|
|
connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
|
2007-10-06 08:47:08 +00:00
|
|
|
connect(whatStyleCO, SIGNAL(activated(QString)),
|
2007-04-24 15:10:14 +00:00
|
|
|
this, SLOT(enableViewPB()));
|
2007-09-09 12:06:37 +00:00
|
|
|
connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(updateView()));
|
|
|
|
connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(updateView()));
|
2007-04-24 15:10:14 +00:00
|
|
|
connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB()));
|
|
|
|
connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked()));
|
|
|
|
connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)),
|
2007-09-05 20:33:29 +00:00
|
|
|
this, SLOT(enableViewPB()));
|
2007-04-24 15:10:14 +00:00
|
|
|
connect(fileListLW, SIGNAL(itemSelectionChanged()),
|
|
|
|
this, SLOT(enableViewPB()));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
updateStyles(ClsType);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::OkCancelPolicy);
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
void GuiTexInfo::change_adaptor()
|
2007-04-24 15:10:14 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-24 15:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
void GuiTexInfo::closeEvent(QCloseEvent * e)
|
2007-04-24 15:10:14 +00:00
|
|
|
{
|
2007-09-11 17:06:15 +00:00
|
|
|
slotClose();
|
2007-04-24 15:10:14 +00:00
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
void GuiTexInfo::rescanClicked()
|
2007-04-24 15:10:14 +00:00
|
|
|
{
|
|
|
|
// build new *Files.lst
|
|
|
|
rescanTexStyles();
|
2007-09-05 20:33:29 +00:00
|
|
|
updateStyles();
|
2007-04-24 15:10:14 +00:00
|
|
|
enableViewPB();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
void GuiTexInfo::viewClicked()
|
2007-04-24 15:10:14 +00:00
|
|
|
{
|
2007-08-31 05:53:55 +00:00
|
|
|
size_t const fitem = fileListLW->currentRow();
|
2007-09-05 20:33:29 +00:00
|
|
|
vector<string> const & data = texdata_[activeStyle];
|
2007-04-24 15:10:14 +00:00
|
|
|
string file = data[fitem];
|
|
|
|
if (!pathCB->isChecked())
|
2007-10-06 08:47:08 +00:00
|
|
|
file = texFileFromList(data[fitem], fileType(activeStyle));
|
|
|
|
viewFile(file);
|
2007-04-24 15:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
void GuiTexInfo::updateView()
|
2007-04-24 15:10:14 +00:00
|
|
|
{
|
2007-10-06 08:47:08 +00:00
|
|
|
// takes advantage of enum order
|
|
|
|
updateStyles(static_cast<TexFileType>(whatStyleCO->currentIndex()));
|
2007-04-24 15:10:14 +00:00
|
|
|
enableViewPB();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
void GuiTexInfo::enableViewPB()
|
2007-04-24 15:10:14 +00:00
|
|
|
{
|
|
|
|
viewPB->setEnabled(fileListLW->currentRow() > -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
void GuiTexInfo::updateStyles(TexFileType type)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-11 21:27:57 +00:00
|
|
|
ContentsType & data = texdata_[type];
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
static string filenames[] = { "clsFile.lst", "styFiles.lst", "bstFiles.lst" };
|
|
|
|
string filename = filenames[type];
|
|
|
|
|
2007-09-11 21:27:57 +00:00
|
|
|
getTexFileList(filename, data);
|
|
|
|
if (data.empty()) {
|
|
|
|
// build filelists of all availabe bst/cls/sty-files.
|
|
|
|
// Done through kpsewhich and an external script,
|
|
|
|
// saved in *Files.lst
|
|
|
|
rescanTexStyles();
|
|
|
|
getTexFileList(filename, data);
|
|
|
|
}
|
2007-09-05 20:33:29 +00:00
|
|
|
bool const withFullPath = pathCB->isChecked();
|
2007-09-11 21:27:57 +00:00
|
|
|
if (withFullPath)
|
|
|
|
return;
|
|
|
|
vector<string>::iterator it1 = data.begin();
|
|
|
|
vector<string>::iterator end1 = data.end();
|
|
|
|
for (; it1 != end1; ++it1)
|
|
|
|
*it1 = support::onlyFilename(*it1);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-11 21:27:57 +00:00
|
|
|
// sort on filename only (no path)
|
|
|
|
std::sort(data.begin(), data.end());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
fileListLW->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
ContentsType::const_iterator it = data.begin();
|
|
|
|
ContentsType::const_iterator end = data.end();
|
|
|
|
for (; it != end; ++it)
|
2007-09-05 20:33:29 +00:00
|
|
|
fileListLW->addItem(toqstr(*it));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-11 21:27:57 +00:00
|
|
|
activeStyle = type;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
void GuiTexInfo::updateStyles()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
updateStyles(activeStyle);
|
|
|
|
}
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
|
|
|
|
void GuiTexInfo::viewFile(string const & filename) const
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// get a class with full path from the list
|
|
|
|
string GuiTexInfo::classOptions(string const & classname) const
|
|
|
|
{
|
|
|
|
FileName const filename(texFileFromList(classname, "cls"));
|
|
|
|
if (filename.empty())
|
|
|
|
return string();
|
|
|
|
string optionList;
|
|
|
|
std::ifstream is(filename.toFilesystemEncoding().c_str());
|
|
|
|
while (is) {
|
|
|
|
string s;
|
|
|
|
is >> s;
|
|
|
|
if (contains(s, "DeclareOption")) {
|
|
|
|
s = s.substr(s.find("DeclareOption"));
|
|
|
|
s = split(s, '{'); // cut front
|
|
|
|
s = token(s, '}', 0); // cut end
|
|
|
|
optionList += (s + '\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return optionList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string GuiTexInfo::fileType(TexFileType type) const
|
|
|
|
{
|
|
|
|
// takes advantage of enum order
|
|
|
|
static string const ext[] = { "cls", "sty", "bst" };
|
|
|
|
return ext[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dialog * createGuiTexInfo(LyXView & lv) { return new GuiTexInfo(lv); }
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 15:10:14 +00:00
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiTexinfo_moc.cpp"
|