#include "BufferView.h"
#include "ColorSet.h"
#include "Cursor.h"
+#include "CutAndPaste.h"
#include "DispatchResult.h"
#include "Encoding.h"
#include "ErrorList.h"
{
OutputParams runparams(runparams_in);
runparams.inIndexEntry = true;
+ if (runparams_in.postpone_fragile_stuff)
+ // This is not needed and would impact sorting
+ runparams.moving_arg = false;
otexstringstream os;
// Handle primary, secondary, and tertiary terms (entries, subentries, and subsubentries, for LaTeX).
vector<docstring> terms;
- if (const vector<docstring> potential_terms = getSubentriesAsText(runparams); !potential_terms.empty()) {
+ const vector<docstring> potential_terms = getSubentriesAsText(runparams);
+ if (!potential_terms.empty()) {
terms = potential_terms;
// The main term is not present in the vector, as it's not a subentry. The main index term is inserted raw in
// the index inset. Considering that the user either uses the new or the legacy mechanism, the main term is the
params_.index = from_utf8(cmd.getArg(1));
break;
}
+ if (cmd.getArg(0) == "changeparam") {
+ string const p = cmd.getArg(1);
+ string const v = cmd.getArg(2);
+ cur.recordUndoInset(this);
+ if (p == "range")
+ params_.range = insetindexpagerangetranslator().find(v);
+ if (p == "pagefmt") {
+ if (v == "default" || v == "textbf"
+ || v == "textit" || v == "emph")
+ params_.pagefmt = v;
+ else
+ lyx::dispatch(FuncRequest(LFUN_INSET_SETTINGS, "index"));
+ }
+ break;
+ }
InsetIndexParams params;
InsetIndex::string2params(to_utf8(cmd.argument()), params);
cur.recordUndoInset(this);
break;
}
+ case LFUN_INSET_INSERT_COPY: {
+ Cursor & bvcur = cur.bv().cursor();
+ if (cmd.origin() == FuncRequest::TOC && bvcur.inTexted()) {
+ cap::copyInsetToTemp(cur, clone());
+ cap::pasteFromTemp(bvcur, bvcur.buffer()->errorList("Paste"));
+ } else
+ cur.undispatched();
+ break;
+ }
+
default:
InsetCollapsible::doDispatch(cur, cmd);
break;
from_utf8(cmd.getArg(1)) == params_.index);
return true;
}
+ if (cmd.getArg(0) == "changeparam") {
+ string const p = cmd.getArg(1);
+ string const v = cmd.getArg(2);
+ if (p == "range") {
+ flag.setEnabled(v == "none" || v == "start" || v == "end");
+ flag.setOnOff(params_.range == insetindexpagerangetranslator().find(v));
+ }
+ if (p == "pagefmt") {
+ flag.setEnabled(!v.empty());
+ if (params_.pagefmt == "default" || params_.pagefmt == "textbf"
+ || params_.pagefmt == "textit" || params_.pagefmt == "emph")
+ flag.setOnOff(params_.pagefmt == v);
+ else
+ flag.setOnOff(v == "custom");
+ }
+ return true;
+ }
return InsetCollapsible::getStatus(cur, cmd, flag);
case LFUN_INSET_DIALOG_UPDATE: {
flag.setEnabled(realbuffer.params().use_indices);
return true;
}
-
+
+ case LFUN_INSET_INSERT_COPY:
+ // This can only be invoked by ToC widget
+ flag.setEnabled(cmd.origin() == FuncRequest::TOC
+ && cur.bv().cursor().inset().insetAllowed(lyxCode()));
+ return true;
+
case LFUN_PARAGRAPH_BREAK:
return macrosPossible("subentry");
-
+
case LFUN_INDEXMACRO_INSERT:
return macrosPossible(cmd.getArg(0));
+ case LFUN_INDEX_TAG_ALL:
+ return true;
+
default:
return InsetCollapsible::getStatus(cur, cmd, flag);
}
private:
bool isModern()
{
+#ifdef LYX_INSET_INDEX_DEBUG
std::cout << to_utf8(entry_) << std::endl;
+#endif // LYX_INSET_INDEX_DEBUG
// If a modern parameter is present, this is definitely a modern index inset. Similarly, if it contains the
// usual LaTeX symbols (!|@), then it is definitely a legacy index inset. Otherwise, if it has features of
void insertIntoNode(const IndexEntry& entry, IndexNode* node, unsigned depth = 0)
{
+ // Do not insert empty entries.
+ if (entry.terms().empty())
+ return;
+
// depth == 0 is for the root, not yet the index, hence the increase when going to vector size.
for (IndexNode* child : node->children) {
if (entry.terms()[depth] == termAtLevel(child, depth)) {
if (depth + 1 == entry.terms().size()) { // == child.entries.begin()->terms().size()
// All term entries match: it's an entry.
- child->entries.emplace_back(entry);
+ if (!entry.terms()[depth].empty())
+ child->entries.emplace_back(entry);
return;
} else {
insertIntoNode(entry, child, depth + 1);
xs << xml::StartTag("li", "class='" + generateCssClassAtDepth(depth) + "'");
xs << xml::CR();
- xs << XMLStream::ESCAPE_NONE << termAtLevel(root_node, depth);
+ xs << termAtLevel(root_node, depth);
// By tree assumption, all the entries at this node have the same set of terms.
if (!root_node->entries.empty()) {
}
entry_number += 1;
}
+ xs << xml::CR();
}
if (!root_node->entries.empty() && !root_node->children.empty()) {