]> 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 f19103a19b0721a7450d2ef128f386d413da89ed..846232289c5486c47395c02fc3ed1b211a4431ee 100644 (file)
@@ -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.
  */
 
 #include "GuiTexinfo.h"
 
-#include "ControlTexinfo.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 <QCloseEvent>
 #include <QCheckBox>
 #include <QListWidget>
 #include <QPushButton>
+#include <QStringList>
 
-#include <algorithm>
-
-using std::string;
-using std::vector;
-
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 namespace frontend {
 
-GuiTexinfoDialog::GuiTexinfoDialog(LyXView & lv)
-       : GuiDialog(lv, "texinfo")
+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);
+}
+
+
+GuiTexInfo::GuiTexInfo(GuiView & lv)
+       : GuiDialog(lv, "texinfo", qt_("TeX Information"))
 {
        setupUi(this);
-       setViewTitle(_("TeX Information"));
-       setController(new ControlTexinfo(*this));
 
-       warningPosted = false;
-       activeStyle = ControlTexinfo::cls;
+       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(updateView()));
        connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(updateView()));
@@ -55,33 +69,18 @@ GuiTexinfoDialog::GuiTexinfoDialog(LyXView & lv)
        connect(fileListLW, SIGNAL(itemSelectionChanged()),
                this, SLOT(enableViewPB()));
 
-       updateStyles(ControlTexinfo::cls);
-
        bc().setPolicy(ButtonPolicy::OkCancelPolicy);
        bc().setCancel(closePB);
 }
 
 
-ControlTexinfo & GuiTexinfoDialog::controller()
-{
-       return static_cast<ControlTexinfo &>(GuiDialog::controller());
-}
-
-
-void GuiTexinfoDialog::change_adaptor()
+void GuiTexInfo::change_adaptor()
 {
        changed();
 }
 
 
-void GuiTexinfoDialog::closeEvent(QCloseEvent * e)
-{
-       slotClose();
-       e->accept();
-}
-
-
-void GuiTexinfoDialog::rescanClicked()
+void GuiTexInfo::rescanClicked()
 {
        // build new *Files.lst
        rescanTexStyles();
@@ -90,96 +89,107 @@ void GuiTexinfoDialog::rescanClicked()
 }
 
 
-void GuiTexinfoDialog::viewClicked()
+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 = getTexFileFromList(data[fitem],
-                       controller().getFileType(activeStyle));
-       controller().viewFile(file);
+               file = texFileFromList(data[fitem], ext[activeStyle_]);
+       viewFile(file);
 }
 
 
-void GuiTexinfoDialog::updateView()
+void GuiTexInfo::updateView()
 {
-       switch (whatStyleCO->currentIndex()) {
-               case 0:
-                       updateStyles(ControlTexinfo::cls);
-                       break;
-               case 1:
-                       updateStyles(ControlTexinfo::sty);
-                       break;
-               case 2:
-                       updateStyles(ControlTexinfo::bst);
-                       break;
-               default:
-                       break;
-       }
-
+       // takes advantage of enum order
+       updateStyles(static_cast<TexFileType>(whatStyleCO->currentIndex()));
        enableViewPB();
 }
 
 
-void GuiTexinfoDialog::enableViewPB()
+void GuiTexInfo::enableViewPB()
 {
        viewPB->setEnabled(fileListLW->currentRow() > -1);
 }
 
 
-void GuiTexinfoDialog::updateStyles(ControlTexinfo::texFileSuffix type)
+void GuiTexInfo::updateStyles(TexFileType type)
 {
-       ContentsType & data = texdata_[type];
-
-       string filename;
-       switch (type) {
-       case ControlTexinfo::bst:
-               filename = "bstFiles.lst";
-               break;
-       case ControlTexinfo::cls:
-               filename = "clsFiles.lst";
-               break;
-       case ControlTexinfo::sty:
-               filename = "styFiles.lst";
-               break;
-       }
-       getTexFileList(filename, data);
+       static QString const filenames[] = {
+               "clsFiles.lst", "styFiles.lst", "bstFiles.lst", "bibFiles.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();
-               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;
+       texdata_[type] = data;
+}
+
 
-       activeStyle = type;
+void GuiTexInfo::updateStyles()
+{
+       updateStyles(activeStyle_);
 }
 
 
-void GuiTexinfoDialog::updateStyles()
+void GuiTexInfo::viewFile(QString const & filename) const
 {
-       updateStyles(activeStyle);
+       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;
+       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"