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 typedef FormController<ControlTexinfo, FormView<FD_texinfo> > base_class;
28 FormTexinfo::FormTexinfo(Dialog & parent)
29 : base_class(parent, _("LaTeX Information")),
30 activeStyle(ControlTexinfo::cls)
34 void FormTexinfo::build() {
35 dialog_.reset(build_texinfo(this));
37 // callback for double click in browser to view the selected file
38 fl_set_browser_dblclick_callback(dialog_->browser,
39 C_FormDialogView_InputCB, 2);
41 string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
42 fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
44 updateStyles(activeStyle);
46 // set up the tooltips
47 string str = _("Shows the installed classses and styles for LaTeX/BibTeX; "
48 "available only if the corresponding LyX layout file exists.");
49 tooltips().init(dialog_->choice_classes, str);
51 str = _("Show full path or only file name.");
52 tooltips().init(dialog_->check_fullpath, str);
54 str = _("Runs the script \"TexFiles.sh\" to build new file lists.");
55 tooltips().init(dialog_->button_rescan, str);
57 str = _("Double click to view contents of file.");
58 tooltips().init(dialog_->browser, str);
59 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
60 // Work-around xforms' bug; enable tooltips for browser widgets.
61 setPrehandler(dialog_->browser);
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)
77 // texhash requires a rescan and an update of the styles
79 updateStyles(activeStyle);
82 } else if (ob == dialog_->browser && ob_value == 2) {
83 // double click in browser: view selected file
84 ContentsType::size_type const sel = fl_get_browser(ob);
85 ContentsType const & data = texdata_[activeStyle];
86 if (sel >= 1 && sel <= data.size())
87 controller().viewFile(data[sel-1]);
89 // reset the browser so that the following single-click
90 // callback doesn't do anything
91 fl_deselect_browser(dialog_->browser);
93 } else if (ob == dialog_->button_rescan) {
94 // build new *Files.lst
96 updateStyles(activeStyle);
98 } else if (ob == dialog_->check_fullpath) {
99 updateStyles(activeStyle);
101 } else if (ob == dialog_->choice_classes) {
102 switch (fl_get_choice(dialog_->choice_classes)) {
104 updateStyles(ControlTexinfo::bst);
107 updateStyles(ControlTexinfo::sty);
111 updateStyles(ControlTexinfo::cls);
115 return ButtonPolicy::SMI_VALID;
119 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
121 ContentsType & data = texdata_[whichStyle];
122 getTexFileList(whichStyle, data);
124 bool const withFullPath = fl_get_button(dialog_->check_fullpath);
126 fl_clear_browser(dialog_->browser);
127 ContentsType::const_iterator it = data.begin();
128 ContentsType::const_iterator end = data.end();
129 for (; it != end; ++it) {
130 string const line = withFullPath ? *it : OnlyFilename(*it);
131 fl_add_browser_line(dialog_->browser, line.c_str());
134 activeStyle = whichStyle;