3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
14 #include "ControlToc.h"
15 #include "forms/form_toc.h"
17 #include "xforms_helpers.h"
20 #include "support/lstrings.h" // frontStrip, strip
22 #include "lyx_forms.h"
24 using namespace lyx::support;
29 typedef FormController<ControlToc, FormView<FD_toc> > base_class;
31 FormToc::FormToc(Dialog & parent)
32 : base_class(parent, _("Table of Contents"))
38 dialog_.reset(build_toc(this));
40 vector<string> types = controller().getTypes();
44 ' ' + getStringFromVector(controller().getTypes(), " | ") + ' ';
45 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
47 // Manage the cancel/close button
48 bcview().setCancel(dialog_->button_close);
52 void FormToc::update()
59 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
61 if (ob == dialog_->browser_toc) {
62 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
64 if (choice - 1 < toc_.size() && choice >= 1) {
65 controller().goTo(toc_[choice - 1]);
67 return ButtonPolicy::SMI_VALID;
70 if (ob != dialog_->choice_toc_type) {
76 return ButtonPolicy::SMI_VALID;
80 void FormToc::updateType()
82 // Update the choice list from scratch
83 fl_clear_choice(dialog_->choice_toc_type);
84 string const choice = getStringFromVector(controller().getTypes(), "|");
85 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
87 // And select the correct one
88 string const type = lyx::toc::getType(controller().params().getCmdName());
89 fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
93 void FormToc::updateContents()
95 string const type = getString(dialog_->choice_toc_type);
97 fl_clear_browser(dialog_->browser_toc);
98 fl_add_browser_line(dialog_->browser_toc,
99 _("*** No Lists ***").c_str());
100 setEnabled(dialog_->browser_toc, false);
104 lyx::toc::Toc const contents = controller().getContents(type);
106 // Check if all elements are the same.
107 if (toc_ == contents) {
111 // List has changed. Update browser
114 if (contents.empty()) {
115 fl_clear_browser(dialog_->browser_toc);
116 fl_add_browser_line(dialog_->browser_toc,
117 _("*** No Lists ***").c_str());
118 setEnabled(dialog_->browser_toc, false);
122 unsigned int const topline =
123 fl_get_browser_topline(dialog_->browser_toc);
124 unsigned int const line = fl_get_browser(dialog_->browser_toc);
126 fl_clear_browser(dialog_->browser_toc);
127 setEnabled(dialog_->browser_toc, true);
129 lyx::toc::Toc::const_iterator cit = contents.begin();
130 lyx::toc::Toc::const_iterator end = contents.end();
131 for (; cit != end; ++cit) {
132 fl_add_browser_line(dialog_->browser_toc,
133 cit->asString().c_str());
136 fl_set_browser_topline(dialog_->browser_toc, topline);
137 fl_select_browser_line(dialog_->browser_toc, line);