[LyX/master] Fix bug #12181

Enrico Forestieri forenr at lyx.org
Sat Mar 6 22:34:34 UTC 2021


commit 7545698380fa4d0203109d340404574c20aad1bc
Author: Enrico Forestieri <forenr at lyx.org>
Date:   Sat Mar 6 23:36:58 2021 +0100

    Fix bug #12181
    
    The context menu for InsetMathRef is now usable.
    InsetMathRef still misses support for RefStyle and thus the
    corresponding entries are omitted from the menu. But this would
    be a different bug.
---
 lib/ui/stdcontext.inc       |   20 ++++++++++++++++++
 src/BufferView.cpp          |   10 ++++++++-
 src/mathed/InsetMathRef.cpp |   47 ++++++++++++++++++++++++++++++++-----------
 src/mathed/InsetMathRef.h   |    4 +-
 4 files changed, 66 insertions(+), 15 deletions(-)

diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc
index 238b001..115d58b 100644
--- a/lib/ui/stdcontext.inc
+++ b/lib/ui/stdcontext.inc
@@ -86,6 +86,26 @@ Menuset
 
 
 #
+# InsetMathRef context menu
+#
+	Menu "context-mathref"
+		Item "Next Cross-Reference|N" "reference-next"
+		Item "Go to Label|G" "label-goto"
+		Separator
+		Item "<Reference>|R" "inset-modify changetype ref"
+		Item "(<Reference>)|e" "inset-modify changetype eqref"
+		Item "<Page>|P" "inset-modify changetype pageref"
+		Item "On Page <Page>|O" "inset-modify changetype vpageref"
+		Item "<Reference> on Page <Page>|f" "inset-modify changetype vref"
+		Item "Formatted Reference|t" "inset-modify changetype formatted"
+		Item "Textual Reference|x" "inset-modify changetype nameref"
+		Item "Label Only|L" "inset-modify changetype labelonly"
+		Separator
+		Item "Settings...|S" "inset-settings"
+	End
+
+
+#
 # InsetRef context menu
 #
 	Menu "context-ref"
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 3abb533..29056b1 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -51,6 +51,7 @@
 #include "insets/InsetText.h"
 
 #include "mathed/InsetMathNest.h"
+#include "mathed/InsetMathRef.h"
 #include "mathed/MathData.h"
 #include "mathed/MathRow.h"
 
@@ -1244,7 +1245,8 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 
 	case LFUN_LABEL_GOTO:
 		flag.setEnabled(!cmd.argument().empty()
-		    || getInsetByCode<InsetRef>(cur, REF_CODE));
+		    || getInsetByCode<InsetRef>(cur, REF_CODE)
+		    || getInsetByCode<InsetMathRef>(cur, MATH_REF_CODE));
 		break;
 
 	case LFUN_CHANGES_MERGE:
@@ -1535,6 +1537,12 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 			// eventually call LFUN_PARAGRAPH_GOTO, but it seems best
 			// to have it here.
 			dr.screenUpdate(Update::Force | Update::FitCursor);
+		} else {
+			InsetMathRef * minset =
+				getInsetByCode<InsetMathRef>(cur, MATH_REF_CODE);
+			if (minset)
+				lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
+							minset->getTarget()));
 		}
 		break;
 	}
diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp
index 7170ca6..b70b7ea 100644
--- a/src/mathed/InsetMathRef.cpp
+++ b/src/mathed/InsetMathRef.cpp
@@ -65,10 +65,20 @@ void InsetMathRef::infoize(odocstream & os) const
 
 void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
