Changeset 27575

Show
Ignore:
Timestamp:
11/16/08 20:19:07 (2 months ago)
Author:
sts
Message:

* "Copy as Reference" in the context menu of a label

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lyx-devel/trunk/lib/ui/stdcontext.inc

    r27136 r27575  
    9090                Item "Next Cross-Reference|N" "reference-next" 
    9191                Item "Go back to Reference|G" "bookmark-goto 0" 
     92                Separator 
     93                Item "Copy as Reference|C" "copy-label-as-reference" 
    9294                Separator 
    9395                Item "Settings...|S" "next-inset-toggle" 
  • lyx-devel/trunk/src/BufferView.cpp

    r27562 r27575  
    898898                break; 
    899899 
     900        case LFUN_COPY_LABEL_AS_REF: 
     901                // if there is an inset at cursor, see whether it 
     902                // handles the lfun, other start from scratch 
     903                Inset * inset = cur.nextInset(); 
     904                if (!inset || !inset->getStatus(cur, cmd, flag)) 
     905                        flag = lyx::getStatus(cmd); 
     906                break; 
     907 
    900908        case LFUN_NEXT_INSET_TOGGLE:  
    901909        case LFUN_NEXT_INSET_MODIFY: { 
     
    13391347                buffer_.params().compressed = !buffer_.params().compressed; 
    13401348                break; 
    1341          
     1349        case LFUN_COPY_LABEL_AS_REF: { 
     1350                // if there is an inset at cursor, try to copy it 
     1351                Inset * inset = cur.nextInset(); 
     1352                if (inset) { 
     1353                        FuncRequest tmpcmd = cmd; 
     1354                        inset->dispatch(cur, tmpcmd); 
     1355                } 
     1356                if (!cur.result().dispatched()) 
     1357                        // It did not work too; no action needed. 
     1358                        break; 
     1359                cur.clearSelection(); 
     1360                processUpdateFlags(Update::SinglePar | Update::FitCursor); 
     1361                break; 
     1362        } 
    13421363        case LFUN_NEXT_INSET_TOGGLE: { 
    13431364                // create the the real function we want to invoke 
  • lyx-devel/trunk/src/CutAndPaste.cpp

    r27562 r27575  
    688688 
    689689 
     690void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext) 
     691{ 
     692        ParagraphList pars; 
     693        Paragraph par; 
     694        BufferParams const & bp = cur.buffer().params(); 
     695        par.setLayout(bp.documentClass().plainLayout()); 
     696        par.insertInset(0, inset, Change(Change::UNCHANGED)); 
     697        pars.push_back(par); 
     698        theCuts.push(make_pair(pars, bp.documentClassPtr())); 
     699 
     700        // stuff the selection onto the X clipboard, from an explicit copy request 
     701        putClipboard(theCuts[0].first, theCuts[0].second, plaintext); 
     702} 
     703 
    690704namespace { 
    691705 
  • lyx-devel/trunk/src/CutAndPaste.h

    r27425 r27575  
    6565/// Push the current selection to the cut buffer and the system clipboard. 
    6666void copySelection(Cursor const & cur); 
     67/// 
     68void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext); 
    6769/** 
    6870 * Push the current selection to the cut buffer and the system clipboard. 
  • lyx-devel/trunk/src/FuncCode.h

    r27518 r27575  
    413413        LFUN_WORD_FINDADV,               // Tommaso, 20081003 
    414414        LFUN_REGEXP_MODE,                // Tommaso, 20081003 
     415        LFUN_COPY_LABEL_AS_REF,          // sts, 20081116 
    415416 
    416417        LFUN_LASTACTION                  // end of the table 
  • lyx-devel/trunk/src/LyXAction.cpp

    r27572 r27575  
    30903090                { LFUN_BRANCH_DEACTIVATE, "branch-deactivate", Argument, Buffer }, 
    30913091 
     3092/*! 
     3093 * \var lyx::FuncCode lyx::LFUN_COPY_LABEL_AS_REF 
     3094 * \li Action: Copies the label at the cursor as a cross-reference to be paster elsewhere. 
     3095 * \li Syntax: copy-label-as-reference 
     3096 * \li Origin: sts, 16 Nov 2008 
     3097 * \endvar 
     3098 */ 
     3099                { LFUN_COPY_LABEL_AS_REF, "copy-label-as-reference", ReadOnly | NoUpdate, Edit }, 
     3100 
    30923101                { LFUN_NOACTION, "", Noop, Hidden } 
    30933102#ifndef DOXYGEN_SHOULD_SKIP_THIS 
  • lyx-devel/trunk/src/insets/InsetLabel.cpp

    r27562 r27575  
    1818#include "Buffer.h" 
    1919#include "BufferView.h" 
     20#include "CutAndPaste.h" 
    2021#include "DispatchResult.h" 
    2122#include "FuncRequest.h" 
     23#include "FuncStatus.h" 
    2224#include "InsetIterator.h" 
    2325#include "ParIterator.h" 
     
    131133                toc.push_back(TocItem(ref_pit, 1, it->first->screenLabel())); 
    132134        } 
     135} 
     136 
     137 
     138bool InsetLabel::getStatus(Cursor & cur, FuncRequest const & cmd, 
     139                           FuncStatus & status) const 
     140{ 
     141        bool enabled; 
     142        switch (cmd.action) { 
     143        case LFUN_COPY_LABEL_AS_REF: 
     144                enabled = true; 
     145                break; 
     146        default: 
     147                return InsetCommand::getStatus(cur, cmd, status); 
     148        } 
     149 
     150        status.setEnabled(enabled); 
     151        return true; 
    133152} 
    134153 
     
    151170        } 
    152171 
     172        case LFUN_COPY_LABEL_AS_REF: { 
     173                InsetCommandParams p(REF_CODE, "ref"); 
     174                p["reference"] = getParam("name"); 
     175                cap::clearSelection(); 
     176                cap::copyInset(cur, new InsetRef(cur.buffer(), p), getParam("name")); 
     177                break; 
     178        } 
     179 
    153180        default: 
    154181                InsetCommand::doDispatch(cur, cmd); 
  • lyx-devel/trunk/src/insets/InsetLabel.h

    r27425 r27575  
    5757        /// 
    5858        void updateCommand(docstring const & new_label, bool updaterefs = true); 
     59        /// 
     60        bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const; 
    5961protected: 
    6062        ///