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