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"
|
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 "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QPushButton>
|
2008-03-08 20:18:22 +00:00
|
|
|
#include <QStringList>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
static QString texFileFromList(QString const & file, QString const & type)
|
2007-10-06 08:47:08 +00:00
|
|
|
{
|
2008-03-08 07:59:47 +00:00
|
|
|
QString lstfile = type + "Files.lst";
|
|
|
|
FileName const abslstfile = libFileSearch(QString(), lstfile);
|
2008-03-08 20:18:22 +00:00
|
|
|
if (abslstfile.empty())
|
2008-03-08 07:59:47 +00:00
|
|
|
return QString();
|
2008-03-08 20:18:22 +00:00
|
|
|
QString cs = toqstr(abslstfile.fileContents("UTF-8"));
|
|
|
|
cs.replace("\r", "");
|
|
|
|
QStringList const result = cs.split("\n").filter(file);
|
|
|
|
if (result.empty())
|
|
|
|
return QString();
|
|
|
|
return result.at(0);
|
2007-10-06 08:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiTexInfo::GuiTexInfo(GuiView & lv)
|
2008-02-05 12:43:19 +00:00
|
|
|
: GuiDialog(lv, "texinfo", qt_("TeX Information"))
|
2007-04-24 15:10:14 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
warningPosted_ = false;
|
|
|
|
activeStyle_ = ClsType;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2018-07-10 11:04:02 +00:00
|
|
|
connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
|
|
|
|
this, SLOT(slotButtonBox(QAbstractButton *)));
|
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
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::OkCancelPolicy);
|
2018-07-10 11:04:02 +00:00
|
|
|
bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
|
2007-09-05 20:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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::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
|
|
|
{
|
2008-03-08 07:59:47 +00:00
|
|
|
// takes advantage of enum order
|
2017-01-01 10:34:35 +00:00
|
|
|
static QString const ext[] = { "cls", "sty", "bst", "bib", "bbx", "cbx" };
|
2008-03-08 07:59:47 +00:00
|
|
|
int const fitem = fileListLW->currentRow();
|
2018-02-24 06:01:34 +00:00
|
|
|
QStringList const & sdata = texdata_[activeStyle_];
|
|
|
|
QString file = sdata[fitem];
|
2007-04-24 15:10:14 +00:00
|
|
|
if (!pathCB->isChecked())
|
2018-02-24 06:01:34 +00:00
|
|
|
file = texFileFromList(sdata[fitem], ext[activeStyle_]);
|
2007-10-06 08:47:08 +00:00
|
|
|
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
|
|
|
{
|
2008-03-08 07:59:47 +00:00
|
|
|
static QString const filenames[] = {
|
2017-01-01 10:34:35 +00:00
|
|
|
"clsFiles.lst", "styFiles.lst", "bstFiles.lst", "bibFiles.lst",
|
|
|
|
"bbxFiles.lst", "cbxFiles.lst"
|
2008-03-08 07:59:47 +00:00
|
|
|
};
|
2007-09-11 21:27:57 +00:00
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
QString const filename = filenames[type];
|
2007-10-06 08:47:08 +00:00
|
|
|
|
2018-02-24 06:01:34 +00:00
|
|
|
QStringList flist = texFileList(filename);
|
|
|
|
if (flist.empty()) {
|
2007-09-11 21:27:57 +00:00
|
|
|
// build filelists of all availabe bst/cls/sty-files.
|
|
|
|
// Done through kpsewhich and an external script,
|
|
|
|
// saved in *Files.lst
|
|
|
|
rescanTexStyles();
|
2018-02-24 06:01:34 +00:00
|
|
|
flist = texFileList(filename);
|
2007-09-11 21:27:57 +00:00
|
|
|
}
|
2008-03-08 07:59:47 +00:00
|
|
|
|
2008-03-07 23:37:55 +00:00
|
|
|
if (!pathCB->isChecked()) {
|
2018-02-24 06:01:34 +00:00
|
|
|
for (int i = 0; i != flist.size(); ++i)
|
|
|
|
flist[i] = onlyFileName(flist[i]);
|
2008-03-07 23:37:55 +00:00
|
|
|
}
|
2007-09-11 21:27:57 +00:00
|
|
|
// sort on filename only (no path)
|
2018-02-24 06:01:34 +00:00
|
|
|
flist.sort();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
fileListLW->clear();
|
2018-02-24 06:01:34 +00:00
|
|
|
for(QString const & item : flist)
|
2008-03-08 07:59:47 +00:00
|
|
|
fileListLW->addItem(item);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
activeStyle_ = type;
|
2018-02-24 06:01:34 +00:00
|
|
|
texdata_[type] = flist;
|
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
|
|
|
{
|
2008-03-08 07:59:47 +00:00
|
|
|
updateStyles(activeStyle_);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 08:47:08 +00:00
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
void GuiTexInfo::viewFile(QString const & filename) const
|
2007-10-06 08:47:08 +00:00
|
|
|
{
|
2008-03-08 07:59:47 +00:00
|
|
|
dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + fromqstr(filename)));
|
2007-10-06 08:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// get a class with full path from the list
|
2008-03-08 07:59:47 +00:00
|
|
|
/*
|
2007-10-06 08:47:08 +00:00
|
|
|
string GuiTexInfo::classOptions(string const & classname) const
|
|
|
|
{
|
|
|
|
FileName const filename(texFileFromList(classname, "cls"));
|
|
|
|
if (filename.empty())
|
|
|
|
return string();
|
|
|
|
string optionList;
|
2007-12-12 19:28:07 +00:00
|
|
|
ifstream is(filename.toFilesystemEncoding().c_str());
|
2007-10-06 08:47:08 +00:00
|
|
|
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;
|
|
|
|
}
|
2008-03-08 07:59:47 +00:00
|
|
|
*/
|
2007-10-06 08:47:08 +00:00
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiTexInfo(GuiView & lv) { return new GuiTexInfo(lv); }
|
2007-10-06 08:47:08 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 15:10:14 +00:00
|
|
|
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiTexinfo.cpp"
|