]> git.lyx.org Git - features.git/commitdiff
* "Copy as Reference" in the context menu of a label
authorStefan Schimanski <sts@lyx.org>
Sun, 16 Nov 2008 19:19:07 +0000 (19:19 +0000)
committerStefan Schimanski <sts@lyx.org>
Sun, 16 Nov 2008 19:19:07 +0000 (19:19 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27575 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ui/stdcontext.inc
src/BufferView.cpp
src/CutAndPaste.cpp
src/CutAndPaste.h
src/FuncCode.h
src/LyXAction.cpp
src/insets/InsetLabel.cpp
src/insets/InsetLabel.h

index fe682bfb1213c8db89a41d8ea1008bf59e0c960b..f9fb09c499b2fd8e09ce0a9aa778208ea50c2a9c 100644 (file)
@@ -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
 
index b463778ef31567e31ec08a0b7a50da8be749f9be..9af4bb71f0c737edd87f36bcfbc02dcc2e4e26c8 100644 (file)
@@ -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;
index f367dde1bddc742fbb5ae1272a8d970e7b260a99..22bc931e0aeb8feb6651a593a6888011baae430e 100644 (file)
@@ -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)
index a46eeb12f4b7645ae605ee551ce5a0f72d16cc48..a4e975b8a1483823c44ad6479f82fa5c4312661a 100644 (file)
@@ -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
index 456ea2d37b313938e79a50177dbfcd779bc51f58..b9c88c8b78189da6328fd054c4b1b807c7636770 100644 (file)
@@ -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
 };
index 4a309c1fedbcb6c4d89a7f9674c0d971719b503b..4b7e690691efc8c74fd4e9ac75c3d5d7ed487daa 100644 (file)
@@ -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
        };
index 0b671b2c0fd6478ac7eb0967443ae14454587932..88d2f4f6c579986851b4a112a6d75b2df4aefd10 100644 (file)
 #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;
index 75a5ed51d4955a09b71cecda3b8a10bfd0892547..92f05605790c2065cbcfa0a9739bd2daf80c38b5 100644 (file)
@@ -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);