3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
16 #pragma implementation
20 #include "FormTexinfo.h"
21 #include "forms/form_texinfo.h"
24 #include "xforms_helpers.h"
25 #include "support/LAssert.h"
26 #include "support/lstrings.h"
28 #include FORMS_H_LOCATION
32 typedef FormCB<ControlTexinfo, FormDB<FD_texinfo> > base_class;
33 FormTexinfo::FormTexinfo()
34 : base_class(_("LaTeX Information")),
35 activeStyle(ControlTexinfo::cls)
39 void FormTexinfo::build() {
40 dialog_.reset(build_texinfo(this));
42 // callback for double click in browser to view the selected file
43 fl_set_browser_dblclick_callback(dialog_->browser, C_FormBaseInputCB, 2);
45 string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
46 fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
48 updateStyles(activeStyle);
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);
55 str = _("Show full path or only file name.");
56 tooltips().init(dialog_->check_fullpath, str);
58 str = _("Runs the script \"TexFiles.sh\" to build new file lists.");
59 tooltips().init(dialog_->button_rescan, str);
61 str = _("Double click to view contents of file.");
62 tooltips().init(dialog_->browser, str);
63 // Work-around xforms' bug; enable tooltips for browser widgets.
64 setPrehandler(dialog_->browser);
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);
73 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
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 controller().runTexhash();
79 // texhash requires a rescan and an update of the styles
80 controller().rescanStyles();
81 updateStyles(activeStyle);
84 } else if (ob == dialog_->browser && ob_value == 2) {
85 // double click in browser: view selected file
86 string selection = string();
87 if (fl_get_button(dialog_->check_fullpath)) {
88 // contents in browser has full path
89 selection = getString(dialog_->browser);
91 // contents in browser has filenames without path
92 // reconstruct path from controller getContents
93 string const files = controller().getContents(activeStyle, true);
94 vector<string> const vec = getVectorFromString(files, "\n");
96 // find line in files vector
97 vector<string>::const_iterator it = vec.begin();
98 int const line = fl_get_browser(dialog_->browser);
99 for (int i = line; it != vec.end() && i > 0; ++it, --i) {
100 if (i == 1) selection = *it;
104 if (!selection.empty()) {
105 controller().viewFile(selection);
108 // reset the browser so that the following single-click callback doesn't do anything
109 fl_deselect_browser(dialog_->browser);
111 } else if (ob == dialog_->button_rescan) {
112 // build new *Files.lst
113 controller().rescanStyles();
114 updateStyles(activeStyle);
116 } else if (ob == dialog_->check_fullpath) {
117 updateStyles(activeStyle);
119 } else if (ob == dialog_->choice_classes) {
120 switch (fl_get_choice(dialog_->choice_classes)) {
122 updateStyles(ControlTexinfo::bst);
125 updateStyles(ControlTexinfo::sty);
129 updateStyles(ControlTexinfo::cls);
133 return ButtonPolicy::SMI_VALID;
137 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
139 fl_clear_browser(dialog_->browser);
141 bool const withFullPath = fl_get_button(dialog_->check_fullpath);
144 controller().getContents(whichStyle, withFullPath);
145 fl_add_browser_line(dialog_->browser, str.c_str());
147 activeStyle = whichStyle;