]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlTexinfo.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlTexinfo.C
index d0ecf3d84562334885cb06ed64892864d17928b2..6262d4a21e92234dfc52d1c63fd5ad8c21421df9 100644 (file)
@@ -3,80 +3,98 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Herbert Voss
+ * \author Herbert Voß
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
 #include "ControlTexinfo.h"
-#include "tex_helpers.h"
 #include "funcrequest.h"
 
+#include "support/filetools.h"
 
-namespace {
+#include <algorithm>
 
-string getFileList(ControlTexinfo::texFileSuffix type, bool withFullPath)
+using std::string;
+using std::vector;
+
+namespace lyx {
+
+using support::OnlyFilename;
+
+namespace frontend {
+
+void getTexFileList(ControlTexinfo::texFileSuffix type,
+                   std::vector<string> & list, bool withPath)
 {
+       string filename;
        switch (type) {
-           case ControlTexinfo::bst:
-               return getTexFileList("bstFiles.lst", withFullPath);
+       case ControlTexinfo::bst:
+               filename = "bstFiles.lst";
                break;
-           case ControlTexinfo::cls:
-               return getTexFileList("clsFiles.lst", withFullPath);
+       case ControlTexinfo::cls:
+               filename = "clsFiles.lst";
                break;
-           case ControlTexinfo::sty:
-               return getTexFileList("styFiles.lst", withFullPath);
+       case ControlTexinfo::sty:
+               filename = "styFiles.lst";
                break;
        }
-       return string();
+       getTexFileList(filename, list);
+       if (list.empty()) {
+               // build filelists of all availabe bst/cls/sty-files.
+               // Done through kpsewhich and an external script,
+               // saved in *Files.lst
+               rescanTexStyles();
+               getTexFileList(filename, list);
+       }
+       if (withPath)
+               return;
+       vector<string>::iterator it  = list.begin();
+       vector<string>::iterator end = list.end();
+       for (; it != end; ++it) {
+               *it = OnlyFilename(*it);
+       }
+       // sort on filename only (no path)
+       std::sort(list.begin(), list.end());
 }
 
-} // namespace anon
-
 
 ControlTexinfo::ControlTexinfo(Dialog & parent)
        : Dialog::Controller(parent)
 {}
 
 
-// build filelists of all availabe bst/cls/sty-files. done through
-// kpsewhich and an external script, saved in *Files.lst
-void ControlTexinfo::rescanStyles() const
+void ControlTexinfo::viewFile(string const & filename) const
 {
-    rescanTexStyles();
+       string const arg = "file " + filename;
+       kernel().dispatch(FuncRequest(LFUN_DIALOG_SHOW, arg));
 }
 
 
-void ControlTexinfo::runTexhash() const
+string const ControlTexinfo::getClassOptions(string const & filename) const
 {
-    texhash();
+       return getListOfOptions(filename, "cls");
 }
 
 
-string const
-ControlTexinfo::getContents(texFileSuffix type, bool withFullPath) const
+string const ControlTexinfo::getFileType(ControlTexinfo::texFileSuffix type) const
 {
-       string list(getFileList(type, withFullPath));
-
-       // initial scan
-       if (list.empty()) {
-               rescanStyles();
-               list = getFileList(type, withFullPath);
+       string ftype;
+       switch (type) {
+       case ControlTexinfo::bst:
+               ftype = "bst";
+               break;
+       case ControlTexinfo::cls:
+               ftype = "cls";
+               break;
+       case ControlTexinfo::sty:
+               ftype = "sty";
+               break;
        }
-       return list;
-}
-
-
-void ControlTexinfo::viewFile(string const filename) const
-{
-       string const arg = "file " + filename;
-       kernel().dispatch(FuncRequest(LFUN_DIALOG_SHOW, arg));
+       return ftype;
 }
 
-
-string const ControlTexinfo::getClassOptions(string const & filename) const
-{
-       return getListOfOptions(filename, "cls");
-}
+} // namespace frontend
+} // namespace lyx