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
15 #include "FormTexinfo.h"
16 #include "forms/form_texinfo.h"
19 #include "xforms_helpers.h"
20 #include "support/LAssert.h"
21 #include "support/lstrings.h"
22 #include "support/filetools.h"
24 #include "lyx_forms.h"
26 using namespace lyx::support;
28 typedef FormController<ControlTexinfo, FormView<FD_texinfo> > base_class;
30 FormTexinfo::FormTexinfo(Dialog & parent)
31 : base_class(parent, _("LaTeX Information")),
32 activeStyle(ControlTexinfo::cls)
36 void FormTexinfo::build() {
37 dialog_.reset(build_texinfo(this));
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);
43 string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
44 fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
46 updateStyles(activeStyle);
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);
53 str = _("Show full path or only file name.");
54 tooltips().init(dialog_->check_fullpath, str);
56 str = _("Runs the script \"TexFiles.sh\" to build new file lists.");
57 tooltips().init(dialog_->button_rescan, str);
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);
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)
79 // texhash requires a rescan and an update of the styles
81 updateStyles(activeStyle);
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]);
91 // reset the browser so that the following single-click
92 // callback doesn't do anything
93 fl_deselect_browser(dialog_->browser);
95 } else if (ob == dialog_->button_rescan) {
96 // build new *Files.lst
98 updateStyles(activeStyle);
100 } else if (ob == dialog_->check_fullpath) {
101 updateStyles(activeStyle);
103 } else if (ob == dialog_->choice_classes) {
104 switch (fl_get_choice(dialog_->choice_classes)) {
106 updateStyles(ControlTexinfo::bst);
109 updateStyles(ControlTexinfo::sty);
113 updateStyles(ControlTexinfo::cls);
117 return ButtonPolicy::SMI_VALID;
121 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
123 ContentsType & data = texdata_[whichStyle];
124 getTexFileList(whichStyle, data);
126 bool const withFullPath = fl_get_button(dialog_->check_fullpath);
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());
136 activeStyle = whichStyle;