]> 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 d11d082224e0fe33e229251089b489b996fa33d0..6262d4a21e92234dfc52d1c63fd5ad8c21421df9 100644 (file)
@@ -1,78 +1,75 @@
-/* This file is part of
- * ======================================================
- *
- *           LyX, The Document Processor
- *
- *           Copyright 2001 The LyX Team.
+/**
+ * \file ControlTexinfo.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * ======================================================
+ * \author Herbert Voß
  *
- * \file ControlTexinfo.C
- * \author Herbert Voss <voss@lyx.org>
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "ControlTexinfo.h"
-#include "Dialogs.h"
-#include "BufferView.h"
-#include "gettext.h"
-#include "helper_funcs.h"
-#include "tex_helpers.h"
+#include "funcrequest.h"
 
-#include "frontends/LyXView.h"
+#include "support/filetools.h"
 
-#include "support/filetools.h" // FileSearch
-#include "support/path.h"
-#include "support/lstrings.h"
+#include <algorithm>
 
-extern string user_lyxdir; // home of *Files.lst
+using std::string;
+using std::vector;
 
+namespace lyx {
 
-ControlTexinfo::ControlTexinfo(LyXView & lv, Dialogs & d)
-       : ControlDialogBI(lv, d)
-{}
+using support::OnlyFilename;
 
+namespace frontend {
 
-// build filelists of all availabe bst/cls/sty-files. done through
-// kpsewhich and an external script, saved in *Files.lst
-void ControlTexinfo::rescanStyles() const
-{
-    rescanTexStyles();
-}
-
-
-void ControlTexinfo::runTexhash() const
-{
-    texhash();
-}
-
-
-string const
-ControlTexinfo::getContents(texFileSuffix type, bool withFullPath) const
+void getTexFileList(ControlTexinfo::texFileSuffix type,
+                   std::vector<string> & list, bool withPath)
 {
+       string filename;
        switch (type) {
-           case bst: 
-               return getTexFileList("bstFiles.lst", withFullPath);
+       case ControlTexinfo::bst:
+               filename = "bstFiles.lst";
                break;
-           case cls:
-               return getTexFileList("clsFiles.lst", withFullPath);
+       case ControlTexinfo::cls:
+               filename = "clsFiles.lst";
                break;
-           case 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());
 }
 
 
-void ControlTexinfo::viewFile(string const filename) const
+ControlTexinfo::ControlTexinfo(Dialog & parent)
+       : Dialog::Controller(parent)
+{}
+
+
+void ControlTexinfo::viewFile(string const & filename) const
 {
-       lv_.getDialogs()->showFile(filename);
+       string const arg = "file " + filename;
+       kernel().dispatch(FuncRequest(LFUN_DIALOG_SHOW, arg));
 }
 
 
@@ -80,3 +77,24 @@ string const ControlTexinfo::getClassOptions(string const & filename) const
 {
        return getListOfOptions(filename, "cls");
 }
+
+
+string const ControlTexinfo::getFileType(ControlTexinfo::texFileSuffix type) const
+{
+       string ftype;
+       switch (type) {
+       case ControlTexinfo::bst:
+               ftype = "bst";
+               break;
+       case ControlTexinfo::cls:
+               ftype = "cls";
+               break;
+       case ControlTexinfo::sty:
+               ftype = "sty";
+               break;
+       }
+       return ftype;
+}
+
+} // namespace frontend
+} // namespace lyx