]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetIndex.cpp
Allow removing words from the personal dictionary, that weren't previously added.
[features.git] / src / insets / InsetIndex.cpp
index c7a95f3f44e6b145425ba149ec92c06ea22c23a2..f40ba031fcca8bf7b88f223e34eecc7f129a3c90 100644 (file)
@@ -18,6 +18,7 @@
 #include "BufferView.h"
 #include "ColorSet.h"
 #include "Cursor.h"
+#include "CutAndPaste.h"
 #include "DispatchResult.h"
 #include "Encoding.h"
 #include "ErrorList.h"
@@ -132,6 +133,9 @@ void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) cons
 {
        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;
 
@@ -369,7 +373,8 @@ void InsetIndex::docbook(XMLStream & xs, OutputParams const & runparams) const
 
        // 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
@@ -579,6 +584,21 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
                        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);
@@ -603,6 +623,16 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
                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;
@@ -626,6 +656,23 @@ bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
                                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: {
@@ -633,13 +680,22 @@ bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
                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);
        }
@@ -1393,7 +1449,9 @@ public:
 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
@@ -1621,12 +1679,17 @@ docstring termAtLevel(const IndexNode* node, unsigned depth)
 
 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);
@@ -1672,7 +1735,7 @@ void outputIndexPage(XMLStream & xs, const IndexNode* root_node, unsigned depth
 
        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()) {
@@ -1725,6 +1788,7 @@ void outputIndexPage(XMLStream & xs, const IndexNode* root_node, unsigned depth
                        }
                        entry_number += 1;
                }
+               xs << xml::CR();
        }
 
        if (!root_node->entries.empty() && !root_node->children.empty()) {