]> git.lyx.org Git - lyx.git/commitdiff
Add "Copy label as reference" to context menu of the TOC.
authorVincent van Ravesteijn <vfr@lyx.org>
Wed, 8 Apr 2009 21:40:42 +0000 (21:40 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Wed, 8 Apr 2009 21:40:42 +0000 (21:40 +0000)
(Note: it is not perfect yet for references in the same model as the labels).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29156 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ui/stdcontext.inc
src/frontends/qt4/TocModel.cpp
src/frontends/qt4/TocModel.h
src/frontends/qt4/TocWidget.cpp

index 552d54b11595f9a8bc71d35bae8cfad9abdb62ea..21215af4a291167a35fa3cdf8684868fddef5465 100644 (file)
@@ -413,4 +413,12 @@ Menuset
                OptItem "Settings...|S" "inset-settings"
        End
 
+#
+# InsetTocLabel context menu
+#
+
+       Menu "context-toc-label"
+               Item "Copy Label as Reference|C" "copy-label-as-reference"
+       End
+
 End
index 1301e8d1747b394a2fc59bfb73f08d5f9d4ca994..a78f2ae325f1c3de8a1b0d6517c5ee72a5b19a2e 100644 (file)
@@ -299,6 +299,20 @@ void TocModels::goTo(QString const & type, QModelIndex const & index) const
 }
 
 
+TocItem const TocModels::currentItem(QString const & type,
+       QModelIndex const & index) const
+{
+       const_iterator it = models_.find(type);
+       if (it == models_.end() || !index.isValid()) {
+               LYXERR(Debug::GUI, "TocModels::currentItem(): QModelIndex is invalid!");
+               return TocItem();
+       }
+       LASSERT(index.model() == it.value()->model(), return TocItem());
+       
+       return it.value()->tocItem(index);
+}
+
 void TocModels::updateBackend() const
 {
        bv_->buffer().masterBuffer()->tocBackend().update();
index c8c8c46bf42d309c11d3ea0295b7539a37a8e0ae..bc479c7de13044be924952f0dae059c2c1e3682c 100644 (file)
@@ -118,6 +118,9 @@ public:
        void sort(QString const & type, bool sort_it);
        ///
        bool isSorted(QString const & type) const;
+       /// the item that is currently selected
+       TocItem const currentItem(QString const & type,
+               QModelIndex const & index) const;
 
 Q_SIGNALS:
        /// Signal that the internal toc_models_ has been reset.
index 59bd1df43676f0870b1925a10f8f6e0b9b6d8c05..7c985d4d9e293cb64314bc46b7dbe6a2d45d629f 100644 (file)
 #include "TocModel.h"
 
 #include "Buffer.h"
+#include "CutAndPaste.h"
 #include "FuncRequest.h"
 #include "LyXFunc.h"
 #include "Menus.h"
+#include "TocBackend.h"
+
+#include "insets/InsetCommand.h"
+#include "insets/InsetRef.h"
 
 #include "support/debug.h"
 #include "support/lassert.h"
@@ -93,6 +98,19 @@ void TocWidget::showContextMenu(const QPoint & pos)
 void TocWidget::doDispatch(Cursor const & cur, FuncRequest const & cmd)
 {
        switch(cmd.action) {
+       case LFUN_COPY_LABEL_AS_REF: {
+               QModelIndex index = tocTV->currentIndex();
+               TocItem const & item = 
+                       gui_view_.tocModels().currentItem(current_type_, index);
+               if (!item.str().empty()) {
+                       InsetCommandParams p(REF_CODE, "ref");
+                       p["reference"] =  item.str();
+                       cap::clearSelection();
+                       cap::copyInset(cur, new InsetRef(*cur.buffer(), p), item.str());
+               }
+               break;
+       }
+
        default:
                break;
        }