Jean-Marc Lasgouttes wrote: > I would really like to see a patch where only the type of float is > used internally, and the GUI name is only for displaying.
I decided to do this properly now (use no translatable strings internally). Some new funtions were needed. See attached patch. For 1.3.6, I propose just to remove the l10n marks from "TOC" again. MenuBackend looks for "TOC", and if this string is translated, menu generation might fail. Jean-Marc, what do you think? Jürgen
Index: toc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/toc.C,v retrieving revision 1.15.2.3 diff -u -r1.15.2.3 toc.C --- toc.C 4 Jul 2005 13:24:46 -0000 1.15.2.3 +++ toc.C 5 Jul 2005 09:42:11 -0000 @@ -60,7 +60,7 @@ { // special case if (cmdName == "tableofcontents") - return _("TOC"); + return "TOC"; else return cmdName; } @@ -101,7 +101,7 @@ const int depth = max(0, labeltype - textclass.maxcounter()); TocItem const item(par->id(), depth, par->asString(buf, true)); - toclist[_("TOC")].push_back(item); + toclist["TOC"].push_back(item); } // For each paragraph, traverse its insets and look for
Index: toc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/toc.C,v retrieving revision 1.45 diff -u -r1.45 toc.C --- toc.C 4 Jul 2005 13:05:03 -0000 1.45 +++ toc.C 5 Jul 2005 12:50:06 -0000 @@ -61,20 +61,38 @@ { // special case if (cmdName == "tableofcontents") - return _("TOC"); + return "TOC"; else return cmdName; } -string const getGuiName(string const & cmdName, Buffer const & buffer) +string const getTypeFromGuiName(string const & guiname, Buffer const & buffer) { FloatList const & floats = buffer.params().getLyXTextClass().floats(); - if (floats.typeExist(cmdName)) - return _(floats.getType(cmdName).name()); + FloatList::const_iterator it = floats.begin(); + FloatList::const_iterator end = floats.end(); + if (guiname == _("Table of Contents")) + return "TOC"; + for (; it != end; ++it) { + if (_(it->second.name()) == guiname) + return it->second.type(); + } + return guiname; +} + + +string const getGuiName(string const & type, Buffer const & buffer) +{ + FloatList const & floats = + buffer.params().getLyXTextClass().floats(); + 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 +148,7 @@ 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 -u -r1.15 toc.h --- toc.h 4 Jul 2005 13:05:03 -0000 1.15 +++ toc.h 5 Jul 2005 12:50:06 -0000 @@ -65,8 +65,11 @@ 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 &); + +/// Returns the type from a given GuiName +std::string const getTypeFromGuiName(std::string const & guiname, 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 -u -r1.30 ControlToc.C --- frontends/controllers/ControlToc.C 4 Jul 2005 13:04:59 -0000 1.30 +++ frontends/controllers/ControlToc.C 5 Jul 2005 12:50:07 -0000 @@ -38,9 +38,21 @@ } +string const ControlToc::getType(string const & guiname) const +{ + return toc::getTypeFromGuiName(guiname, kernel().buffer()); +} + + +string const ControlToc::getGuiName(string const & type) const +{ + return toc::getGuiName(type, kernel().buffer()); +} + + string const ControlToc::getGuiName() const { - return toc::getGuiName(params().getCmdName(), kernel().buffer()); + return getGuiName(params().getCmdName()); } Index: frontends/controllers/ControlToc.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlToc.h,v retrieving revision 1.15 diff -u -r1.15 ControlToc.h --- frontends/controllers/ControlToc.h 4 Jul 2005 13:04:59 -0000 1.15 +++ frontends/controllers/ControlToc.h 5 Jul 2005 12:50:07 -0000 @@ -33,8 +33,14 @@ /// Return the list of types available std::vector<std::string> const getTypes() const; + /// Return the type from a given GuiName + std::string const ControlToc::getType(std::string const & guiname) const; + /// Return the guiname from a given cmdName of the TOC param std::string const getGuiName() const; + + /// Return the guiname from a given cmdName of the TOC param + 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 -u -r1.6 GToc.C --- frontends/gtk/GToc.C 4 Jul 2005 13:05:00 -0000 1.6 +++ frontends/gtk/GToc.C 5 Jul 2005 12:50:07 -0000 @@ -88,7 +88,8 @@ 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 @@ 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 @@ } Gtk::TreeModel::iterator it = typecombo_->get_active(); - Glib::ustring const type = (*it)[listCol_]; + Glib::ustring const guiname = (*it)[listCol_]; + string const type = controller().getType(guiname); 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 -u -r1.30 QToc.C --- frontends/qt2/QToc.C 4 Jul 2005 13:05:00 -0000 1.30 +++ frontends/qt2/QToc.C 5 Jul 2005 12:50:08 -0000 @@ -56,12 +56,13 @@ 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::updateToc(int newdepth) { - string type = fromqstr(dialog_->typeCO->currentText()); + string const & type = controller().getType( + fromqstr(dialog_->typeCO->currentText())); toc::Toc const & contents = controller().getContents(type); @@ -157,6 +159,7 @@ 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 -u -r1.61 FormToc.C --- frontends/xforms/FormToc.C 4 Jul 2005 13:05:01 -0000 1.61 +++ frontends/xforms/FormToc.C 5 Jul 2005 12:50:10 -0000 @@ -85,18 +85,23 @@ { // 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()); + vector<string> const & choice = controller().getTypes(); + 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 - string const guiname = controller().getGuiName(); - fl_set_choice_text(dialog_->choice_toc_type, guiname.c_str()); + string const act_guiname = controller().getGuiName(); + fl_set_choice_text(dialog_->choice_toc_type, act_guiname.c_str()); } void FormToc::updateContents() { - string const type = getString(dialog_->choice_toc_type); + string const type = controller().getType( + getString(dialog_->choice_toc_type)); 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 -u -r1.140 insetfloat.C --- insets/insetfloat.C 9 May 2005 17:29:21 -0000 1.140 +++ insets/insetfloat.C 5 Jul 2005 12:50:11 -0000 @@ -436,10 +436,10 @@ if (pit->layout()->labeltype == LABEL_SENSITIVE) { string const name = floatname(params_.type, buf.params()); string const str = - convert<string>(toclist[name].size() + 1) + convert<string>(toclist[params_.type].size() + 1) + ". " + pit->asString(buf, false); lyx::toc::TocItem const item(pit->id(), 0 , str); - toclist[name].push_back(item); + toclist[params_.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 -u -r1.76 insetwrap.C --- insets/insetwrap.C 9 May 2005 17:29:22 -0000 1.76 +++ insets/insetwrap.C 5 Jul 2005 12:50:11 -0000 @@ -244,10 +244,10 @@ if (pit->layout()->labeltype == LABEL_SENSITIVE) { string const name = floatname(params_.type, buf.params()); string const str = - convert<string>(toclist[name].size() + 1) + convert<string>(toclist[params_.type].size() + 1) + ". " + pit->asString(buf, false); lyx::toc::TocItem const item(pit->id(), 0 , str); - toclist[name].push_back(item); + toclist[params_.type].push_back(item); } } }