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