[LyX/master] New lfun to copy index insets from ToC
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Fri Nov 4 20:03:19 UTC 2022
commit fad170be1a6913403f200815be112a38ea9b857f
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Fri Nov 4 21:52:46 2022 +0100
New lfun to copy index insets from ToC
The new function inset-insert-copy can only be invoked from the ToC.
It is currently only implemented for Index inset.
It is a special lfun because Inset::dispatch is called directly from
the ToC widget with cursor pointing to the inset, whereas the patch
happens in the workarea at caret position. This function cannot be
called directly.
Add an entry for this function in the toc context menu.
Fixes bug #4582.
---
lib/ui/stdcontext.inc | 2 ++
src/FuncCode.h | 1 +
src/LyXAction.cpp | 8 ++++++++
src/insets/InsetIndex.cpp | 21 +++++++++++++++++++--
4 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc
index f440d98..64cafd0 100644
--- a/lib/ui/stdcontext.inc
+++ b/lib/ui/stdcontext.inc
@@ -621,6 +621,8 @@ Menuset
#
Menu "context-toc-index"
+ OptItem "Insert Copy at Cursor Position|I" "inset-insert-copy"
+ Separator
OptItem "Settings...|S" "inset-settings"
End
diff --git a/src/FuncCode.h b/src/FuncCode.h
index b80d37f..3667a98 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -502,6 +502,7 @@ enum FuncCode
LFUN_SPELLING_REMOVE_LOCAL, // jspitzm 20210307
LFUN_BRANCH_SYNC_ALL, // sanda 20220415
LFUN_INDEXMACRO_INSERT, // spitz 20220220
+ LFUN_INSET_INSERT_COPY, // spitz 20221101
LFUN_LASTACTION // end of the table
};
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 742c613..e1f91d2 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -2070,6 +2070,14 @@ void LyXAction::init()
*/
{ LFUN_INSET_COPY_AS, "inset-copy-as", ReadOnly | NoUpdate | AtPoint, Edit },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_INSET_INSERT_COPY
+ * \li Action: Inserts the inset's content (in ToC pane) at the position of the cursor.
+ * \li Syntax: inset-insert-copy
+ * \li Origin: spitz, 1 Nov 2022
+ * \endvar
+ */
+ { LFUN_INSET_INSERT_COPY, "inset-insert-copy", Noop, Edit},
/*!
* \var lyx::FuncCode lyx::LFUN_INSET_DIALOG_UPDATE
diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp
index b5625e8..839d094 100644
--- a/src/insets/InsetIndex.cpp
+++ b/src/insets/InsetIndex.cpp
@@ -18,6 +18,7 @@
#include "BufferView.h"
#include "ColorSet.h"
#include "Cursor.h"
+#include "CutAndPaste.h"
#include "DispatchResult.h"
#include "Encoding.h"
#include "ErrorList.h"
@@ -621,6 +622,16 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
break;
}
+ case LFUN_INSET_INSERT_COPY: {
+ Cursor & bvcur = cur.bv().cursor();
+ if (cmd.origin() == FuncRequest::TOC && bvcur.inTexted()) {
+ cap::copyInsetToTemp(cur, clone());
+ cap::pasteFromTemp(bvcur, bvcur.buffer()->errorList("Paste"));
+ } else
+ cur.undispatched();
+ break;
+ }
+
default:
InsetCollapsible::doDispatch(cur, cmd);
break;
@@ -668,10 +679,16 @@ bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
flag.setEnabled(realbuffer.params().use_indices);
return true;
}
-
+
+ case LFUN_INSET_INSERT_COPY:
+ // This can only be invoked by ToC widget
+ flag.setEnabled(cmd.origin() == FuncRequest::TOC
+ && cur.bv().cursor().inset().insetAllowed(lyxCode()));
+ return true;
+
case LFUN_PARAGRAPH_BREAK:
return macrosPossible("subentry");
-
+
case LFUN_INDEXMACRO_INSERT:
return macrosPossible(cmd.getArg(0));
More information about the lyx-cvs
mailing list