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