}
-Menu const & BufferView::contextMenu(int x, int y) const
+docstring BufferView::contextMenu(int x, int y) const
{
+ // Get inset under mouse, if there is one.
+ Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
+ if (covering_inset)
+ return covering_inset->contextMenu(*this, x, y);
+
// FIXME: Do something more elaborate here.
- return theApp()->menuBackend().getMenu(from_ascii("edit"));
+ return from_ascii("edit");
}
/// \return Tool tip for the given position.
docstring toolTip(int x, int y) const;
/// \return the context menu for the given position.
- Menu const & contextMenu(int x, int y) const;
+ docstring contextMenu(int x, int y) const;
/// Save the current position as bookmark.
/// if idx == 0, save to temp_bookmark
break;
case LFUN_MENU_OPEN:
- guiApp->menus().openByName(toqstr(cmd.argument()));
+ if (QMenu * menu = guiApp->menus().menu(toqstr(cmd.argument())))
+ menu->exec(QCursor::pos());
break;
case LFUN_FILE_INSERT:
void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
{
QPoint pos = e->pos();
- Menu const & menu = buffer_view_->contextMenu(pos.x(), pos.y());
- LYXERR(Debug::GUI, "context menu resquested: " << menu.name());
-
- // FIXME: do something with GuiPopupMenu and MenuBackend.
- // Some cleanups of GuiPopupMenu and GuiMenubar are needed
- // before!
+ docstring name = buffer_view_->contextMenu(pos.x(), pos.y());
+ if (name.empty()) {
+ QAbstractScrollArea::contextMenuEvent(e);
+ return;
+ }
+ QMenu * menu = guiApp->menus().menu(toqstr(name));
+ if (!menu) {
+ QAbstractScrollArea::contextMenuEvent(e);
+ return;
+ }
+ // Position the menu to the right.
+ // FIXME: menu position should be different for RTL text.
+ pos.rx() += menu->width();
+ // FIXME: correct vertical position of the menu WRT screen espace.
+ //pos.ry() += menu->height();
+ menu->exec(pos);
QAbstractScrollArea::contextMenuEvent(e);
}
}
-void Menus::openByName(QString const & name)
+QMenu * Menus::menu(QString const & name)
{
- if (QMenu * menu = name_map_.value(name))
- menu->exec(QCursor::pos());
+ LYXERR(Debug::GUI, "Context menu requested: "
+ << qstring_to_ucs4(name));
+ GuiPopupMenu * menu = name_map_.value(name, 0);
+ if (!menu)
+ LYXERR0("resquested context menu not found: "
+ << qstring_to_ucs4(name));
+ return menu;
}
///
void fillMenuBar(GuiView * view);
- /// opens a top-level submenu given its name
- void openByName(QString const & name);
+ /// \return a top-level submenu given its name.
+ QMenu * menu(QString const & name);
/// update the state of the menuitems - not needed
void updateView();
typedef QHash<QString, GuiPopupMenu *> NameMap;
- /// name to menu for openByName
+ /// name to menu for \c menu() method.
NameMap name_map_;
};
}
+docstring Inset::contextMenu(BufferView const &, int, int) const
+{
+ return docstring();
+}
+
+
Dimension const Inset::dimension(BufferView const & bv) const
{
return bv.coordCache().getInsets().dim(this);
/// This default implementation returns an empty string.
virtual docstring toolTip(BufferView const & bv, int x, int y) const;
+ /// \return Context menu identifier for this inset.
+ /// This default implementation returns an empty string.
+ virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
+
// FIXME This should really disappear in favor of
// docstring name() const { return from_ascii(insetName(lyxCode()))); }
// There's no reason to be using different names in different places.