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