Item "Next Cross-Reference|N" "reference-next"
Item "Go back to Reference|G" "bookmark-goto 0"
Separator
+ Item "Copy as Reference|C" "copy-label-as-reference"
+ Separator
Item "Settings...|S" "next-inset-toggle"
End
flag.setEnabled(! this->cursor().inRegexped());
break;
+ case LFUN_COPY_LABEL_AS_REF:
+ // if there is an inset at cursor, see whether it
+ // handles the lfun, other start from scratch
+ Inset * inset = cur.nextInset();
+ if (!inset || !inset->getStatus(cur, cmd, flag))
+ flag = lyx::getStatus(cmd);
+ break;
+
case LFUN_NEXT_INSET_TOGGLE:
case LFUN_NEXT_INSET_MODIFY: {
// this is the real function we want to invoke
// turn compression on/off
buffer_.params().compressed = !buffer_.params().compressed;
break;
-
+ case LFUN_COPY_LABEL_AS_REF: {
+ // if there is an inset at cursor, try to copy it
+ Inset * inset = cur.nextInset();
+ if (inset) {
+ FuncRequest tmpcmd = cmd;
+ inset->dispatch(cur, tmpcmd);
+ }
+ if (!cur.result().dispatched())
+ // It did not work too; no action needed.
+ break;
+ cur.clearSelection();
+ processUpdateFlags(Update::SinglePar | Update::FitCursor);
+ break;
+ }
case LFUN_NEXT_INSET_TOGGLE: {
// create the the real function we want to invoke
FuncRequest tmpcmd = cmd;
}
+void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext)
+{
+ ParagraphList pars;
+ Paragraph par;
+ BufferParams const & bp = cur.buffer().params();
+ par.setLayout(bp.documentClass().plainLayout());
+ par.insertInset(0, inset, Change(Change::UNCHANGED));
+ pars.push_back(par);
+ theCuts.push(make_pair(pars, bp.documentClassPtr()));
+
+ // stuff the selection onto the X clipboard, from an explicit copy request
+ putClipboard(theCuts[0].first, theCuts[0].second, plaintext);
+}
+
namespace {
void copySelectionToStack(Cursor const & cur, CutStack & cutstack)
void cutSelection(Cursor & cur, bool doclear = true, bool realcut = true);
/// Push the current selection to the cut buffer and the system clipboard.
void copySelection(Cursor const & cur);
+///
+void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext);
/**
* Push the current selection to the cut buffer and the system clipboard.
* \param plaintext plain text version of the selection for the system
LFUN_TAB_DELETE,
LFUN_WORD_FINDADV, // Tommaso, 20081003
LFUN_REGEXP_MODE, // Tommaso, 20081003
+ LFUN_COPY_LABEL_AS_REF, // sts, 20081116
LFUN_LASTACTION // end of the table
};
*/
{ LFUN_BRANCH_DEACTIVATE, "branch-deactivate", Argument, Buffer },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_COPY_LABEL_AS_REF
+ * \li Action: Copies the label at the cursor as a cross-reference to be paster elsewhere.
+ * \li Syntax: copy-label-as-reference
+ * \li Origin: sts, 16 Nov 2008
+ * \endvar
+ */
+ { LFUN_COPY_LABEL_AS_REF, "copy-label-as-reference", ReadOnly | NoUpdate, Edit },
+
{ LFUN_NOACTION, "", Noop, Hidden }
#ifndef DOXYGEN_SHOULD_SKIP_THIS
};
#include "buffer_funcs.h"
#include "Buffer.h"
#include "BufferView.h"
+#include "CutAndPaste.h"
#include "DispatchResult.h"
#include "FuncRequest.h"
+#include "FuncStatus.h"
#include "InsetIterator.h"
#include "ParIterator.h"
#include "sgml.h"
}
+bool InsetLabel::getStatus(Cursor & cur, FuncRequest const & cmd,
+ FuncStatus & status) const
+{
+ bool enabled;
+ switch (cmd.action) {
+ case LFUN_COPY_LABEL_AS_REF:
+ enabled = true;
+ break;
+ default:
+ return InsetCommand::getStatus(cur, cmd, status);
+ }
+
+ status.setEnabled(enabled);
+ return true;
+}
+
+
void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
break;
}
+ case LFUN_COPY_LABEL_AS_REF: {
+ InsetCommandParams p(REF_CODE, "ref");
+ p["reference"] = getParam("name");
+ cap::clearSelection();
+ cap::copyInset(cur, new InsetRef(cur.buffer(), p), getParam("name"));
+ break;
+ }
+
default:
InsetCommand::doDispatch(cur, cmd);
break;
void addToToc(DocIterator const &);
///
void updateCommand(docstring const & new_label, bool updaterefs = true);
+ ///
+ bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const;
protected:
///
void doDispatch(Cursor & cur, FuncRequest & cmd);