commit 5a43b86141a6630ff87b9f5fdba94187e282d1fe
Author: Enrico Forestieri <[email protected]>
Date: Fri Mar 5 21:21:41 2021 +0100
Allow context menus in mathed
It is now possible to get a context menu for math insets.
InsetMathSpace was already providing a specific context menu,
but it was never triggered because the math hull inset is not
descendable. It is still so, but now when a context menu is
requested all the insets inside the math hull are examined.
If the inset under the cursor provides a context menu, it
is shown instead of the general math one.
Fixes #12100.
---
src/BufferView.cpp | 44 +++++++++++++++++++++++++++++++++++++++++-
src/BufferView.h | 6 ++++-
src/mathed/InsetMathRef.h | 6 +++++
src/mathed/InsetMathSpace.h | 2 +
4 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 295b983..3abb533 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -50,7 +50,7 @@
#include "insets/InsetRef.h"
#include "insets/InsetText.h"
-#include "mathed/InsetMath.h"
+#include "mathed/InsetMathNest.h"
#include "mathed/MathData.h"
#include "mathed/MathRow.h"
@@ -669,13 +669,53 @@ string 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)
+ if (covering_inset) {
+ if (covering_inset->asInsetMath()) {
+ CoordCache::Insets const & inset_cache =
+ coordCache().getInsets();
+ Inset const * inner_inset = mathContextMenu(
+ covering_inset->asInsetMath()->asNestInset(),
+ inset_cache, x, y);
+ if (inner_inset)
+ return inner_inset->contextMenu(*this, x, y);
+ }
return covering_inset->contextMenu(*this, x, y);
+ }
return buffer_.inset().contextMenu(*this, x, y);
}
+Inset const * BufferView::mathContextMenu(InsetMathNest const * inset,
+ CoordCache::Insets const & inset_cache, int x, int y) const
+{
+ for (size_t i = 0; i < inset->nargs(); ++i) {
+ MathData const & ar = inset->cell(i);
+ for (size_t j = 0; j < ar.size(); ++j) {
+ string const name = lyxerr.debugging(Debug::MATHED)
+ ? insetName(ar[j].nucleus()->lyxCode())
+ : string();
+ LYXERR(Debug::MATHED, "Examining inset: " << name);
+ if (!ar[j].nucleus()->contextMenuName().empty()) {
+ if (inset_cache.covers(ar[j].nucleus(), x, y)) {
+ LYXERR(Debug::MATHED, "Hit inset: "
+ << name);
+ return ar[j].nucleus();
+ }
+ }
+ InsetMathNest const * imn =
+ ar[j].nucleus()->asNestInset();
+ if (imn) {
+ Inset const * inner =
+ mathContextMenu(imn, inset_cache, x, y);
+ if (inner)
+ return inner;
+ }
+ }
+ }
+ return nullptr;
+}
+
void BufferView::scrollDocView(int const pixels, bool update)
{
diff --git a/src/BufferView.h b/src/BufferView.h
index 830c2d7..ab5ba60 100644
--- a/src/BufferView.h
+++ b/src/BufferView.h
@@ -15,6 +15,7 @@
#ifndef BUFFER_VIEW_H
#define BUFFER_VIEW_H
+#include "CoordCache.h"
#include "DocumentClassPtr.h"
#include "TexRow.h"
#include "update_flags.h"
@@ -32,7 +33,6 @@ namespace frontend { class GuiBufferViewDelegate; }
class Buffer;
class Change;
-class CoordCache;
class Cursor;
class CursorSlice;
class Dimension;
@@ -42,6 +42,7 @@ class FuncRequest;
class FuncStatus;
class Intl;
class Inset;
+class InsetMathNest;
class Length;
class MathData;
class MathRow;
@@ -160,6 +161,9 @@ public:
docstring toolTip(int x, int y) const;
/// \return the context menu for the given position.
std::string contextMenu(int x, int y) const;
+ /// \return the math inset with a context menu for the given position
+ Inset const * mathContextMenu(InsetMathNest const * inset,
+ CoordCache::Insets const & inset_cache, int x, int y) const;
/// Save the current position as bookmark.
/// if idx == 0, save to temp_bookmark
diff --git a/src/mathed/InsetMathRef.h b/src/mathed/InsetMathRef.h
index 5527a0d..3f7a8a6 100644
--- a/src/mathed/InsetMathRef.h
+++ b/src/mathed/InsetMathRef.h
@@ -33,6 +33,12 @@ public:
///
void infoize(odocstream & os) const override;
///
+ bool hasSettings() const override { return true; }
+ ///
+ bool clickable(BufferView const &, int, int) const override { return
true; }
+ ///
+ std::string contextMenuName() const override { return "context-ref"; }
+ ///
mode_type currentMode() const override { return TEXT_MODE; }
///
bool lockedMode() const override { return true; }
diff --git a/src/mathed/InsetMathSpace.h b/src/mathed/InsetMathSpace.h
index 283237d..9612172 100644
--- a/src/mathed/InsetMathSpace.h
+++ b/src/mathed/InsetMathSpace.h
@@ -62,6 +62,8 @@ public:
///
bool hasSettings() const override { return true; }
///
+ bool clickable(BufferView const &, int, int) const override { return
true; }
+ ///
std::string contextMenuName() const override;
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const
override;
--
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs