1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
10 * \file ControlTexinfo.C
11 * \author Herbert Voss <voss@lyx.org>
17 #pragma implementation
21 #include "ButtonControllerBase.h"
22 #include "ControlTexinfo.h"
24 #include "frontends/LyXView.h"
25 #include "BufferView.h"
27 #include "support/filetools.h" // FileSearch
28 #include "support/systemcall.h"
29 #include "support/path.h"
30 #include "helper_funcs.h"
31 #include "support/lstrings.h"
33 extern string user_lyxdir; // home of *Files.lst
36 ControlTexinfo::ControlTexinfo(LyXView & lv, Dialogs & d)
37 : ControlDialogBI(lv, d)
39 d_.showTexinfo.connect(SigC::slot(this, &ControlTexinfo::show));
43 // build filelists of all availabe bst/cls/sty-files. done through
44 // kpsewhich and an external script, saved in *Files.lst
45 void ControlTexinfo::rescanStyles() const
47 // Run rescan in user lyx directory
50 one.startscript(Systemcall::Wait,
51 LibFileSearch("scripts", "TeXFiles.sh"));
56 void ControlTexinfo::runTexhash() const
58 // Run texhash in user lyx directory
61 //path to texhash through system
63 one.startscript(Systemcall::Wait, "texhash");
66 // Alert::alert(_("texhash run!"),
67 // _("rebuilding of the TeX-tree could only be successfull"),
68 // _("if you have had user-write-permissions to the tex-dir."));
74 string const sortEntries(string & str_in)
76 std::vector<string> dbase = getVectorFromString(str_in,"\n");
77 std::sort(dbase.begin(), dbase.end()); // sort entries
78 std::vector<string>::iterator p =
79 std::unique(dbase.begin(), dbase.end()); // compact
80 dbase.erase(p, dbase.end()); // shrink
81 return getStringFromVector(dbase,"\n");
88 ControlTexinfo::getContents(texFileSuffix type, bool withFullPath) const
90 static string const bstFilename("bstFiles.lst");
91 static string const clsFilename("clsFiles.lst");
92 static string const styFilename("styFiles.lst");
97 filename = bstFilename;
100 filename = clsFilename;
103 filename = styFilename;
107 string fileContents = GetFileContents(LibFileSearch(string(),filename));
109 if (!fileContents.empty()) {
111 return(sortEntries(fileContents));
114 string dummy = OnlyFilename(token(fileContents,'\n',1));
115 string contents = dummy;
117 dummy = OnlyFilename(token(fileContents,'\n',++Entries));
118 contents += ("\n"+dummy);
119 } while (!dummy.empty());
120 return(sortEntries(contents));
123 return _("Missing filelist. try Rescan");
126 void ControlTexinfo::viewFile(string const filename) const
128 lv_.getDialogs()->showFile(filename);