]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlTexinfo.C
7ebdbb4b71d41a7263f65c9a45cf33f262f01267
[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         return getStringFromVector(dbase,"\n");
74 }
75
76 } //namespace anon
77
78
79 string const
80 ControlTexinfo::getContents(texFileSuffix type, bool withFullPath) const
81 {
82         static string const bstFilename("bstFiles.lst");
83         static string const clsFilename("clsFiles.lst");
84         static string const styFilename("styFiles.lst");
85
86         string filename;
87         switch (type) {
88         case bst: 
89                 filename = bstFilename;
90                 break;
91         case cls:
92                 filename = clsFilename;
93                 break;
94         case sty:
95                 filename = clsFilename;
96                 break;
97         }
98
99         string fileContents = GetFileContents(LibFileSearch(string(),filename));
100         // everything ok?
101         if (!fileContents.empty()) {
102                 if (withFullPath)
103                         return(sortEntries(fileContents));
104                 else {
105                         int Entries = 1;
106                         string dummy = OnlyFilename(token(fileContents,'\n',1));
107                         string contents = dummy;
108                         do {
109                                 dummy = OnlyFilename(token(fileContents,'\n',++Entries));
110                                 contents += ("\n"+dummy);
111                         } while (!dummy.empty());
112                         return(sortEntries(contents));
113                 }
114         } else
115                 return _("Missing filelist. try Rescan");
116 }
117
118 void ControlTexinfo::viewFile(string const filename) const
119 {
120         lv_.getDialogs()->showFile(filename);
121 }
122
123
124 void ControlTexinfo::help() const
125 {
126         lv_.getDialogs()->showFile(i18nLibFileSearch("help","Texinfo.hlp"));
127 }