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
14 #include "FormTexinfo.h"
15 #include "forms/form_texinfo.h"
18 #include "xforms_helpers.h"
19 #include "support/LAssert.h"
20 #include "support/lstrings.h"
21 #include "support/filetools.h"
23 #include "lyx_forms.h"
25 using namespace lyx::support;
27 typedef FormController<ControlTexinfo, FormView<FD_texinfo> > base_class;
29 FormTexinfo::FormTexinfo(Dialog & parent)
30 : base_class(parent, _("LaTeX Information")),
31 activeStyle(ControlTexinfo::cls)
35 void FormTexinfo::build() {
36 dialog_.reset(build_texinfo(this));
38 // callback for double click in browser to view the selected file
39 fl_set_browser_dblclick_callback(dialog_->browser,
40 C_FormDialogView_InputCB, 2);
42 string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
43 fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
45 updateStyles(activeStyle);
47 // set up the tooltips
48 string str = _("Shows the installed classses and styles for LaTeX/BibTeX; "
49 "available only if the corresponding LyX layout file exists.");
50 tooltips().init(dialog_->choice_classes, str);
52 str = _("Show full path or only file name.");
53 tooltips().init(dialog_->check_fullpath, str);
55 str = _("Runs the script \"TexFiles.sh\" to build new file lists.");
56 tooltips().init(dialog_->button_rescan, str);
58 str = _("Double click to view contents of file.");
59 tooltips().init(dialog_->browser, str);
60 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
61 // Work-around xforms' bug; enable tooltips for browser widgets.
62 setPrehandler(dialog_->browser);
65 str = _("Runs the script \"texhash\" which builds a new LaTeX tree. "
66 "Needed if you install a new TeX class or style. You need write "
67 "permissions for the TeX-dirs, often /var/lib/texmf and others.");
68 tooltips().init(dialog_->button_texhash, str);
72 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
74 if (ob == dialog_->button_texhash) {
75 // makes only sense if the rights are set well for
76 // users (/var/lib/texmf/ls-R)
78 // texhash requires a rescan and an update of the styles
80 updateStyles(activeStyle);
83 } else if (ob == dialog_->browser && ob_value == 2) {
84 // double click in browser: view selected file
85 ContentsType::size_type const sel = fl_get_browser(ob);
86 ContentsType const & data = texdata_[activeStyle];
87 if (sel >= 1 && sel <= data.size())
88 controller().viewFile(data[sel-1]);
90 // reset the browser so that the following single-click
91 // callback doesn't do anything
92 fl_deselect_browser(dialog_->browser);
94 } else if (ob == dialog_->button_rescan) {
95 // build new *Files.lst
97 updateStyles(activeStyle);
99 } else if (ob == dialog_->check_fullpath) {
100 updateStyles(activeStyle);
102 } else if (ob == dialog_->choice_classes) {
103 switch (fl_get_choice(dialog_->choice_classes)) {
105 updateStyles(ControlTexinfo::bst);
108 updateStyles(ControlTexinfo::sty);
112 updateStyles(ControlTexinfo::cls);
116 return ButtonPolicy::SMI_VALID;
120 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
122 ContentsType & data = texdata_[whichStyle];
123 getTexFileList(whichStyle, data);
125 bool const withFullPath = fl_get_button(dialog_->check_fullpath);
127 fl_clear_browser(dialog_->browser);
128 ContentsType::const_iterator it = data.begin();
129 ContentsType::const_iterator end = data.end();
130 for (; it != end; ++it) {
131 string const line = withFullPath ? *it : OnlyFilename(*it);
132 fl_add_browser_line(dialog_->browser, line.c_str());
135 activeStyle = whichStyle;