]> git.lyx.org Git - features.git/commitdiff
General support for InsetCommand context menu. For this to work properly I had to...
authorAbdelrazak Younes <younes@lyx.org>
Sun, 9 Mar 2008 11:22:39 +0000 (11:22 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 9 Mar 2008 11:22:39 +0000 (11:22 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23579 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/Menus.cpp
src/frontends/qt4/Menus.h
src/insets/InsetCommand.cpp
src/insets/InsetCommand.h
src/insets/InsetRef.cpp
src/insets/InsetRef.h

index eefe3ee1530cfbf3045b42e30938695785bd3c55..9ade138c1043214a2490efb3b64fee890e7e98a2 100644 (file)
@@ -1667,7 +1667,7 @@ bool GuiView::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_MENU_OPEN:
-                       if (QMenu * menu = guiApp->menus().menu(toqstr(cmd.argument())))
+                       if (QMenu * menu = guiApp->menus().menu(toqstr(cmd.argument()), *this))
                                menu->exec(QCursor::pos());
                        break;
 
index 2618f830ba3493f94b10abe83c47b351e5d7dac8..ec398feb39d90ecfb9b83276bff8f4cbec7c5645 100644 (file)
@@ -611,7 +611,7 @@ void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
                QAbstractScrollArea::contextMenuEvent(e);
                return;
        }
-       QMenu * menu = guiApp->menus().menu(toqstr(name));
+       QMenu * menu = guiApp->menus().menu(toqstr(name), *lyx_view_);
        if (!menu) {
                QAbstractScrollArea::contextMenuEvent(e);
                return;
index c51b4ac17ee09caf013cd8bf00d9b0f231206570..3876fcb991f241825e1dfb7cdd0305ee784494e0 100644 (file)
@@ -292,6 +292,14 @@ public:
                setTitle(label(mi));
        }
 
+       ///
+       GuiPopupMenu(GuiView * gv, QString const & name_, bool top_level)
+               : QMenu(gv), top_level_menu(top_level? new Menu : 0), view(gv),
+               name(name_)
+       {
+               setTitle(name_);
+       }
+
        ~GuiPopupMenu() { delete top_level_menu; }
 
        /// populates the menu or one of its submenu
@@ -1480,23 +1488,29 @@ void Menus::updateMenu(QString const & name)
        // Here, We make sure that theLyXFunc points to the correct LyXView.
        theLyXFunc().setLyXView(qmenu->view);
 
+       if (!d->hasMenu(qmenu->name)) {
+               LYXERR(Debug::GUI, "\tWARNING: non existing menu: "
+                       << fromqstr(qmenu->name));
+               return;
+       }
+
        Menu const & fromLyxMenu = d->getMenu(qmenu->name);
        d->expand(fromLyxMenu, *qmenu->top_level_menu, qmenu->view->buffer());
-
-       if (!d->hasMenu(qmenu->top_level_menu->name())) {
-               LYXERR(Debug::GUI, "\tWARNING: menu seems empty"
-                       << fromqstr(qmenu->top_level_menu->name()));
-       }
        qmenu->populate(qmenu, qmenu->top_level_menu);
 }
 
 
-QMenu * Menus::menu(QString const & name)
+QMenu * Menus::menu(QString const & name, GuiView & view)
 {
        LYXERR(Debug::GUI, "Context menu requested: " << fromqstr(name));
        GuiPopupMenu * menu = d->name_map_.value(name, 0);
-       if (!menu)
+       if (!menu && !name.startsWith("context-")) {
                LYXERR0("resquested context menu not found: " << fromqstr(name));
+               return 0;
+       }
+
+       menu = new GuiPopupMenu(&view, name, true);
+       d->name_map_[name] = menu;
        return menu;
 }
 
index daafcd3fa99791daf159120fe8eb5fedc14cb871..a56e092e4e7d30a495a56762273e9fd41f888c4b 100644 (file)
@@ -41,7 +41,7 @@ public:
        void fillMenuBar(GuiView * view);
 
        /// \return a top-level submenu given its name.
-       QMenu * menu(QString const & name);
+       QMenu * menu(QString const & name, GuiView & view);
 
        ///
        void read(Lexer &);
index 3f4904d4490879b3fab57464733e061aafa23f3b..c1fa7b6f06dec976503e20745de174fa11d9a0df 100644 (file)
@@ -116,7 +116,7 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_MOUSE_RELEASE: {
-               if (!cur.selection())
+               if (!cur.selection() && cmd.button() != mouse_button::button3)
                        edit(cur, true);
                break;
        }
@@ -148,6 +148,12 @@ bool InsetCommand::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
+docstring InsetCommand::contextMenu(BufferView const &, int, int) const
+{
+       return from_ascii("context-") + from_ascii(mailer_name_);
+}
+
+
 void InsetCommand::edit(Cursor & cur, bool, EntryDirection)
 {
        if (!mailer_name_.empty())
index beada3091a892d786f60a8052fd9e5cbd2b3a619..9e946745ca098ddf98c482248f75119efa7b3158 100644 (file)
@@ -84,6 +84,8 @@ public:
        static bool isCompatibleCommand(std::string const & cmd);
        /// update label and references.
        virtual void updateCommand(docstring const &, bool) {};
+       ///
+       virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
 
 protected:
        ///
index f908a13598eddbb060eb88e2e421147d6d73a29d..82821a61b1ee4ec827b0b721b4a6be3db03d88b8 100644 (file)
@@ -74,24 +74,6 @@ ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
 }
 
 
-void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
-{
-       switch (cmd.action) {
-       case LFUN_MOUSE_RELEASE:
-               // Eventually trigger dialog with button 3 not 1
-               if (cmd.button() == mouse_button::button3)
-                       lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
-                                                 getParam("reference")));
-               else
-                       InsetCommand::doDispatch(cur, cmd);
-               break;
-
-       default:
-               InsetCommand::doDispatch(cur, cmd);
-       }
-}
-
-
 docstring InsetRef::screenLabel() const
 {
        return screen_label_;
@@ -183,13 +165,6 @@ void InsetRef::addToToc(ParConstIterator const & cpit) const
 }
 
 
-docstring InsetRef::contextMenu(BufferView const &, int, int) const
-{
-       // FIXME: find a way to create a menu with "Goto label" inside.
-       return docstring();
-}
-
-
 void InsetRef::validate(LaTeXFeatures & features) const
 {
        if (getCmdName() == "vref" || getCmdName() == "vpageref")
index a9c8f7c8877c2950f2043ae3d6cca3c624b5ee84..da4a176dbc051df568d83b74b62641efe440844c 100644 (file)
@@ -71,13 +71,9 @@ public:
        void updateLabels(ParIterator const & it);
        ///
        void addToToc(ParConstIterator const &) const;
-       ///
-       virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
 protected:
        ///
        InsetRef(InsetRef const &);
-       ///
-       void doDispatch(Cursor & cur, FuncRequest & cmd);
 private:
        ///
        Inset * clone() const { return new InsetRef(*this); }