]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiTexinfo.cpp
Also display the info about BibTeX databases in the TeX info panel.
[lyx.git] / src / frontends / qt4 / GuiTexinfo.cpp
index 048df8d7e6c8e8ef6c8edcaba16df189bfb11e56..846232289c5486c47395c02fc3ed1b211a4431ee 100644 (file)
 #include "GuiTexinfo.h"
 
 #include "FuncRequest.h"
-#include "support/debug.h"
 
 #include "support/filetools.h"
+#include "support/foreach.h"
 #include "support/FileName.h"
-#include "support/lstrings.h"
 
 #include "qt_helpers.h"
 
-#include <QCloseEvent>
 #include <QCheckBox>
 #include <QListWidget>
 #include <QPushButton>
-
-#include <fstream>
-#include <algorithm>
+#include <QStringList>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 namespace frontend {
 
-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)
+static QString texFileFromList(QString const & file, QString 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();
-       }
-       // FIXME UNICODE
-       string const allClasses = to_utf8(abslstfile.fileContents("UTF-8"));
-       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;
+       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);
 }
 
 
 GuiTexInfo::GuiTexInfo(GuiView & lv)
-       : GuiDialog(lv, "texinfo")
+       : GuiDialog(lv, "texinfo", qt_("TeX Information"))
 {
        setupUi(this);
-       setViewTitle(_("TeX Information"));
 
-       warningPosted = false;
-       activeStyle = ClsType;
+       warningPosted_ = false;
+       activeStyle_ = ClsType;
 
        connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
 
@@ -107,8 +69,6 @@ GuiTexInfo::GuiTexInfo(GuiView & lv)
        connect(fileListLW, SIGNAL(itemSelectionChanged()),
                this, SLOT(enableViewPB()));
 
-       updateStyles(ClsType);
-
        bc().setPolicy(ButtonPolicy::OkCancelPolicy);
        bc().setCancel(closePB);
 }
@@ -120,13 +80,6 @@ void GuiTexInfo::change_adaptor()
 }
 
 
-void GuiTexInfo::closeEvent(QCloseEvent * e)
-{
-       slotClose();
-       e->accept();
-}
-
-
 void GuiTexInfo::rescanClicked()
 {
        // build new *Files.lst
@@ -138,11 +91,13 @@ void GuiTexInfo::rescanClicked()
 
 void GuiTexInfo::viewClicked()
 {
-       size_t const fitem = fileListLW->currentRow();
-       vector<string> const & data = texdata_[activeStyle];
-       string file = data[fitem];
+       // takes advantage of enum order
+       static QString const ext[] = { "cls", "sty", "bst", "bib" };
+       int const fitem = fileListLW->currentRow();
+       QStringList const & data = texdata_[activeStyle_];
+       QString file = data[fitem];
        if (!pathCB->isChecked())
-               file = texFileFromList(data[fitem], fileType(activeStyle));
+               file = texFileFromList(data[fitem], ext[activeStyle_]);
        viewFile(file);
 }
 
@@ -163,60 +118,58 @@ void GuiTexInfo::enableViewPB()
 
 void GuiTexInfo::updateStyles(TexFileType type)
 {
-       ContentsType & data = texdata_[type];
+       static QString const filenames[] = {
+               "clsFiles.lst", "styFiles.lst", "bstFiles.lst", "bibFiles.lst"
+       };
 
-       static string filenames[] = { "clsFile.lst", "styFiles.lst", "bstFiles.lst" };
-       string filename = filenames[type];
+       QString const filename = filenames[type];
 
-       getTexFileList(filename, data);
+       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();
-               getTexFileList(filename, data);
+               data = texFileList(filename);
        }
-       bool const withFullPath = pathCB->isChecked();
-       if (withFullPath)
-               return;
-       vector<string>::iterator it1  = data.begin();
-       vector<string>::iterator end1 = data.end();
-       for (; it1 != end1; ++it1)
-               *it1 = support::onlyFilename(*it1);
 
+       if (!pathCB->isChecked()) {
+               for (int i = 0; i != data.size(); ++i)
+                       data[i] = onlyFileName(data[i]);
+       }
        // sort on filename only (no path)
-       std::sort(data.begin(), data.end());
+       data.sort();
 
        fileListLW->clear();
-       ContentsType::const_iterator it  = data.begin();
-       ContentsType::const_iterator end = data.end();
-       for (; it != end; ++it)
-               fileListLW->addItem(toqstr(*it));
+       foreach (QString const & item, data)
+               fileListLW->addItem(item);
 
-       activeStyle = type;
+       activeStyle_ = type;
+       texdata_[type] = data;
 }
 
 
 void GuiTexInfo::updateStyles()
 {
-       updateStyles(activeStyle);
+       updateStyles(activeStyle_);
 }
 
 
-void GuiTexInfo::viewFile(string const & filename) const
+void GuiTexInfo::viewFile(QString const & filename) const
 {
-       dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + filename));
+       dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + fromqstr(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());
+       ifstream is(filename.toFilesystemEncoding().c_str());
        while (is) {
                string s;
                is >> s;
@@ -229,14 +182,7 @@ string GuiTexInfo::classOptions(string const & classname) const
        }
        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(GuiView & lv) { return new GuiTexInfo(lv); }
@@ -246,4 +192,4 @@ Dialog * createGuiTexInfo(GuiView & lv) { return new GuiTexInfo(lv); }
 } // namespace lyx
 
 
-#include "GuiTexinfo_moc.cpp"
+#include "moc_GuiTexinfo.cpp"