mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Implement reference-to-paragraph in outliner (#1624)
This allows to insert a cross-reference to headings, figures or tables by right-clicking on the outliner item. If the item in question does not have a label yet, it is inserted.
This commit is contained in:
parent
3fe99bf6f5
commit
143e534d1e
@ -584,6 +584,8 @@ Menuset
|
|||||||
|
|
||||||
Menu "context-toc-figure"
|
Menu "context-toc-figure"
|
||||||
Item "Settings...|S" "inset-settings"
|
Item "Settings...|S" "inset-settings"
|
||||||
|
Separator
|
||||||
|
SubMenu "Insert Cross-Reference to this Item|C" "context-toc-ref-to-par"
|
||||||
End
|
End
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -600,6 +602,8 @@ Menuset
|
|||||||
|
|
||||||
Menu "context-toc-table"
|
Menu "context-toc-table"
|
||||||
Item "Settings...|S" "inset-settings"
|
Item "Settings...|S" "inset-settings"
|
||||||
|
Separator
|
||||||
|
SubMenu "Insert Cross-Reference to this Item|C" "context-toc-ref-to-par"
|
||||||
End
|
End
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -707,6 +711,18 @@ Menuset
|
|||||||
# Toc Table of Context context menu
|
# Toc Table of Context context menu
|
||||||
#
|
#
|
||||||
|
|
||||||
|
Menu "context-toc-ref-to-par"
|
||||||
|
Item "<Reference>|R" "reference-to-paragraph ref"
|
||||||
|
Item "(<Reference>)|e" "reference-to-paragraph eqref"
|
||||||
|
Item "<Page>|P" "reference-to-paragraph pageref"
|
||||||
|
Item "On Page <Page>|O" "reference-to-paragraph vpageref"
|
||||||
|
Item "<Reference> on Page <Page>|f" "reference-to-paragraph vref"
|
||||||
|
Item "Formatted Reference|t" "reference-to-paragraph formatted"
|
||||||
|
Item "Textual Reference|x" "reference-to-paragraph nameref"
|
||||||
|
Item "Label Only|L" "reference-to-paragraph labelonly"
|
||||||
|
|
||||||
|
End
|
||||||
|
|
||||||
Menu "context-toc-tableofcontents"
|
Menu "context-toc-tableofcontents"
|
||||||
Item "Promote Section|P" "outline-out"
|
Item "Promote Section|P" "outline-out"
|
||||||
Item "Demote Section|D" "outline-in"
|
Item "Demote Section|D" "outline-in"
|
||||||
@ -714,6 +730,8 @@ Menuset
|
|||||||
Item "Move Section Down|w" "outline-down"
|
Item "Move Section Down|w" "outline-down"
|
||||||
Separator
|
Separator
|
||||||
Item "Select Section|S" "section-select"
|
Item "Select Section|S" "section-select"
|
||||||
|
Separator
|
||||||
|
SubMenu "Insert Cross-Reference to this Item|C" "context-toc-ref-to-par"
|
||||||
End
|
End
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "FuncStatus.h"
|
#include "FuncStatus.h"
|
||||||
#include "LyX.h"
|
#include "LyX.h"
|
||||||
#include "Menus.h"
|
#include "Menus.h"
|
||||||
|
#include "Paragraph.h"
|
||||||
#include "TocBackend.h"
|
#include "TocBackend.h"
|
||||||
|
|
||||||
#include "insets/InsetCommand.h"
|
#include "insets/InsetCommand.h"
|
||||||
@ -180,6 +181,7 @@ bool TocWidget::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|||||||
case LFUN_OUTLINE_DOWN:
|
case LFUN_OUTLINE_DOWN:
|
||||||
case LFUN_OUTLINE_IN:
|
case LFUN_OUTLINE_IN:
|
||||||
case LFUN_OUTLINE_OUT:
|
case LFUN_OUTLINE_OUT:
|
||||||
|
case LFUN_REFERENCE_TO_PARAGRAPH:
|
||||||
case LFUN_SECTION_SELECT:
|
case LFUN_SECTION_SELECT:
|
||||||
status.setEnabled((bool)item.dit());
|
status.setEnabled((bool)item.dit());
|
||||||
return true;
|
return true;
|
||||||
@ -248,6 +250,46 @@ void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case LFUN_REFERENCE_TO_PARAGRAPH: {
|
||||||
|
docstring const type = cmd.argument();
|
||||||
|
TocItem const & item =
|
||||||
|
gui_view_.tocModels().currentItem(current_type_, index);
|
||||||
|
if (item.action().action() == LFUN_PARAGRAPH_GOTO) {
|
||||||
|
// easy case
|
||||||
|
docstring const id = item.dit().paragraphGotoArgument(true);
|
||||||
|
docstring const arg = (type.empty()) ? id : id + " " + type;
|
||||||
|
dispatch(FuncRequest(cmd, arg));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Captions etc.
|
||||||
|
// Here we cannot employ LFUN_REFERENCE_TO_PARAGRAPH
|
||||||
|
// as it won't land in the inset. Seo we do it ourselves;
|
||||||
|
// 1. save current position
|
||||||
|
lyx::dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
|
||||||
|
// go to the item
|
||||||
|
sendDispatch(item.action());
|
||||||
|
// check if it has a label
|
||||||
|
docstring label = from_utf8(cur.innerParagraph().getLabel());
|
||||||
|
if (label.empty()) {
|
||||||
|
// if not:
|
||||||
|
// insert a new label
|
||||||
|
// we do not want to open the dialog, hence we
|
||||||
|
// do not employ LFUN_LABEL_INSERT
|
||||||
|
InsetCommandParams p(LABEL_CODE);
|
||||||
|
label = cur.getPossibleLabel();
|
||||||
|
p["name"] = label;
|
||||||
|
string const data = InsetCommand::params2string(p);
|
||||||
|
lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
|
||||||
|
}
|
||||||
|
// now go back to the original position ...
|
||||||
|
lyx::dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
|
||||||
|
// ... to insert the ref
|
||||||
|
docstring const arg = (type.empty()) ? label
|
||||||
|
: label + from_ascii(" ") + type;
|
||||||
|
lyx::dispatch(FuncRequest(LFUN_REFERENCE_INSERT, arg));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case LFUN_OUTLINE_UP:
|
case LFUN_OUTLINE_UP:
|
||||||
case LFUN_OUTLINE_DOWN:
|
case LFUN_OUTLINE_DOWN:
|
||||||
case LFUN_OUTLINE_IN:
|
case LFUN_OUTLINE_IN:
|
||||||
|
Loading…
Reference in New Issue
Block a user