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"
25 #include "BufferView.h"
27 #include "support/filetools.h" // FileSearch
28 #include "support/syscall.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
35 ControlTexinfo::ControlTexinfo(LyXView & lv, Dialogs & d)
36 : ControlDialog<ControlConnectBI>(lv, d)
38 d_.showTexinfo.connect(SigC::slot(this, &ControlTexinfo::show));
41 // build filelists of all availabe bst/cls/sty-files. done through
42 // kpsewhich and an external script, saved in *Files.lst
43 void ControlTexinfo::rescanStyles() const
45 // Run rescan in user lyx directory
47 Systemcalls one(Systemcalls::System,
48 LibFileSearch("scripts", "TeXFiles.sh"));
53 void ControlTexinfo::runTexhash() const
55 // Run texhash in user lyx directory
58 //path to texhash through system
59 Systemcalls one(Systemcalls::System,"texhash");
61 // Alert::alert(_("texhash run!"),
62 // _("rebuilding of the TeX-tree could only be successfull"),
63 // _("if you have had user-write-permissions to the tex-dir."));
69 string const sortEntries(string & str_in)
71 std::vector<string> dbase = getVectorFromString(str_in,"\n");
72 std::sort(dbase.begin(), dbase.end()); // sort entries
73 std::vector<string>::iterator p =
74 std::unique(dbase.begin(), dbase.end()); // compact
75 dbase.erase(p, dbase.end()); // shrink
76 return getStringFromVector(dbase,"\n");
83 ControlTexinfo::getContents(texFileSuffix type, bool withFullPath) const
85 static string const bstFilename("bstFiles.lst");
86 static string const clsFilename("clsFiles.lst");
87 static string const styFilename("styFiles.lst");
92 filename = bstFilename;
95 filename = clsFilename;
98 filename = styFilename;
102 string fileContents = GetFileContents(LibFileSearch(string(),filename));
104 if (!fileContents.empty()) {
106 return(sortEntries(fileContents));
109 string dummy = OnlyFilename(token(fileContents,'\n',1));
110 string contents = dummy;
112 dummy = OnlyFilename(token(fileContents,'\n',++Entries));
113 contents += ("\n"+dummy);
114 } while (!dummy.empty());
115 return(sortEntries(contents));
118 return _("Missing filelist. try Rescan");
121 void ControlTexinfo::viewFile(string const filename) const
123 lv_.getDialogs()->showFile(filename);
127 void ControlTexinfo::help() const
129 lv_.getDialogs()->showFile(i18nLibFileSearch("help","Texinfo.hlp"));