]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTexinfo.C
using std::vector
[lyx.git] / src / frontends / xforms / FormTexinfo.C
1 /**
2  * \file FormTexinfo.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Herbert Voss
7  *
8  * Full author contact details are available in file CREDITS
9  * \date 2001-10-01
10  */
11
12 #include <config.h>
13 #include <fstream>
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include "xformsBC.h"
20 #include "FormTexinfo.h"
21 #include "forms/form_texinfo.h"
22 #include "Tooltips.h"
23 #include "gettext.h"
24 #include "xforms_helpers.h"
25 #include "support/LAssert.h"
26 #include "support/lstrings.h"
27
28 #include FORMS_H_LOCATION
29
30 using std::vector;
31
32 typedef FormCB<ControlTexinfo, FormDB<FD_texinfo> > base_class;
33 FormTexinfo::FormTexinfo()
34         : base_class(_("LaTeX Information")),
35           activeStyle(ControlTexinfo::cls)
36 {}
37
38
39 void FormTexinfo::build() {
40         dialog_.reset(build_texinfo(this));
41
42         // callback for double click in browser to view the selected file
43         fl_set_browser_dblclick_callback(dialog_->browser, C_FormBaseInputCB, 2);
44
45         string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
46         fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
47
48         updateStyles(activeStyle);
49
50         // set up the tooltips
51         string str = _("Shows the installed classses and styles for LaTeX/BibTeX; "
52                         "available only if the corresponding LyX layout file exists.");
53         tooltips().init(dialog_->choice_classes, str);
54
55         str = _("Show full path or only file name.");
56         tooltips().init(dialog_->check_fullpath, str);
57
58         str = _("Runs the script \"TexFiles.sh\" to build new file lists.");
59         tooltips().init(dialog_->button_rescan, str);
60
61         str = _("Double click to view contents of file.");
62         tooltips().init(dialog_->browser, str);
63
64         str = _("Runs the script \"texhash\" which builds a new LaTeX tree. "
65                 "Needed if you install a new TeX class or style. You need write "
66                 "permissions for the TeX-dirs, often /var/lib/texmf and others.");
67         tooltips().init(dialog_->button_texhash, str);
68 }
69
70
71 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
72
73         if (ob == dialog_->button_texhash) {
74                 // makes only sense if the rights are set well for
75                 // users (/var/lib/texmf/ls-R)
76                 controller().runTexhash();
77                 // texhash requires a rescan and an update of the styles
78                 controller().rescanStyles();
79                 updateStyles(activeStyle);
80
81
82         } else if (ob == dialog_->browser && ob_value == 2) {
83                 // double click in browser: view selected file
84                 string selection = string();
85                 if (fl_get_button(dialog_->check_fullpath)) {
86                         // contents in browser has full path
87                         selection = getString(dialog_->browser);
88                 } else {
89                         // contents in browser has filenames without path
90                         // reconstruct path from controller getContents
91                         string const files = controller().getContents(activeStyle, true);
92                         vector<string> const vec = getVectorFromString(files, "\n");
93
94                         // find line in files vector
95                         vector<string>::const_iterator it = vec.begin();
96                         int const line = fl_get_browser(dialog_->browser);
97                         for (int i = line; it != vec.end() && i > 0; ++it, --i) {
98                                 if (i == 1) selection = *it;
99                         }
100                 }
101
102                 if (!selection.empty()) {
103                         controller().viewFile(selection);
104                 }
105
106                 // reset the browser so that the following single-click callback doesn't do anything
107                 fl_deselect_browser(dialog_->browser);
108                 
109         } else if (ob == dialog_->button_rescan) {
110                 // build new *Files.lst
111                 controller().rescanStyles();
112                 updateStyles(activeStyle);
113
114         } else if (ob == dialog_->check_fullpath) {
115                 updateStyles(activeStyle);
116
117         } else if (ob == dialog_->choice_classes) {
118                 switch (fl_get_choice(dialog_->choice_classes)) {
119                 case 3:
120                         updateStyles(ControlTexinfo::bst);
121                         break;
122                 case 2:
123                         updateStyles(ControlTexinfo::sty);
124                         break;
125                 case 1:
126                 default:
127                         updateStyles(ControlTexinfo::cls);
128                 }
129         }
130
131         return ButtonPolicy::SMI_VALID;
132 }
133
134
135 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
136 {
137         fl_clear_browser(dialog_->browser);
138
139         bool const withFullPath = fl_get_button(dialog_->check_fullpath);
140
141         string const str =
142                 controller().getContents(whichStyle, withFullPath);
143         fl_add_browser_line(dialog_->browser, str.c_str());
144
145         activeStyle = whichStyle;
146 }