From 32ab2ff2b73077cae55b690084aa7cfaa5e7c956 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 2 Feb 2011 17:11:56 +0000 Subject: [PATCH] Fix bug #7224. This allows two different floats to declare the same ListCommand without our writing it to the menu twice. There's a minor annoyance, which is that we always take the list name from the first declaration of the Float, but it's not clear whether this is a real issue. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37424 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/layouts/tufte-book.layout | 2 ++ src/frontends/qt4/Menus.cpp | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/layouts/tufte-book.layout b/lib/layouts/tufte-book.layout index 2e29595d58..826476982c 100644 --- a/lib/layouts/tufte-book.layout +++ b/lib/layouts/tufte-book.layout @@ -221,6 +221,7 @@ Float NumberWithin none Style plain ListName "List of Tables" + ListCommand listoftables NeedsFloatPkg false End @@ -232,6 +233,7 @@ Float NumberWithin none Style plain ListName "List of Figures" + ListCommand listoffigures NeedsFloatPkg false End diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index d3cce1e56b..70379d9582 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1094,11 +1094,21 @@ void MenuDefinition::expandFloatListInsert(Buffer const * buf) FloatList const & floats = buf->params().documentClass().floats(); FloatList::const_iterator cit = floats.begin(); FloatList::const_iterator end = floats.end(); + set seen; for (; cit != end; ++cit) { - addWithStatusCheck(MenuItem(MenuItem::Command, - qt_(cit->second.listName()), - FuncRequest(LFUN_FLOAT_LIST_INSERT, - cit->second.floattype()))); + // Different floats could declare the same ListCommand. We only + // want it on the list once, though. + string const & list_cmd = cit->second.listCommand(); + // This form of insert returns an iterator pointing to the newly + // inserted element OR the existing element with that value, and + // a bool indicating whether we inserted a new element. So we can + // see if one is there and insert it if not all at once. + pair::iterator, bool> ret = seen.insert(list_cmd); + if (!ret.second) + continue; + string const & list_name = cit->second.listName(); + addWithStatusCheck(MenuItem(MenuItem::Command, qt_(list_name), + FuncRequest(LFUN_FLOAT_LIST_INSERT, cit->second.floattype()))); } } -- 2.39.2