mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Add "Copy label as reference" to context menu of the TOC.
(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
This commit is contained in:
parent
a465fcb55e
commit
695870771f
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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.
|
||||
|
@ -19,9 +19,14 @@
|
||||
#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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user