3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Herbert Voss <voss@lyx.org>
14 #pragma implementation
18 #include "FormTexinfo.h"
19 #include "form_texinfo.h"
22 #include "xforms_helpers.h"
23 #include "support/LAssert.h"
27 // C function wrapper, required by xforms.
29 int C_FormTexinfoFeedbackCB(FL_OBJECT * ob, int event,
30 FL_Coord, FL_Coord, int, void *)
32 // Note that the return value is important in the pre-emptive handler.
33 // Don't return anything other than 0.
36 // Don't Assert this one, as it can happen quite reasonably when things
37 // are being deleted in the d-tor.
39 if (!ob->form) return 0;
42 static_cast<FormTexinfo*>(ob->form->u_vdata);
43 pre->feedbackCB(ob, event);
47 void setPreHandler(FL_OBJECT * ob)
50 fl_set_object_prehandler(ob, C_FormTexinfoFeedbackCB);
56 typedef FormCB<ControlTexinfo, FormDB<FD_form_texinfo> > base_class;
57 FormTexinfo::FormTexinfo(ControlTexinfo & c)
58 : base_class(c, _("TeX Infos")),
59 warningPosted(false), activeStyle(ControlTexinfo::cls)
63 void FormTexinfo::build() {
64 dialog_.reset(build_texinfo());
66 fl_set_browser_fontstyle(dialog_->browser,FL_FIXED_STYLE);
67 // with Path is default
68 fl_set_button(dialog_->button_fullPath, 1);
69 updateStyles(ControlTexinfo::cls);
71 setPreHandler(dialog_->button_rescan);
72 setPreHandler(dialog_->button_view);
73 setPreHandler(dialog_->button_texhash);
74 setPreHandler(dialog_->button_fullPath);
75 setPreHandler(dialog_->browser);
76 setPreHandler(dialog_->radio_cls);
77 setPreHandler(dialog_->radio_sty);
78 setPreHandler(dialog_->radio_bst);
79 setPreHandler(dialog_->message);
80 setPreHandler(dialog_->help);
84 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long) {
85 if (ob == dialog_->help) {
88 } else if (ob == dialog_->radio_cls) {
89 updateStyles(ControlTexinfo::cls);
91 } else if (ob == dialog_->radio_sty) {
92 updateStyles(ControlTexinfo::sty);
94 } else if (ob == dialog_->radio_bst) {
95 updateStyles(ControlTexinfo::bst);
97 } else if (ob == dialog_->button_rescan) {
98 // build new *Files.lst
99 controller().rescanStyles();
100 updateStyles(activeStyle);
102 } else if (ob == dialog_->button_fullPath) {
103 setEnabled(dialog_->button_view,
104 fl_get_button(dialog_->button_fullPath));
105 updateStyles(activeStyle);
107 } else if (ob == dialog_->button_texhash) {
108 // makes only sense if the rights are set well for
109 // users (/var/lib/texmf/ls-R)
110 controller().runTexhash();
111 // update files in fact of texhash
112 controller().rescanStyles();
114 } else if (ob == dialog_->button_view) {
115 unsigned int selection = fl_get_browser(dialog_->browser);
118 controller().viewFile(
119 fl_get_browser_line(dialog_->browser,
124 return ButtonPolicy::SMI_VALID;
127 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
129 fl_clear_browser(dialog_->browser);
131 bool const withFullPath = fl_get_button(dialog_->button_fullPath);
134 controller().getContents(whichStyle, withFullPath);
135 fl_add_browser_line(dialog_->browser, str.c_str());
137 activeStyle = whichStyle;
141 // preemptive handler for feedback messages
142 void FormTexinfo::feedbackCB(FL_OBJECT * ob, int event)
148 warningPosted = false;
153 if (!warningPosted) {
154 fl_set_object_label(dialog_->message, "");
155 fl_redraw_object(dialog_->message);
165 void FormTexinfo::feedback(FL_OBJECT * ob)
171 if (ob == dialog_->button_rescan) {
172 str = _("starts rescan ...");
174 } else if (ob == dialog_->button_fullPath) {
175 str = _("View full path or only file name");
177 } else if (ob == dialog_->button_texhash) {
178 str = _("starts texhash and rescan...");
180 } else if (ob == dialog_->button_view) {
181 str = _("views a selected file");
185 fl_set_object_label(dialog_->message, str.c_str());
186 fl_redraw_object(dialog_->message);