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"
30 typedef FormController<ControlTexinfo, FormView<FD_texinfo> > base_class;
32 FormTexinfo::FormTexinfo(Dialog & parent)
33 : base_class(parent, _("TeX Information")),
34 activeStyle(ControlTexinfo::cls)
38 void FormTexinfo::build() {
39 dialog_.reset(build_texinfo(this));
41 // callback for double click in browser to view the selected file
42 fl_set_browser_dblclick_callback(dialog_->browser,
43 C_FormDialogView_InputCB, 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 rebuild the file lists.");
59 tooltips().init(dialog_->button_rescan, str);
61 str = _("Double click to view contents of file.");
62 tooltips().init(dialog_->browser, str);
63 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
64 // Work-around xforms' bug; enable tooltips for browser widgets.
65 setPrehandler(dialog_->browser);
68 str = _("Runs the script \"texhash\" which builds a new LaTeX tree. "
69 "Needed if you install a new TeX class or style. You need write "
70 "permissions for the TeX-dirs, often /var/lib/texmf and others.");
71 tooltips().init(dialog_->button_texhash, str);
75 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
77 if (ob == dialog_->button_texhash) {
78 // makes only sense if the rights are set well for
79 // users (/var/lib/texmf/ls-R)
81 // texhash requires a rescan and an update of the styles
83 updateStyles(activeStyle);
86 } else if (ob == dialog_->browser && ob_value == 2) {
87 // double click in browser: view selected file
88 ContentsType::size_type const sel = fl_get_browser(ob);
89 ContentsType const & data = texdata_[activeStyle];
90 string file = data[sel-1];
91 if (!fl_get_button(dialog_->check_fullpath))
92 file = getTexFileFromList(data[sel-1],
93 controller().getFileType(activeStyle));
94 if (sel >= 1 && sel <= data.size())
95 controller().viewFile(file);
97 // reset the browser so that the following single-click
98 // callback doesn't do anything
99 fl_deselect_browser(dialog_->browser);
101 } else if (ob == dialog_->button_rescan) {
102 // build new *Files.lst
104 updateStyles(activeStyle);
106 } else if (ob == dialog_->check_fullpath) {
107 updateStyles(activeStyle);
109 } else if (ob == dialog_->choice_classes) {
110 switch (fl_get_choice(dialog_->choice_classes)) {
112 updateStyles(ControlTexinfo::bst);
115 updateStyles(ControlTexinfo::sty);
119 updateStyles(ControlTexinfo::cls);
123 return ButtonPolicy::SMI_VALID;
127 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
129 ContentsType & data = texdata_[whichStyle];
130 bool const withFullPath = fl_get_button(dialog_->check_fullpath);
131 getTexFileList(whichStyle, data, withFullPath);
133 fl_clear_browser(dialog_->browser);
134 ContentsType::const_iterator it = data.begin();
135 ContentsType::const_iterator end = data.end();
136 for (; it != end; ++it)
137 fl_add_browser_line(dialog_->browser, (*it).c_str());
139 activeStyle = whichStyle;
142 } // namespace frontend