+	// Ctrl + click: go to label
+	if (cmd.action() == LFUN_MOUSE_RELEASE && cmd.modifier() == ControlModifier) {
+		LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
+		//FIXME: use DispatchResult argument
+		lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
+		return;
+	}
+
 	switch (cmd.action()) {
-	case LFUN_INSET_MODIFY:
-		if (cmd.getArg(0) == "ref") {
-			if (cmd.getArg(1) == "changetarget") {
+	case LFUN_INSET_MODIFY: {
+		string const arg0 = cmd.getArg(0);
+		string const arg1   = cmd.getArg(1);
+		if (arg0 == "ref") {
+			if (arg1 == "changetarget") {
 				string const oldtarget = cmd.getArg(2);
 				string const newtarget = cmd.getArg(3);
 				if (!oldtarget.empty() && !newtarget.empty()
@@ -85,9 +95,20 @@ void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
 				setBuffer(buf);
 				break;
 			}
+		} else if (arg0 == "changetype") {
+			docstring const data = from_ascii(createDialogStr(arg1));
+			MathData ar;
+			if (createInsetMath_fromDialogStr(data, ar)) {
+				cur.recordUndo();
+				Buffer & buf = buffer();
+				*this = *ar[0].nucleus()->asRefInset();
+				setBuffer(buf);
+				break;
+			}
 		}
 		cur.undispatched();
 		break;
+	}
 
 	case LFUN_INSET_DIALOG_UPDATE: {
 		string const data = createDialogStr();
@@ -95,19 +116,19 @@ void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
 		break;
 	}
 
+	case LFUN_INSET_SETTINGS: {
+		string const data = createDialogStr();
+		cur.bv().showDialog("ref", data, this);
+		cur.dispatched();
+		break;
+	}
+
 	case LFUN_MOUSE_RELEASE:
 		if (cur.selection()) {
 			cur.undispatched();
 			break;
 		}
-		if (cmd.button() == mouse_button::button3) {
-			LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
-			//FIXME: use DispatchResult argument
-			lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
-			break;
-		}
 		if (cmd.button() == mouse_button::button1) {
-			// Eventually trigger dialog with button 3, not 1
 			string const data = createDialogStr();
 			cur.bv().showDialog("ref", data, this);
 			break;
@@ -144,6 +165,7 @@ bool InsetMathRef::getStatus(Cursor & cur, FuncRequest const & cmd,
 	// we handle these
 	case LFUN_INSET_MODIFY:
 	case LFUN_INSET_DIALOG_UPDATE:
+	case LFUN_INSET_SETTINGS:
 	case LFUN_MOUSE_RELEASE:
 	case LFUN_MOUSE_PRESS:
 	case LFUN_MOUSE_DOUBLE:
@@ -227,9 +249,10 @@ void InsetMathRef::updateBuffer(ParIterator const & it, UpdateType /*utype*/, bo
 }
 
 
-string const InsetMathRef::createDialogStr() const
+string const InsetMathRef::createDialogStr(string const & type) const
 {
-	InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
+	InsetCommandParams icp(REF_CODE, (type.empty()
+			?  to_ascii(commandname()) : type));
 	icp["reference"] = asString(cell(0));
 	if (!cell(1).empty())
 		icp["name"] = asString(cell(1));
diff --git a/src/mathed/InsetMathRef.h b/src/mathed/InsetMathRef.h
index 3f7a8a6..6d7f0a1 100644
--- a/src/mathed/InsetMathRef.h
+++ b/src/mathed/InsetMathRef.h
@@ -37,7 +37,7 @@ public:
 	///
 	bool clickable(BufferView const &, int, int) const override { return true; }
 	///
-	std::string contextMenuName() const override { return "context-ref"; }
+	std::string contextMenuName() const override { return "context-mathref"; }
 	///
 	mode_type currentMode() const override { return TEXT_MODE; }
 	///
@@ -56,7 +56,7 @@ public:
 	/// docbook output
 	void docbook(XMLStream &, OutputParams const &) const override;
 	/// generate something that will be understood by the Dialogs.
-	std::string const createDialogStr() const;
+	std::string const createDialogStr(std::string const & type = std::string()) const;
 
 	struct ref_type_info {
 		///


More information about the lyx-cvs mailing list