]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiTexinfo.cpp
QDialogButtonBox for the remaining dialogs.
[lyx.git] / src / frontends / qt4 / GuiTexinfo.cpp
index de2c7e118a078ef31d3ec0be205a48d3c17ecb9c..554b874095cde560d057c2115976fb10a8770e7e 100644 (file)
 
 #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 <QCheckBox>
 #include <QListWidget>
 #include <QPushButton>
-
-#include <fstream>
-#include <algorithm>
+#include <QStringList>
 
 using namespace std;
 using namespace lyx::support;
@@ -38,42 +33,16 @@ namespace frontend {
 
 static QString texFileFromList(QString const & file, QString const & type)
 {
-       QString file_ = file;
-       // do we need to add the suffix?
-       if (getExtension(file) != type)
-               file_ += '.' + type;
-
-       lyxerr << "Searching for file " << fromqstr(file_) << endl;
-
        QString 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(QString(), lstfile);
-       if (abslstfile.empty()) {
-               lyxerr << "File `'" << fromqstr(lstfile) << "' not found." << endl;
+       if (abslstfile.empty())
                return QString();
-       }
-       // 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, fromqstr(file))
-                                               || support::onlyFilename(classfile) != fromqstr(file))
-                                       && ++count < 1000) {
-               classfile = token(allClasses, '\n', ++entries);
-       }
-
-       // now we have filename with full path
-       lyxerr << "with full path: " << classfile << endl;
-
-       return toqstr(classfile);
+       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);
 }
 
 
@@ -85,7 +54,8 @@ GuiTexInfo::GuiTexInfo(GuiView & lv)
        warningPosted_ = false;
        activeStyle_ = ClsType;
 
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
 
        connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
        connect(whatStyleCO, SIGNAL(activated(QString)),
@@ -100,7 +70,7 @@ GuiTexInfo::GuiTexInfo(GuiView & lv)
                this, SLOT(enableViewPB()));
 
        bc().setPolicy(ButtonPolicy::OkCancelPolicy);
-       bc().setCancel(closePB);
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
 }
 
 
@@ -122,12 +92,12 @@ void GuiTexInfo::rescanClicked()
 void GuiTexInfo::viewClicked()
 {
        // takes advantage of enum order
-       static QString const ext[] = { "cls", "sty", "bst" };
+       static QString const ext[] = { "cls", "sty", "bst", "bib", "bbx", "cbx" };
        int const fitem = fileListLW->currentRow();
-       QStringList const & data = texdata_[activeStyle_];
-       QString file = data[fitem];
+       QStringList const & sdata = texdata_[activeStyle_];
+       QString file = sdata[fitem];
        if (!pathCB->isChecked())
-               file = texFileFromList(data[fitem], ext[activeStyle_]);
+               file = texFileFromList(sdata[fitem], ext[activeStyle_]);
        viewFile(file);
 }
 
@@ -149,33 +119,34 @@ void GuiTexInfo::enableViewPB()
 void GuiTexInfo::updateStyles(TexFileType type)
 {
        static QString const filenames[] = {
-               "clsFiles.lst", "styFiles.lst", "bstFiles.lst"
+               "clsFiles.lst", "styFiles.lst", "bstFiles.lst", "bibFiles.lst",
+               "bbxFiles.lst", "cbxFiles.lst"
        };
 
        QString const filename = filenames[type];
 
-       QStringList data = texFileList(filename);
-       if (data.empty()) {
+       QStringList flist = texFileList(filename);
+       if (flist.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);
+               flist = texFileList(filename);
        }
 
        if (!pathCB->isChecked()) {
-               for (int i = 0; i != data.size(); ++i)
-                       data[i] = onlyFilename(data[i]);
+               for (int i = 0; i != flist.size(); ++i)
+                       flist[i] = onlyFileName(flist[i]);
        }
        // sort on filename only (no path)
-       data.sort();
+       flist.sort();
 
        fileListLW->clear();
-       foreach (QString const & item, data)
+       for(QString const & item : flist)
                fileListLW->addItem(item);
 
        activeStyle_ = type;
-       texdata_[type] = data;
+       texdata_[type] = flist;
 }
 
 
@@ -222,4 +193,4 @@ Dialog * createGuiTexInfo(GuiView & lv) { return new GuiTexInfo(lv); }
 } // namespace lyx
 
 
-#include "GuiTexinfo_moc.cpp"
+#include "moc_GuiTexinfo.cpp"