]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTexinfo.C
ws changes
[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         // Work-around xforms' bug; enable tooltips for browser widgets.
64         setPrehandler(dialog_->browser);
65
66         str = _("Runs the script \"texhash\" which builds a new LaTeX tree. "
67                 "Needed if you install a new TeX class or style. You need write "
68                 "permissions for the TeX-dirs, often /var/lib/texmf and others.");
69         tooltips().init(dialog_->button_texhash, str);
70 }
71
72
73 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
74
75         if (ob == dialog_->button_texhash) {
76                 // makes only sense if the rights are set well for
77                 // users (/var/lib/texmf/ls-R)
78                 controller().runTexhash();
79                 // texhash requires a rescan and an update of the styles
80                 controller().rescanStyles();
81                 updateStyles(activeStyle);
82
83
84         } else if (ob == dialog_->browser && ob_value == 2) {
85                 // double click in browser: view selected file
86                 string selection = string();
87                 if (fl_get_button(dialog_->check_fullpath)) {
88                         // contents in browser has full path
89                         selection = getString(dialog_->browser);
90                 } else {
91                         // contents in browser has filenames without path
92                         // reconstruct path from controller getContents
93                         string const files = controller().getContents(activeStyle, true);
94                         vector<string> const vec = getVectorFromString(files, "\n");
95
96                         // find line in files vector
97                         vector<string>::const_iterator it = vec.begin();
98                         int const line = fl_get_browser(dialog_->browser);
99                         for (int i = line; it != vec.end() && i > 0; ++it, --i) {
100                                 if (i == 1) selection = *it;
101                         }
102                 }
103
104                 if (!selection.empty()) {
105                         controller().viewFile(selection);
106                 }
107
108                 // reset the browser so that the following single-click callback doesn't do anything
109                 fl_deselect_browser(dialog_->browser);
110
111         } else if (ob == dialog_->button_rescan) {
112                 // build new *Files.lst
113                 controller().rescanStyles();
114                 updateStyles(activeStyle);
115
116         } else if (ob == dialog_->check_fullpath) {
117                 updateStyles(activeStyle);
118
119         } else if (ob == dialog_->choice_classes) {
120                 switch (fl_get_choice(dialog_->choice_classes)) {
121                 case 3:
122                         updateStyles(ControlTexinfo::bst);
123                         break;
124                 case 2:
125                         updateStyles(ControlTexinfo::sty);
126                         break;
127                 case 1:
128                 default:
129                         updateStyles(ControlTexinfo::cls);
130                 }
131         }
132
133         return ButtonPolicy::SMI_VALID;
134 }
135
136
137 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
138 {
139         fl_clear_browser(dialog_->browser);
140
141         bool const withFullPath = fl_get_button(dialog_->check_fullpath);
142
143         string const str =
144                 controller().getContents(whichStyle, withFullPath);
145         fl_add_browser_line(dialog_->browser, str.c_str());
146
147         activeStyle = whichStyle;
148 }