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
17 #include "FormTexinfo.h"
18 #include "forms/form_texinfo.h"
21 #include "xforms_helpers.h"
22 #include "support/LAssert.h"
23 #include "support/lstrings.h"
25 #include "lyx_forms.h"
29 typedef FormController<ControlTexinfo, FormView<FD_texinfo> > base_class;
31 FormTexinfo::FormTexinfo(Dialog & parent)
32 : base_class(parent, _("LaTeX Information")),
33 activeStyle(ControlTexinfo::cls)
37 void FormTexinfo::build() {
38 dialog_.reset(build_texinfo(this));
40 // callback for double click in browser to view the selected file
41 fl_set_browser_dblclick_callback(dialog_->browser,
42 C_FormDialogView_InputCB, 2);
44 string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
45 fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
47 updateStyles(activeStyle);
49 // set up the tooltips
50 string str = _("Shows the installed classses and styles for LaTeX/BibTeX; "
51 "available only if the corresponding LyX layout file exists.");
52 tooltips().init(dialog_->choice_classes, str);
54 str = _("Show full path or only file name.");
55 tooltips().init(dialog_->check_fullpath, str);
57 str = _("Runs the script \"TexFiles.sh\" to build new file lists.");
58 tooltips().init(dialog_->button_rescan, str);
60 str = _("Double click to view contents of file.");
61 tooltips().init(dialog_->browser, str);
62 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
63 // Work-around xforms' bug; enable tooltips for browser widgets.
64 setPrehandler(dialog_->browser);
67 str = _("Runs the script \"texhash\" which builds a new LaTeX tree. "
68 "Needed if you install a new TeX class or style. You need write "
69 "permissions for the TeX-dirs, often /var/lib/texmf and others.");
70 tooltips().init(dialog_->button_texhash, str);
74 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
76 if (ob == dialog_->button_texhash) {
77 // makes only sense if the rights are set well for
78 // users (/var/lib/texmf/ls-R)
79 controller().runTexhash();
80 // texhash requires a rescan and an update of the styles
81 controller().rescanStyles();
82 updateStyles(activeStyle);
85 } else if (ob == dialog_->browser && ob_value == 2) {
86 // double click in browser: view selected file
87 string selection = getString(dialog_->browser);
88 if (!fl_get_button(dialog_->check_fullpath)) {
89 // contents in browser has filenames without path
90 // reconstruct path from controller getContents
91 string const files = controller().getContents(activeStyle, true);
92 vector<string> const vec = getVectorFromString(files, "\n");
94 // find line in files vector
95 vector<string>::const_iterator it = vec.begin();
96 for (; it != vec.end(); ++it) {
97 if ((*it).find(selection) != string::npos) {
103 if (!selection.empty()) {
104 controller().viewFile(selection);
107 // reset the browser so that the following single-click callback doesn't do anything
108 fl_deselect_browser(dialog_->browser);
110 } else if (ob == dialog_->button_rescan) {
111 // build new *Files.lst
112 controller().rescanStyles();
113 updateStyles(activeStyle);
115 } else if (ob == dialog_->check_fullpath) {
116 updateStyles(activeStyle);
118 } else if (ob == dialog_->choice_classes) {
119 switch (fl_get_choice(dialog_->choice_classes)) {
121 updateStyles(ControlTexinfo::bst);
124 updateStyles(ControlTexinfo::sty);
128 updateStyles(ControlTexinfo::cls);
132 return ButtonPolicy::SMI_VALID;
136 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
138 fl_clear_browser(dialog_->browser);
140 bool const withFullPath = fl_get_button(dialog_->check_fullpath);
143 controller().getContents(whichStyle, withFullPath);
144 fl_add_browser_line(dialog_->browser, str.c_str());
146 activeStyle = whichStyle;