]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormErrorList.C
If I ever see another licence blurb again, it'll be too soon...
[lyx.git] / src / frontends / xforms / FormErrorList.C
1 /**
2  * \file FormErrorList.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alfredo Braunstein
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13
14 #include "errorlist.h"
15 #include "FormErrorList.h"
16 #include "xformsBC.h"
17 #include "xforms_helpers.h"
18 #include "ControlErrorList.h"
19 #include "forms/form_errorlist.h"
20 #include "support/lstrings.h" // frontStrip, strip
21 #include "debug.h"
22 #include "gettext.h"
23 #include "lyx_forms.h"
24
25
26 typedef FormController<ControlErrorList, FormView<FD_errorlist> > base_class;
27
28 FormErrorList::FormErrorList(Dialog & parent)
29         : base_class(parent, "")
30 {}
31
32
33 int dumb_validator(FL_OBJECT *, const char *, const char *, int)
34 {
35         return FL_INVALID;
36 }
37
38
39 void FormErrorList::build()
40 {
41         dialog_.reset(build_errorlist(this));
42         fl_set_input_filter(dialog_->input_description, dumb_validator);
43 }
44
45
46 void FormErrorList::update()
47 {
48         setTitle(controller().name());
49         updateContents();
50 }
51
52
53 ButtonPolicy::SMInput FormErrorList::input(FL_OBJECT * ob, long)
54 {
55         if (ob == dialog_->browser_errors) {
56                 //xforms return values 1..n
57                 int const choice = int(fl_get_browser(dialog_->browser_errors)) - 1;
58                 goTo(choice);
59         }
60
61         return ButtonPolicy::SMI_VALID;
62 }
63
64
65 void FormErrorList::goTo(int where)
66 {
67         ErrorList const & errors = controller().errorList();
68
69         if (0 <= where && where < int(errors.size())) {
70                 controller().goTo(where);
71                 fl_set_input(dialog_->input_description,
72                              errors[where].description.c_str());
73                 fl_set_input_topline(dialog_->input_description, 1);
74         }
75 }
76
77
78 void FormErrorList::updateContents()
79 {
80         fl_clear_browser(dialog_->browser_errors);
81
82         ErrorList const & errors = controller().errorList();
83         if (errors.empty()) {
84                 fl_add_browser_line(dialog_->browser_errors,
85                                     _("*** No Lists ***").c_str());
86                 setEnabled(dialog_->browser_errors, false);
87                 return;
88         }
89
90         setEnabled(dialog_->browser_errors, true);
91
92         ErrorList::const_iterator cit = errors.begin();
93         ErrorList::const_iterator end = errors.end();
94
95         for (; cit != end; ++cit) {
96                 fl_add_browser_line(dialog_->browser_errors,
97                                     cit->error.c_str());
98         }
99
100         fl_select_browser_line(dialog_->browser_errors, 1);
101         goTo(0);
102 }