]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormErrorList.C
get rid of InsetError users
[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 void FormErrorList::build()
34 {
35         dialog_.reset(build_errorlist(this));
36         setEnabled(dialog_->input_description, false);
37 }
38
39
40 void FormErrorList::update()
41 {
42         fl_set_form_title(dialog_->form, controller().name().c_str());
43         updateContents();
44 }
45
46
47 ButtonPolicy::SMInput FormErrorList::input(FL_OBJECT * ob, long)
48 {
49         if (ob == dialog_->browser_errors) {
50                 //xforms return values 1..n
51                 int const choice = int(fl_get_browser(dialog_->browser_errors)) - 1;
52                 goTo(choice);
53                 return ButtonPolicy::SMI_VALID;
54         }
55
56         return ButtonPolicy::SMI_VALID;
57 }
58
59
60 void FormErrorList::goTo(int where)
61 {
62         ErrorList const & errors = controller().errorList();
63
64         if (0 <= where && where < int(errors.size())) {
65                 controller().goTo(where);
66                 fl_set_input(dialog_->input_description,
67                              errors[where].description.c_str());
68                 setEnabled(dialog_->input_description, false);
69         }
70 }
71
72
73 void FormErrorList::updateContents()
74 {
75         fl_clear_browser(dialog_->browser_errors);
76
77         ErrorList const & errors = controller().errorList();
78         if (errors.empty()) {
79                 fl_add_browser_line(dialog_->browser_errors,
80                                     _("*** No Lists ***").c_str());
81                 setEnabled(dialog_->browser_errors, false);
82                 return;
83         }
84
85         setEnabled(dialog_->browser_errors, true);
86
87         ErrorList::const_iterator cit = errors.begin();
88         ErrorList::const_iterator end = errors.end();
89
90         for (; cit != end; ++cit) {
91                 fl_add_browser_line(dialog_->browser_errors,
92                                     cit->error.c_str());
93         }
94
95         fl_select_browser_line(dialog_->browser_errors, 1);
96         goTo(1);
97 }