]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlTexinfo.C
guii2
[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 "frontends/LyXView.h"
25 #include "BufferView.h"
26 #include "gettext.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"
32
33 extern string user_lyxdir; // home of *Files.lst
34
35
36 ControlTexinfo::ControlTexinfo(LyXView & lv, Dialogs & d)
37         : ControlDialogBI(lv, d)
38 {
39         d_.showTexinfo.connect(SigC::slot(this, &ControlTexinfo::show));
40 }
41
42
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
46 {
47         // Run rescan in user lyx directory
48         Path p(user_lyxdir);
49         Systemcall one;
50         one.startscript(Systemcall::Wait,
51                         LibFileSearch("scripts", "TeXFiles.sh"));
52         p.pop();
53 }
54
55
56 void ControlTexinfo::runTexhash() const
57 {
58         // Run texhash in user lyx directory
59         Path p(user_lyxdir);
60
61         //path to texhash through system
62         Systemcall one;
63         one.startscript(Systemcall::Wait, "texhash");
64
65         p.pop();
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."));
69 }
70
71
72 namespace {
73
74 string const sortEntries(string & str_in)
75 {
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");
82 }
83
84 } //namespace anon
85
86
87 string const
88 ControlTexinfo::getContents(texFileSuffix type, bool withFullPath) const
89 {
90         static string const bstFilename("bstFiles.lst");
91         static string const clsFilename("clsFiles.lst");
92         static string const styFilename("styFiles.lst");
93
94         string filename;
95         switch (type) {
96         case bst:
97                 filename = bstFilename;
98                 break;
99         case cls:
100                 filename = clsFilename;
101                 break;
102         case sty:
103                 filename = styFilename;
104                 break;
105         }
106
107         string fileContents = GetFileContents(LibFileSearch(string(),filename));
108         // everything ok?
109         if (!fileContents.empty()) {
110                 if (withFullPath)
111                         return(sortEntries(fileContents));
112                 else {
113                         int Entries = 1;
114                         string dummy = OnlyFilename(token(fileContents,'\n',1));
115                         string contents = dummy;
116                         do {
117                                 dummy = OnlyFilename(token(fileContents,'\n',++Entries));
118                                 contents += ("\n"+dummy);
119                         } while (!dummy.empty());
120                         return(sortEntries(contents));
121                 }
122         } else
123                 return _("Missing filelist. try Rescan");
124 }
125
126 void ControlTexinfo::viewFile(string const filename) const
127 {
128         lv_.getDialogs()->showFile(filename);
129 }