> > > the situation with settings is even more weird, because if you insert > > > picture into another inset, eg box, settings get enabled but also gets > > > checkbox. > > > > I am trying to work on it. > > i'm trying to do something similar but can't get it right. in short i would > like to put checkbox in context menu which will show the current group of the > given picture, but i didn't find a way how to get flags in text3 > text::getStatus being accepted, they are simply ignored. > > i was able to solve it by moving status code into LyxFunc.cpp, but this is > not the rightplace for such a code. > > this would explain why sometimes settings context is sometimes disabled and > sometimes > enabled even with checkbox. > > is this bug somewhere in getStatus mechanism or where else should i put > the code for handling status of LFUN_SET_GRAPHICS_GROUP ?
fyi this is the working code, when status check is put inside LyXFunc::getStatus in LyXFunc.cpp when i put equivalent code inside Text::getStatus in text3.cpp then flag settings are ignored. any idea whats wrong? pavel
diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 7bbeba7..b44a197 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -453,6 +453,16 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const enable = false; break; + case LFUN_SET_GRAPHICS_GROUP: { + if (!view()) break; + InsetGraphics * ins = InsetGraphics::getCurrentGraphicsInset(view()->cursor()); + if (!ins) break; + if (!cmd.argument().empty()) + flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId); + enable = true; + break; + } + case LFUN_TOOLBAR_TOGGLE: case LFUN_INSET_APPLY: case LFUN_BUFFER_WRITE: diff --git a/src/Text3.cpp b/src/Text3.cpp index aed8fc8..2180ebe 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -2272,7 +2272,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_BUFFER_BEGIN_SELECT: case LFUN_BUFFER_END_SELECT: case LFUN_UNICODE_INSERT: - case LFUN_SET_GRAPHICS_GROUP: // these are handled in our dispatch() enable = true; break; diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 51ef148..db451e3 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -293,7 +293,7 @@ public: void expandToolbars(); void expandBranches(Buffer const * buf); void expandCiteStyles(BufferView const *); - void expandGraphicsGroups(Buffer const * buf); + void expandGraphicsGroups(BufferView const *); /// ItemList items_; /// @@ -633,18 +633,26 @@ QString limitStringLength(docstring const & str) } -void MenuDefinition::expandGraphicsGroups(Buffer const * buf) +void MenuDefinition::expandGraphicsGroups(BufferView const * bv) { + if (!bv || !&bv->buffer() || !&bv->cursor()) return; + + Cursor const & cur = bv->cursor(); + Buffer const & buf = bv->buffer(); set<string> grp; - InsetGraphics::getGraphicsGroups(*buf, grp); + InsetGraphics::getGraphicsGroups(buf, grp); set<string>::const_iterator it = grp.begin(); set<string>::const_iterator end = grp.end(); if (grp.empty()) return; + InsetGraphics * ins = InsetGraphics::getCurrentGraphicsInset(cur); + if (!ins) return; add(MenuItem(MenuItem::Separator)); - add(MenuItem(MenuItem::Command, qt_("Clear group"), FuncRequest(LFUN_SET_GRAPHICS_GROUP))); + if (!ins->getParams().groupId.empty()) + add(MenuItem(MenuItem::Command, qt_("Clear group"), FuncRequest(LFUN_SET_GRAPHICS_GROUP))); for (; it != end; it++) { - add(MenuItem(MenuItem::Command, toqstr(*it), FuncRequest(LFUN_SET_GRAPHICS_GROUP, *it))); + addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(*it), + FuncRequest(LFUN_SET_GRAPHICS_GROUP, *it))); } } @@ -1422,7 +1430,7 @@ void Menus::Impl::expand(MenuDefinition const & frommenu, break; case MenuItem::GraphicsGroups: - tomenu.expandGraphicsGroups(buf); + tomenu.expandGraphicsGroups(bv); break; case MenuItem::Submenu: {