]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlTexinfo.C
Rename .C => .cpp for files in src/frontends/controllers, step 1
[lyx.git] / src / frontends / controllers / ControlTexinfo.C
index 040192ce35becb13c33de9872a43035b0bc661fc..7694773600a4fb9e684573baeef32858d1981097 100644 (file)
-/* This file is part of
- * ======================================================
+/**
+ * \file ControlTexinfo.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Herbert Voß
  *
- *           Copyright 2001 The LyX Team.
- *
- * ======================================================
- *
- * \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 "ViewBase.h"
-#include "ButtonControllerBase.h"
 #include "ControlTexinfo.h"
-#include "Dialogs.h"
-#include "frontends/LyXView.h"
-#include "BufferView.h"
-#include "gettext.h"
-#include "support/filetools.h" // FileSearch
-#include "support/systemcall.h"
-#include "support/path.h"
-#include "helper_funcs.h"
-#include "support/lstrings.h"
+#include "funcrequest.h"
 
-extern string user_lyxdir; // home of *Files.lst
+#include "support/filetools.h"
 
+#include <algorithm>
 
-ControlTexinfo::ControlTexinfo(LyXView & lv, Dialogs & d)
-       : ControlDialogBI(lv, d)
-{
-       d_.showTexinfo.connect(SigC::slot(this, &ControlTexinfo::show));
-}
+using std::string;
+using std::vector;
+
+namespace lyx {
 
+using support::onlyFilename;
 
-// build filelists of all availabe bst/cls/sty-files. done through
-// kpsewhich and an external script, saved in *Files.lst
-void ControlTexinfo::rescanStyles() const
+namespace frontend {
+
+void getTexFileList(ControlTexinfo::texFileSuffix type,
+                   std::vector<string> & list, bool withPath)
 {
-       // Run rescan in user lyx directory
-       Path p(user_lyxdir);
-       Systemcall one;
-       one.startscript(Systemcall::Wait,
-                       LibFileSearch("scripts", "TeXFiles.sh"));
-       p.pop();
+       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, 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::runTexhash() const
-{
-       // Run texhash in user lyx directory
-       Path p(user_lyxdir);
+ControlTexinfo::ControlTexinfo(Dialog & parent)
+       : Dialog::Controller(parent)
+{}
 
-       //path to texhash through system
-       Systemcall one;
-       one.startscript(Systemcall::Wait, "texhash");
 
-       p.pop();
-//     Alert::alert(_("texhash run!"),
-//                _("rebuilding of the TeX-tree could only be successfull"),
-//                _("if you have had user-write-permissions to the tex-dir."));
+void ControlTexinfo::viewFile(string const & filename) const
+{
+       string const arg = "file " + filename;
+       kernel().dispatch(FuncRequest(LFUN_DIALOG_SHOW, arg));
 }
 
 
-namespace {
-
-string const sortEntries(string & str_in)
+string const ControlTexinfo::getClassOptions(string const & filename) const
 {
-       std::vector<string> dbase = getVectorFromString(str_in,"\n");
-       std::sort(dbase.begin(), dbase.end());          // sort entries
-       std::vector<string>::iterator p =
-           std::unique(dbase.begin(), dbase.end());    // compact
-       dbase.erase(p, dbase.end());                    // shrink
-       return getStringFromVector(dbase,"\n");
+       return getListOfOptions(filename, "cls");
 }
 
-} //namespace anon
 
-
-string const
-ControlTexinfo::getContents(texFileSuffix type, bool withFullPath) const
+string const ControlTexinfo::getFileType(ControlTexinfo::texFileSuffix type) const
 {
-       static string const bstFilename("bstFiles.lst");
-       static string const clsFilename("clsFiles.lst");
-       static string const styFilename("styFiles.lst");
-
-       string filename;
+       string ftype;
        switch (type) {
-       case bst:
-               filename = bstFilename;
+       case ControlTexinfo::bst:
+               ftype = "bst";
                break;
-       case cls:
-               filename = clsFilename;
+       case ControlTexinfo::cls:
+               ftype = "cls";
                break;
-       case sty:
-               filename = styFilename;
+       case ControlTexinfo::sty:
+               ftype = "sty";
                break;
        }
-
-       string fileContents = GetFileContents(LibFileSearch(string(),filename));
-       // everything ok?
-       if (!fileContents.empty()) {
-               if (withFullPath)
-                       return(sortEntries(fileContents));
-               else {
-                       int Entries = 1;
-                       string dummy = OnlyFilename(token(fileContents,'\n',1));
-                       string contents = dummy;
-                       do {
-                               dummy = OnlyFilename(token(fileContents,'\n',++Entries));
-                               contents += ("\n"+dummy);
-                       } while (!dummy.empty());
-                       return(sortEntries(contents));
-               }
-       } else
-               return _("Missing filelist. try Rescan");
+       return ftype;
 }
 
-void ControlTexinfo::viewFile(string const filename) const
-{
-       lv_.getDialogs()->showFile(filename);
-}
+} // namespace frontend
+} // namespace lyx