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.
13 #include "FormTexinfo.h"
14 #include "forms/form_texinfo.h"
19 #include "support/filetools.h"
21 #include "lyx_forms.h"
27 using support::OnlyFilename;
32 typedef FormController<ControlTexinfo, FormView<FD_texinfo> > base_class;
34 FormTexinfo::FormTexinfo(Dialog & parent)
35 : base_class(parent, _("LaTeX Information")),
36 activeStyle(ControlTexinfo::cls)
40 void FormTexinfo::build() {
41 dialog_.reset(build_texinfo(this));
43 // callback for double click in browser to view the selected file
44 fl_set_browser_dblclick_callback(dialog_->browser,
45 C_FormDialogView_InputCB, 2);
47 string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
48 fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
50 updateStyles(activeStyle);
52 // set up the tooltips
53 string str = _("Shows the installed classses and styles for LaTeX/BibTeX; "
54 "available only if the corresponding LyX layout file exists.");
55 tooltips().init(dialog_->choice_classes, str);
57 str = _("Show full path or only file name.");
58 tooltips().init(dialog_->check_fullpath, str);
60 str = _("Runs the script \"TexFiles.sh\" to rebuild the file lists.");
61 tooltips().init(dialog_->button_rescan, str);
63 str = _("Double click to view contents of file.");
64 tooltips().init(dialog_->browser, str);
65 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
66 // Work-around xforms' bug; enable tooltips for browser widgets.
67 setPrehandler(dialog_->browser);
70 str = _("Runs the script \"texhash\" which builds a new LaTeX tree. "
71 "Needed if you install a new TeX class or style. You need write "
72 "permissions for the TeX-dirs, often /var/lib/texmf and others.");
73 tooltips().init(dialog_->button_texhash, str);
77 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
79 if (ob == dialog_->button_texhash) {
80 // makes only sense if the rights are set well for
81 // users (/var/lib/texmf/ls-R)
83 // texhash requires a rescan and an update of the styles
85 updateStyles(activeStyle);
88 } else if (ob == dialog_->browser && ob_value == 2) {
89 // double click in browser: view selected file
90 ContentsType::size_type const sel = fl_get_browser(ob);
91 ContentsType const & data = texdata_[activeStyle];
92 if (sel >= 1 && sel <= data.size())
93 controller().viewFile(data[sel-1]);
95 // reset the browser so that the following single-click
96 // callback doesn't do anything
97 fl_deselect_browser(dialog_->browser);
99 } else if (ob == dialog_->button_rescan) {
100 // build new *Files.lst
102 updateStyles(activeStyle);
104 } else if (ob == dialog_->check_fullpath) {
105 updateStyles(activeStyle);
107 } else if (ob == dialog_->choice_classes) {
108 switch (fl_get_choice(dialog_->choice_classes)) {
110 updateStyles(ControlTexinfo::bst);
113 updateStyles(ControlTexinfo::sty);
117 updateStyles(ControlTexinfo::cls);
121 return ButtonPolicy::SMI_VALID;
125 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
127 ContentsType & data = texdata_[whichStyle];
128 getTexFileList(whichStyle, data);
130 bool const withFullPath = fl_get_button(dialog_->check_fullpath);
132 fl_clear_browser(dialog_->browser);
133 ContentsType::const_iterator it = data.begin();
134 ContentsType::const_iterator end = data.end();
135 for (; it != end; ++it) {
136 string const line = withFullPath ? *it : OnlyFilename(*it);
137 fl_add_browser_line(dialog_->browser, line.c_str());
140 activeStyle = whichStyle;
143 } // namespace frontend