]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBibitem.cpp
Whitespace.
[lyx.git] / src / insets / InsetBibitem.cpp
index eb8e1c7c7751c881ebd8f9dfb213a76f87b68d4c..a05b21d28b00deb14564f7e11247a629fd7abceb 100644 (file)
@@ -25,7 +25,7 @@
 #include "FuncRequest.h"
 #include "InsetIterator.h"
 #include "InsetList.h"
-#include "Language.h" 
+#include "Language.h"
 #include "Lexer.h"
 #include "output_xhtml.h"
 #include "OutputParams.h"
@@ -122,6 +122,9 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cur.noScreenUpdate();
                        break;
                }
+
+               cur.recordUndo();
+
                docstring const & old_key = params()["key"];
                docstring const & old_label = params()["label"];
                docstring label = p["label"];
@@ -163,12 +166,12 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
                                                if (label[previous] != '{')
                                                        label.replace(pos, 1, lbrace + brackets_escape[k] + rbrace);
                                }
+               }
 
-                       if (old_label != label) {
-                               p["label"] = label;
-                               cur.forceBufferUpdate();
-                               buffer().invalidateBibinfoCache();
-                       }
+               if (old_label != label) {
+                       p["label"] = label;
+                       cur.forceBufferUpdate();
+                       buffer().invalidateBibinfoCache();
                }
 
                setParam("label", p["label"]);
@@ -288,35 +291,27 @@ docstring bibitemWidest(Buffer const & buffer, OutputParams const & runparams)
        }
 
        if (!lbl.empty()) {
-               docstring latex_lbl;
-               for (size_t n = 0; n < lbl.size(); ++n) {
-                       try {
-                               latex_lbl += runparams.encoding->latexChar(lbl[n]);
-                       } catch (EncodingException & /* e */) {
-                               if (runparams.dryrun) {
-                                       latex_lbl += "<" + _("LyX Warning: ")
-                                                 + _("uncodable character") + " '";
-                                       latex_lbl += docstring(1, lbl[n]);
-                                       latex_lbl += "'>";
-                               }
-                       }
-               }
-               return latex_lbl;
+               pair<docstring, docstring> latex_lbl =
+                       runparams.encoding->latexString(lbl, runparams.dryrun);
+               return latex_lbl.first;
        }
 
        return from_ascii("99");
 }
 
 
-void InsetBibitem::fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const
+void InsetBibitem::collectBibKeys(InsetIterator const & it) const
 {
        docstring const key = getParam("key");
+       docstring const label = getParam("label");
        BibTeXInfo keyvalmap(false);
-       keyvalmap.label(bibLabel());
-       DocIterator doc_it(it); 
+       keyvalmap.key(key);
+       keyvalmap.label(label);
+       DocIterator doc_it(it);
        doc_it.forwardPos();
-       keyvalmap[from_ascii("ref")] = doc_it.paragraph().asString();
-       keys[key] = keyvalmap;
+       keyvalmap[from_ascii("ref")] = doc_it.paragraph().asString(
+               AS_STR_INSETS | AS_STR_SKIPDELETE);
+       buffer().addBibTeXInfo(key, keyvalmap);
 }
 
 
@@ -326,8 +321,9 @@ void InsetBibitem::updateBuffer(ParIterator const & it, UpdateType utype)
        BufferParams const & bp = buffer().masterBuffer()->params();
        Counters & counters = bp.documentClass().counters();
        docstring const bibitem = from_ascii("bibitem");
-       if (counters.hasCounter(bibitem) && getParam("label").empty()) {
-               counters.step(bibitem, utype);
+       if (getParam("label").empty()) {
+               if (counters.hasCounter(bibitem))
+                       counters.step(bibitem, utype);
                string const & lang = it.paragraph().getParLanguage(bp)->code();
                autolabel_ = counters.theCounter(bibitem, lang);
        } else {
@@ -344,7 +340,8 @@ docstring InsetBibitem::xhtml(XHTMLStream & xs, OutputParams const &) const
        // need to use "name" anyway, eventually, because some browsers do not
        // handle jumping to ids. If we don't do that, though, we can just put the
        // id into the span tag.
-       string const attrs = "id='" + to_utf8(getParam("label")) + "'";
+       string const attrs =
+               "id='LyXCite-" + to_utf8(html::cleanAttr(getParam("key"))) + "'";
        xs << html::CompTag("a", attrs);
        xs << html::StartTag("span", "class='bibitemlabel'");
        xs << bibLabel();