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);
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);
71 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
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 controller().runTexhash();
77 // texhash requires a rescan and an update of the styles
78 controller().rescanStyles();
79 updateStyles(activeStyle);
82 } else if (ob == dialog_->browser && ob_value == 2) {
83 // double click in browser: view selected file
84 string selection = string();
85 if (fl_get_button(dialog_->check_fullpath)) {
86 // contents in browser has full path
87 selection = getString(dialog_->browser);
89 // contents in browser has filenames without path
90 // reconstruct path from controller getContents
91 string const files = controller().getContents(activeStyle, true);
92 vector<string> const vec = getVectorFromString(files, "\n");
94 // find line in files vector
95 vector<string>::const_iterator it = vec.begin();
96 int const line = fl_get_browser(dialog_->browser);
97 for (int i = line; it != vec.end() && i > 0; ++it, --i) {
98 if (i == 1) selection = *it;
102 if (!selection.empty()) {
103 controller().viewFile(selection);
106 // reset the browser so that the following single-click callback doesn't do anything
107 fl_deselect_browser(dialog_->browser);
109 } else if (ob == dialog_->button_rescan) {
110 // build new *Files.lst
111 controller().rescanStyles();
112 updateStyles(activeStyle);
114 } else if (ob == dialog_->check_fullpath) {
115 updateStyles(activeStyle);
117 } else if (ob == dialog_->choice_classes) {
118 switch (fl_get_choice(dialog_->choice_classes)) {
120 updateStyles(ControlTexinfo::bst);
123 updateStyles(ControlTexinfo::sty);
127 updateStyles(ControlTexinfo::cls);
131 return ButtonPolicy::SMI_VALID;
135 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
137 fl_clear_browser(dialog_->browser);
139 bool const withFullPath = fl_get_button(dialog_->check_fullpath);
142 controller().getContents(whichStyle, withFullPath);
143 fl_add_browser_line(dialog_->browser, str.c_str());
145 activeStyle = whichStyle;