]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlTexinfo.C
5dccb1afbd7f43511ab2f40d0ad2409371751902
[lyx.git] / src / frontends / controllers / ControlTexinfo.C
1 /* This file is part of
2  * ====================================================== 
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2001 The LyX Team.
7  *
8  * ======================================================
9  *
10  * \file ControlTexinfo.C
11  * \author Herbert Voss <voss@lyx.org>
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "ViewBase.h"
21 #include "ButtonControllerBase.h"
22 #include "ControlTexinfo.h"
23 #include "Dialogs.h"
24 #include "LyXView.h"
25 #include "BufferView.h"
26 #include "gettext.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"
32
33 extern string user_lyxdir; // home of *Files.lst
34
35 ControlTexinfo::ControlTexinfo(LyXView & lv, Dialogs & d)
36                         : ControlDialog<ControlConnectBI>(lv, d)
37 {
38         d_.showTexinfo.connect(SigC::slot(this, &ControlTexinfo::show));
39 }
40
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
44 {
45         // Run rescan in user lyx directory
46         Path p(user_lyxdir);
47         Systemcalls one(Systemcalls::System,
48                         LibFileSearch("scripts", "TeXFiles.sh"));
49         p.pop();
50 }
51
52
53 void ControlTexinfo::runTexhash() const
54 {
55         // Run texhash in user lyx directory
56         Path p(user_lyxdir);
57
58         //path to texhash through system
59         Systemcalls one(Systemcalls::System,"texhash"); 
60         p.pop();
61 //      WriteAlert(_("texhash run!"), 
62 //                 _("rebuilding of the TeX-tree could only be successfull"),
63 //                 _("if you have had user-write-permissions to the tex-dir."));
64 }
65
66
67 namespace {
68
69 string const sortEntries(string & str_in)
70 {
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");
77 }
78
79 } //namespace anon
80
81
82 string const
83 ControlTexinfo::getContents(texFileSuffix type, bool withFullPath) const
84 {
85         static string const bstFilename("bstFiles.lst");
86         static string const clsFilename("clsFiles.lst");
87         static string const styFilename("styFiles.lst");
88
89         string filename;
90         switch (type) {
91         case bst: 
92                 filename = bstFilename;
93                 break;
94         case cls:
95                 filename = clsFilename;
96                 break;
97         case sty:
98                 filename = styFilename;
99                 break;
100         }
101
102         string fileContents = GetFileContents(LibFileSearch(string(),filename));
103         // everything ok?
104         if (!fileContents.empty()) {
105                 if (withFullPath)
106                         return(sortEntries(fileContents));
107                 else {
108                         int Entries = 1;
109                         string dummy = OnlyFilename(token(fileContents,'\n',1));
110                         string contents = dummy;
111                         do {
112                                 dummy = OnlyFilename(token(fileContents,'\n',++Entries));
113                                 contents += ("\n"+dummy);
114                         } while (!dummy.empty());
115                         return(sortEntries(contents));
116                 }
117         } else
118                 return _("Missing filelist. try Rescan");
119 }
120
121 void ControlTexinfo::viewFile(string const filename) const
122 {
123         lv_.getDialogs()->showFile(filename);
124 }
125
126
127 void ControlTexinfo::help() const
128 {
129         lv_.getDialogs()->showFile(i18nLibFileSearch("help","Texinfo.hlp"));
130 }