mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 10:18:50 +00:00
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
This commit is contained in:
parent
b7cf6951b6
commit
51a5db7110
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 &);
|
||||
|
@ -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())
|
||||
|
@ -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:
|
||||
///
|
||||
|
@ -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")
|
||||
|
@ -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); }
|
||||
|
Loading…
Reference in New Issue
Block a user