]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTexinfo.C
Introduce LFUN_PRINT.
[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 lyx::support::OnlyFilename;
24
25 using std::string;
26
27
28 typedef FormController<ControlTexinfo, FormView<FD_texinfo> > base_class;
29
30 FormTexinfo::FormTexinfo(Dialog & parent)
31         : base_class(parent, _("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,
41                                          C_FormDialogView_InputCB, 2);
42
43         string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
44         fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
45
46         updateStyles(activeStyle);
47
48         // set up the tooltips
49         string str = _("Shows the installed classses and styles for LaTeX/BibTeX; "
50                         "available only if the corresponding LyX layout file exists.");
51         tooltips().init(dialog_->choice_classes, str);
52
53         str = _("Show full path or only file name.");
54         tooltips().init(dialog_->check_fullpath, str);
55
56         str = _("Runs the script \"TexFiles.sh\" to build new file lists.");
57         tooltips().init(dialog_->button_rescan, str);
58
59         str = _("Double click to view contents of file.");
60         tooltips().init(dialog_->browser, str);
61 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
62         // Work-around xforms' bug; enable tooltips for browser widgets.
63         setPrehandler(dialog_->browser);
64 #endif
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                 texhash();
79                 // texhash requires a rescan and an update of the styles
80                 rescanTexStyles();
81                 updateStyles(activeStyle);
82
83
84         } else if (ob == dialog_->browser && ob_value == 2) {
85                 // double click in browser: view selected file
86                 ContentsType::size_type const sel = fl_get_browser(ob);
87                 ContentsType const & data = texdata_[activeStyle];
88                 if (sel >= 1 && sel <= data.size())
89                         controller().viewFile(data[sel-1]);
90
91                 // reset the browser so that the following single-click
92                 // callback doesn't do anything
93                 fl_deselect_browser(dialog_->browser);
94
95         } else if (ob == dialog_->button_rescan) {
96                 // build new *Files.lst
97                 rescanTexStyles();
98                 updateStyles(activeStyle);
99
100         } else if (ob == dialog_->check_fullpath) {
101                 updateStyles(activeStyle);
102
103         } else if (ob == dialog_->choice_classes) {
104                 switch (fl_get_choice(dialog_->choice_classes)) {
105                 case 3:
106                         updateStyles(ControlTexinfo::bst);
107                         break;
108                 case 2:
109                         updateStyles(ControlTexinfo::sty);
110                         break;
111                 case 1:
112                 default:
113                         updateStyles(ControlTexinfo::cls);
114                 }
115         }
116
117         return ButtonPolicy::SMI_VALID;
118 }
119
120
121 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
122 {
123         ContentsType & data = texdata_[whichStyle];
124         getTexFileList(whichStyle, data);
125
126         bool const withFullPath = fl_get_button(dialog_->check_fullpath);
127
128         fl_clear_browser(dialog_->browser);
129         ContentsType::const_iterator it  = data.begin();
130         ContentsType::const_iterator end = data.end();
131         for (; it != end; ++it) {
132                 string const line = withFullPath ? *it : OnlyFilename(*it);
133                 fl_add_browser_line(dialog_->browser, line.c_str());
134         }
135
136         activeStyle = whichStyle;
137 }