From 42d71d632fc8ec53091f434a707e638c5614aff2 Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Tue, 13 May 2008 14:26:47 +0000 Subject: [PATCH] getStatus for LFUN_SET_GRAPHICS_GROUP so context menu looks nicer. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24751 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXFunc.cpp | 14 ++++++++++++++ src/Text3.cpp | 1 - src/frontends/qt4/Menus.cpp | 24 +++++++++++++++++------- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index cd573f6022..88cd8c4a15 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -453,6 +453,20 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const enable = false; break; + // FIXME optimally this should be in Text::getStatus. In such a case the flags + // are not passed when using context menu. This way it works. + 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 27bc623520..9479755302 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -2273,7 +2273,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 ee1a5b69c3..a75ebc252a 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -294,7 +294,7 @@ public: void expandToolbars(); void expandBranches(Buffer const * buf); void expandCiteStyles(BufferView const *); - void expandGraphicsGroups(Buffer const * buf); + void expandGraphicsGroups(BufferView const *); /// ItemList items_; /// @@ -634,18 +634,28 @@ QString limitStringLength(docstring const & str) } -void MenuDefinition::expandGraphicsGroups(Buffer const * buf) +void MenuDefinition::expandGraphicsGroups(BufferView const * bv) { + if (!bv) + return; + Cursor const & cur = bv->cursor(); + Buffer const & buf = bv->buffer(); set grp; - InsetGraphics::getGraphicsGroups(*buf, grp); + InsetGraphics::getGraphicsGroups(buf, grp); set::const_iterator it = grp.begin(); set::const_iterator end = grp.end(); - if (grp.empty()) return; + 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))); } } @@ -1423,7 +1433,7 @@ void Menus::Impl::expand(MenuDefinition const & frommenu, break; case MenuItem::GraphicsGroups: - tomenu.expandGraphicsGroups(buf); + tomenu.expandGraphicsGroups(bv); break; case MenuItem::Submenu: { -- 2.39.2