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;
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;
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
// 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;
}
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 &);
}
case LFUN_MOUSE_RELEASE: {
- if (!cur.selection())
+ if (!cur.selection() && cmd.button() != mouse_button::button3)
edit(cur, true);
break;
}
}
+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())
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:
///
}
-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_;
}
-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")
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); }