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