]> git.lyx.org Git - features.git/commitdiff
getStatus for LFUN_SET_GRAPHICS_GROUP so context menu looks nicer.
authorPavel Sanda <sanda@lyx.org>
Tue, 13 May 2008 14:26:47 +0000 (14:26 +0000)
committerPavel Sanda <sanda@lyx.org>
Tue, 13 May 2008 14:26:47 +0000 (14:26 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24751 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyXFunc.cpp
src/Text3.cpp
src/frontends/qt4/Menus.cpp

index cd573f6022372885f1ee6d20535ef900d3fbdde4..88cd8c4a15bfc28000da8f803b1c41efc9a8d230 100644 (file)
@@ -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:
index 27bc623520259a0b50e06be4e7900a33a8896f1e..947975530204c41b5f0085728084277c541ba58b 100644 (file)
@@ -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;
index ee1a5b69c3d7c65b77ca01599ebe2ee5fc040dd2..a75ebc252ab871b23b154176688504063aad78d3 100644 (file)
@@ -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<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;
+       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: {