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, _("TeX 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 string file = data[sel-1];
93 if (!fl_get_button(dialog_->check_fullpath))
94 file = getTexFileFromList(data[sel-1],
95 controller().getFileType(activeStyle));
96 if (sel >= 1 && sel <= data.size())
97 controller().viewFile(file);
99 // reset the browser so that the following single-click
100 // callback doesn't do anything
101 fl_deselect_browser(dialog_->browser);
103 } else if (ob == dialog_->button_rescan) {
104 // build new *Files.lst
106 updateStyles(activeStyle);
108 } else if (ob == dialog_->check_fullpath) {
109 updateStyles(activeStyle);
111 } else if (ob == dialog_->choice_classes) {
112 switch (fl_get_choice(dialog_->choice_classes)) {
114 updateStyles(ControlTexinfo::bst);
117 updateStyles(ControlTexinfo::sty);
121 updateStyles(ControlTexinfo::cls);
125 return ButtonPolicy::SMI_VALID;
129 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
131 ContentsType & data = texdata_[whichStyle];
132 bool const withFullPath = fl_get_button(dialog_->check_fullpath);
133 getTexFileList(whichStyle, data, withFullPath);
135 fl_clear_browser(dialog_->browser);
136 ContentsType::const_iterator it = data.begin();
137 ContentsType::const_iterator end = data.end();
138 for (; it != end; ++it)
139 fl_add_browser_line(dialog_->browser, (*it).c_str());
141 activeStyle = whichStyle;
144 } // namespace frontend