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.
This commit is contained in:
Enrico Forestieri 2021-03-06 23:36:58 +01:00
parent 5d269df606
commit 7545698380
4 changed files with 66 additions and 15 deletions

View File

@ -85,6 +85,26 @@ Menuset
End
#
# 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
#

View File

@ -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;
}

View File

@ -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));

View File

@ -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 {
///