mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
* "Copy as Reference" in the context menu of a label
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27575 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b56f16c5be
commit
5a10add52e
@ -90,6 +90,8 @@ Menuset
|
||||
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
|
||||
|
||||
|
@ -897,6 +897,14 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
|
||||
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
|
||||
@ -1338,7 +1346,20 @@ bool BufferView::dispatch(FuncRequest const & cmd)
|
||||
// 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;
|
||||
|
@ -687,6 +687,20 @@ void copySelection(Cursor const & cur)
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
|
@ -64,6 +64,8 @@ void replaceSelection(Cursor & cur);
|
||||
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
|
||||
|
@ -412,6 +412,7 @@ enum FuncCode
|
||||
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
|
||||
};
|
||||
|
@ -3089,6 +3089,15 @@ void LyXAction::init()
|
||||
*/
|
||||
{ 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
|
||||
};
|
||||
|
@ -17,8 +17,10 @@
|
||||
#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"
|
||||
@ -133,6 +135,23 @@ void InsetLabel::addToToc(DocIterator const & cpit)
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
@ -150,6 +169,14 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
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;
|
||||
|
@ -56,6 +56,8 @@ public:
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user