Juergen Spitzmueller wrote: > Jean-Marc Lasgouttes wrote: > > Except that I do not think this requires to create a vector. But I may > > be mistaken. > > No, you're right. I'm just about to implement this.
Attached. But I cannot compile gtk at the moment, so somebody has to test and adjust this. Better? Jürgen
Index: toc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/toc.C,v retrieving revision 1.45 diff -p -u -r1.45 toc.C --- toc.C 4 Jul 2005 13:05:03 -0000 1.45 +++ toc.C 26 Jul 2005 13:55:32 -0000 @@ -17,7 +17,6 @@ #include "bufferparams.h" #include "FloatList.h" #include "funcrequest.h" -#include "gettext.h" #include "LyXAction.h" #include "paragraph.h" #include "pariterator.h" @@ -61,20 +60,22 @@ string const getType(string const & cmdN { // special case if (cmdName == "tableofcontents") - return _("TOC"); + return "TOC"; else return cmdName; } -string const getGuiName(string const & cmdName, Buffer const & buffer) +string const getGuiName(string const & type, Buffer const & buffer) { FloatList const & floats = buffer.params().getLyXTextClass().floats(); - if (floats.typeExist(cmdName)) - return _(floats.getType(cmdName).name()); + if (floats.typeExist(type)) + return floats.getType(type).name(); + else if (type == "TOC") + return "Table of Contents"; else - return getType(cmdName); + return type; } @@ -130,7 +131,7 @@ TocList const getTocList(Buffer const & tocstring = pit->asString(buf, true); TocItem const item(pit->id(), toclevel - min_toclevel, tocstring); - toclist[_("TOC")].push_back(item); + toclist["TOC"].push_back(item); } } return toclist; Index: toc.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/toc.h,v retrieving revision 1.15 diff -p -u -r1.15 toc.h --- toc.h 4 Jul 2005 13:05:03 -0000 1.15 +++ toc.h 26 Jul 2005 13:55:32 -0000 @@ -65,8 +65,8 @@ void asciiTocList(std::string const &, B by ControlToc::getContents() */ std::string const getType(std::string const & cmdName); -/// Returns the guiname from a given CmdName -std::string const getGuiName(std::string const & cmdName, Buffer const &); +/// Returns the guiname from a given type +std::string const getGuiName(std::string const & type, Buffer const &); inline bool operator==(TocItem const & a, TocItem const & b) Index: frontends/controllers/ControlToc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlToc.C,v retrieving revision 1.30 diff -p -u -r1.30 ControlToc.C --- frontends/controllers/ControlToc.C 4 Jul 2005 13:04:59 -0000 1.30 +++ frontends/controllers/ControlToc.C 26 Jul 2005 13:55:33 -0000 @@ -21,6 +21,7 @@ class Buffer; namespace lyx { namespace frontend { + ControlToc::ControlToc(Dialog & d) : ControlCommand(d, "toc") {} @@ -38,9 +39,9 @@ vector<string> const ControlToc::getType } -string const ControlToc::getGuiName() const +string const ControlToc::getGuiName(string const & type) const { - return toc::getGuiName(params().getCmdName(), kernel().buffer()); + return toc::getGuiName(type, kernel().buffer()); } Index: frontends/controllers/ControlToc.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlToc.h,v retrieving revision 1.15 diff -p -u -r1.15 ControlToc.h --- frontends/controllers/ControlToc.h 4 Jul 2005 13:04:59 -0000 1.15 +++ frontends/controllers/ControlToc.h 26 Jul 2005 13:55:33 -0000 @@ -34,7 +34,7 @@ public: std::vector<std::string> const getTypes() const; /// Return the guiname from a given cmdName of the TOC param - std::string const getGuiName() const; + std::string const getGuiName(std::string const & type) const; /// Given a type, returns the contents toc::Toc const getContents(std::string const & type) const; Index: frontends/gtk/GToc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gtk/GToc.C,v retrieving revision 1.6 diff -p -u -r1.6 GToc.C --- frontends/gtk/GToc.C 4 Jul 2005 13:05:00 -0000 1.6 +++ frontends/gtk/GToc.C 26 Jul 2005 13:55:34 -0000 @@ -88,7 +88,8 @@ void GToc::update() void GToc::updateType() { changing_views_ = true; - string const targettype = controller().getGuiName(); + string const targettype = + toc::getType(controller().params().getCmdName()); typestore_->clear(); vector<string> types = controller().getTypes(); @@ -100,8 +101,9 @@ void GToc::updateType() vector<string>::iterator it = types.begin(); vector<string>::iterator end = types.end(); for(;it != end; ++it) { + string const & guiname = _(controller().getGuiName(*it)); Gtk::TreeModel::iterator row = typestore_->append(); - (*row)[listCol_] = *it; + (*row)[listCol_] = guiname; if (*it == targettype) typecombo_->set_active(row); } @@ -119,7 +121,8 @@ void GToc::updateContents() } Gtk::TreeModel::iterator it = typecombo_->get_active(); - Glib::ustring const type = (*it)[listCol_]; + vector<string> const & choice = controller().getTypes(); + string const type = choice[(*it)[listColIndex_]]; toc::Toc const contents = controller().getContents(type); // Check if all elements are the same. Index: frontends/qt2/QToc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QToc.C,v retrieving revision 1.30 diff -p -u -r1.30 QToc.C --- frontends/qt2/QToc.C 4 Jul 2005 13:05:00 -0000 1.30 +++ frontends/qt2/QToc.C 26 Jul 2005 13:55:35 -0000 @@ -56,12 +56,13 @@ void QToc::updateType() dialog_->typeCO->clear(); vector<string> const & choice = controller().getTypes(); - string const & guiname = controller().getGuiName(); + string const & type = toc::getType(controller().params().getCmdName()); for (vector<string>::const_iterator it = choice.begin(); it != choice.end(); ++it) { - dialog_->typeCO->insertItem(toqstr(*it)); - if (*it == guiname) { + string const & guiname = _(controller().getGuiName(*it)); + dialog_->typeCO->insertItem(toqstr(guiname)); + if (*it == type) { dialog_->typeCO->setCurrentItem(it - choice.begin()); setTitle(guiname); } @@ -78,7 +79,8 @@ void QToc::update_contents() void QToc::updateToc(int newdepth) { - string type = fromqstr(dialog_->typeCO->currentText()); + vector<string> const & choice = controller().getTypes(); + string const & type = choice[dialog_->typeCO->currentItem()]; toc::Toc const & contents = controller().getContents(type); @@ -157,6 +159,7 @@ void QToc::updateToc(int newdepth) dialog_->tocLV->setUpdatesEnabled(true); dialog_->tocLV->update(); + setTitle(dialog_->typeCO->currentText()); } Index: frontends/xforms/FormToc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormToc.C,v retrieving revision 1.61 diff -p -u -r1.61 FormToc.C --- frontends/xforms/FormToc.C 4 Jul 2005 13:05:01 -0000 1.61 +++ frontends/xforms/FormToc.C 26 Jul 2005 13:55:36 -0000 @@ -43,9 +43,8 @@ void FormToc::build() vector<string> types = controller().getTypes(); - string const choice = - ' ' + getStringFromVector(controller().getTypes(), " | ") + ' '; + ' ' + getStringFromVector(types, " | ") + ' '; fl_addto_choice(dialog_->choice_toc_type, choice.c_str()); // Manage the cancel/close button @@ -85,18 +84,23 @@ void FormToc::updateType() { // Update the choice list from scratch fl_clear_choice(dialog_->choice_toc_type); - string const choice = getStringFromVector(controller().getTypes(), "|"); - fl_addto_choice(dialog_->choice_toc_type, choice.c_str()); - - // And select the correct one - string const guiname = controller().getGuiName(); - fl_set_choice_text(dialog_->choice_toc_type, guiname.c_str()); + vector<string> const & choice = controller().getTypes(); + string const & type = toc::getType(controller().params().getCmdName()); + for (vector<string>::const_iterator it = choice.begin(); + it != choice.end(); ++it) { + string const & guiname = _(controller().getGuiName(*it)); + fl_addto_choice(dialog_->choice_toc_type, guiname.c_str()); + // And select the correct one + if (*it == type) + fl_set_choice(dialog_->choice_toc_type, it - choice.begin() + 1); + } } void FormToc::updateContents() { - string const type = getString(dialog_->choice_toc_type); + vector<string> types = controller().getTypes(); + string const type = types[fl_get_choice(dialog_->choice_toc_type) - 1]; if (type.empty()) { fl_clear_browser(dialog_->browser_toc); fl_add_browser_line(dialog_->browser_toc, Index: insets/insetfloat.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfloat.C,v retrieving revision 1.140 diff -p -u -r1.140 insetfloat.C --- insets/insetfloat.C 9 May 2005 17:29:21 -0000 1.140 +++ insets/insetfloat.C 26 Jul 2005 13:55:38 -0000 @@ -434,12 +434,12 @@ void InsetFloat::addToToc(lyx::toc::TocL // Find a caption layout in one of the (child inset's) pars for (; pit != end; ++pit) { if (pit->layout()->labeltype == LABEL_SENSITIVE) { - string const name = floatname(params_.type, buf.params()); + string const type = params_.type; string const str = - convert<string>(toclist[name].size() + 1) + convert<string>(toclist[type].size() + 1) + ". " + pit->asString(buf, false); lyx::toc::TocItem const item(pit->id(), 0 , str); - toclist[name].push_back(item); + toclist[type].push_back(item); } } } Index: insets/insetwrap.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetwrap.C,v retrieving revision 1.76 diff -p -u -r1.76 insetwrap.C --- insets/insetwrap.C 9 May 2005 17:29:22 -0000 1.76 +++ insets/insetwrap.C 26 Jul 2005 13:55:43 -0000 @@ -242,12 +242,12 @@ void InsetWrap::addToToc(lyx::toc::TocLi // Find a caption layout in one of the (child inset's) pars for (; pit != end; ++pit) { if (pit->layout()->labeltype == LABEL_SENSITIVE) { - string const name = floatname(params_.type, buf.params()); + string const type = params_.type; string const str = - convert<string>(toclist[name].size() + 1) + convert<string>(toclist[type].size() + 1) + ". " + pit->asString(buf, false); lyx::toc::TocItem const item(pit->id(), 0 , str); - toclist[name].push_back(item); + toclist[type].push_back(item); } } }