X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiTexinfo.cpp;h=cc901c9c2866876f33dbf1fd8a48a4f8bb083652;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=2efa10b37a2d6e3bedebebc7b9286a91c49e84d7;hpb=212386be8a1573fb52b5da718961835816a3c8e2;p=lyx.git diff --git a/src/frontends/qt4/GuiTexinfo.cpp b/src/frontends/qt4/GuiTexinfo.cpp index 2efa10b37a..cc901c9c28 100644 --- a/src/frontends/qt4/GuiTexinfo.cpp +++ b/src/frontends/qt4/GuiTexinfo.cpp @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author Edwin Leuven + * \author Herbert Voß * * Full author contact details are available in file CREDITS. */ @@ -11,157 +12,184 @@ #include #include "GuiTexinfo.h" -#include "qt_helpers.h" + +#include "FuncRequest.h" #include "support/filetools.h" +#include "support/foreach.h" +#include "support/FileName.h" + +#include "qt_helpers.h" -#include #include #include #include +#include -using std::string; -using std::vector; +using namespace std; +using namespace lyx::support; namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiTexinfoDialog -// -///////////////////////////////////////////////////////////////////// +static QString texFileFromList(QString const & file, QString const & type) +{ + QString lstfile = type + "Files.lst"; + FileName const abslstfile = libFileSearch(QString(), lstfile); + if (abslstfile.empty()) + return QString(); + 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); +} -GuiTexinfoDialog::GuiTexinfoDialog(GuiTexinfo * form) - : form_(form) +GuiTexInfo::GuiTexInfo(GuiView & lv) + : GuiDialog(lv, "texinfo", qt_("TeX Information")) { setupUi(this); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + warningPosted_ = false; + activeStyle_ = ClsType; + + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked())); - connect(whatStyleCO, SIGNAL(activated(const QString &)), + connect(whatStyleCO, SIGNAL(activated(QString)), this, SLOT(enableViewPB())); - connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(update())); - connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(update())); + connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(updateView())); + connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(updateView())); connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB())); connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked())); connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)), - this, SLOT( enableViewPB() ) ); + this, SLOT(enableViewPB())); connect(fileListLW, SIGNAL(itemSelectionChanged()), this, SLOT(enableViewPB())); -} - -void GuiTexinfoDialog::change_adaptor() -{ - form_->changed(); + bc().setPolicy(ButtonPolicy::OkCancelPolicy); + bc().setCancel(closePB); } -void GuiTexinfoDialog::closeEvent(QCloseEvent * e) +void GuiTexInfo::change_adaptor() { - form_->slotWMHide(); - e->accept(); + changed(); } -void GuiTexinfoDialog::rescanClicked() +void GuiTexInfo::rescanClicked() { // build new *Files.lst rescanTexStyles(); - form_->updateStyles(); + updateStyles(); enableViewPB(); } -void GuiTexinfoDialog::viewClicked() +void GuiTexInfo::viewClicked() { - size_t const fitem = fileListLW->currentRow(); - vector const & data = form_->texdata_[form_->activeStyle]; - string file = data[fitem]; + // takes advantage of enum order + static QString const ext[] = { "cls", "sty", "bst" }; + int const fitem = fileListLW->currentRow(); + QStringList const & data = texdata_[activeStyle_]; + QString file = data[fitem]; if (!pathCB->isChecked()) - file = getTexFileFromList(data[fitem], - form_->controller().getFileType(form_->activeStyle)); - form_->controller().viewFile(file); + file = texFileFromList(data[fitem], ext[activeStyle_]); + viewFile(file); } -void GuiTexinfoDialog::update() +void GuiTexInfo::updateView() { - switch (whatStyleCO->currentIndex()) { - case 0: - form_->updateStyles(ControlTexinfo::cls); - break; - case 1: - form_->updateStyles(ControlTexinfo::sty); - break; - case 2: - form_->updateStyles(ControlTexinfo::bst); - break; - default: - break; - } - + // takes advantage of enum order + updateStyles(static_cast(whatStyleCO->currentIndex())); enableViewPB(); } -void GuiTexinfoDialog::enableViewPB() +void GuiTexInfo::enableViewPB() { viewPB->setEnabled(fileListLW->currentRow() > -1); } -///////////////////////////////////////////////////////////////////// -// -// GuiTexinfo -// -///////////////////////////////////////////////////////////////////// - - -GuiTexinfo::GuiTexinfo(GuiDialog & parent) - : GuiView(parent, _("TeX Information")), - warningPosted(false), activeStyle(ControlTexinfo::cls) +void GuiTexInfo::updateStyles(TexFileType type) { -} - + static QString const filenames[] = { + "clsFiles.lst", "styFiles.lst", "bstFiles.lst" + }; + + QString const filename = filenames[type]; + + QStringList data = texFileList(filename); + if (data.empty()) { + // build filelists of all availabe bst/cls/sty-files. + // Done through kpsewhich and an external script, + // saved in *Files.lst + rescanTexStyles(); + data = texFileList(filename); + } -void GuiTexinfo::build_dialog() -{ - dialog_.reset(new GuiTexinfoDialog(this)); + if (!pathCB->isChecked()) { + for (int i = 0; i != data.size(); ++i) + data[i] = onlyFilename(data[i]); + } + // sort on filename only (no path) + data.sort(); - updateStyles(ControlTexinfo::cls); + fileListLW->clear(); + foreach (QString const & item, data) + fileListLW->addItem(item); - bc().setCancel(dialog_->closePB); + activeStyle_ = type; + texdata_[type] = data; } -void GuiTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle) +void GuiTexInfo::updateStyles() { - ContentsType & data = texdata_[whichStyle]; - bool const withFullPath = dialog_->pathCB->isChecked(); - - getTexFileList(whichStyle, data, withFullPath); + updateStyles(activeStyle_); +} - dialog_->fileListLW->clear(); - ContentsType::const_iterator it = data.begin(); - ContentsType::const_iterator end = data.end(); - for (; it != end; ++it) - dialog_->fileListLW->addItem(toqstr(*it)); - activeStyle = whichStyle; +void GuiTexInfo::viewFile(QString const & filename) const +{ + dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + fromqstr(filename))); } -void GuiTexinfo::updateStyles() +/// get a class with full path from the list +/* +string GuiTexInfo::classOptions(string const & classname) const { - updateStyles(activeStyle); + FileName const filename(texFileFromList(classname, "cls")); + if (filename.empty()) + return string(); + string optionList; + 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; } +*/ + + +Dialog * createGuiTexInfo(GuiView & lv) { return new GuiTexInfo(lv); } + } // namespace frontend } // namespace lyx -#include "GuiTexinfo_moc.cpp" +#include "moc_GuiTexinfo.cpp"