]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTexinfo.C
dont use pragma impementation and interface anymore
[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 = string();
84                 if (fl_get_button(dialog_->check_fullpath)) {
85                         // contents in browser has full path
86                         selection = getString(dialog_->browser);
87                 } else {
88                         // contents in browser has filenames without path
89                         // reconstruct path from controller getContents
90                         string const files = controller().getContents(activeStyle, true);
91                         vector<string> const vec = getVectorFromString(files, "\n");
92
93                         // find line in files vector
94                         vector<string>::const_iterator it = vec.begin();
95                         int const line = fl_get_browser(dialog_->browser);
96                         for (int i = line; it != vec.end() && i > 0; ++it, --i) {
97                                 if (i == 1) selection = *it;
98                         }
99                 }
100
101                 if (!selection.empty()) {
102                         controller().viewFile(selection);
103                 }
104
105                 // reset the browser so that the following single-click callback doesn't do anything
106                 fl_deselect_browser(dialog_->browser);
107
108         } else if (ob == dialog_->button_rescan) {
109                 // build new *Files.lst
110                 controller().rescanStyles();
111                 updateStyles(activeStyle);
112
113         } else if (ob == dialog_->check_fullpath) {
114                 updateStyles(activeStyle);
115
116         } else if (ob == dialog_->choice_classes) {
117                 switch (fl_get_choice(dialog_->choice_classes)) {
118                 case 3:
119                         updateStyles(ControlTexinfo::bst);
120                         break;
121                 case 2:
122                         updateStyles(ControlTexinfo::sty);
123                         break;
124                 case 1:
125                 default:
126                         updateStyles(ControlTexinfo::cls);
127                 }
128         }
129
130         return ButtonPolicy::SMI_VALID;
131 }
132
133
134 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
135 {
136         fl_clear_browser(dialog_->browser);
137
138         bool const withFullPath = fl_get_button(dialog_->check_fullpath);
139
140         string const str =
141                 controller().getContents(whichStyle, withFullPath);
142         fl_add_browser_line(dialog_->browser, str.c_str());
143
144         activeStyle = whichStyle;
145 }