From 51a5db71104e635e64f97e2c49737b6a9c66c6ab Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 9 Mar 2008 11:22:39 +0000 Subject: [PATCH] General support for InsetCommand context menu. For this to work properly I had to disable all actions triggered by mouse right-clicking. This was bad ui in any case. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23579 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiView.cpp | 2 +- src/frontends/qt4/GuiWorkArea.cpp | 2 +- src/frontends/qt4/Menus.cpp | 28 +++++++++++++++++++++------- src/frontends/qt4/Menus.h | 2 +- src/insets/InsetCommand.cpp | 8 +++++++- src/insets/InsetCommand.h | 2 ++ src/insets/InsetRef.cpp | 25 ------------------------- src/insets/InsetRef.h | 4 ---- 8 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index eefe3ee153..9ade138c10 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -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; diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 2618f830ba..ec398feb39 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -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; diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index c51b4ac17e..3876fcb991 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -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; } diff --git a/src/frontends/qt4/Menus.h b/src/frontends/qt4/Menus.h index daafcd3fa9..a56e092e4e 100644 --- a/src/frontends/qt4/Menus.h +++ b/src/frontends/qt4/Menus.h @@ -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 &); diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp index 3f4904d449..c1fa7b6f06 100644 --- a/src/insets/InsetCommand.cpp +++ b/src/insets/InsetCommand.cpp @@ -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()) diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h index beada3091a..9e946745ca 100644 --- a/src/insets/InsetCommand.h +++ b/src/insets/InsetCommand.h @@ -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: /// diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index f908a13598..82821a61b1 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -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") diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h index a9c8f7c887..da4a176dbc 100644 --- a/src/insets/InsetRef.h +++ b/src/insets/InsetRef.h @@ -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); } -- 2.39.2