]> git.lyx.org Git - features.git/commitdiff
New lfun to copy index insets from ToC
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 4 Nov 2022 20:52:46 +0000 (21:52 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 4 Nov 2022 20:52:46 +0000 (21:52 +0100)
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
src/FuncCode.h
src/LyXAction.cpp
src/insets/InsetIndex.cpp

index f440d98c43d85c2ebaf00c54d954405aa5705ef9..64cafd0012f57bb99a9f965e914e379de5710010 100644 (file)
@@ -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
 
index b80d37f6f7e66e74db92ed7722d215e7be26a215..3667a98c1da6bd00bc7d7aaffaefcb12d30a6f18 100644 (file)
@@ -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
 };
 
index 742c6132063cf9b670248048726416136d0efcd0..e1f91d2d89dd0f13b3eb11f1c90d5bb9b34fb804 100644 (file)
@@ -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
index b5625e81be827a8c3a09c5c74f90d9a8a77f787f..839d09472a42744375bcc4fa9264cd34e9e398d6 100644 (file)
@@ -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));