#include "BiblioInfo.h"
#include "Buffer.h"
+#include "Cursor.h"
#include "buffer_funcs.h"
#include "BufferParams.h"
#include "BufferView.h"
InsetBibitem::InsetBibitem(Buffer * buf, InsetCommandParams const & p)
- : InsetCommand(buf, p, "bibitem")
+ : InsetCommand(buf, p)
{
- buffer_->invalidateBibinfoCache();
+ buffer().invalidateBibinfoCache();
if (getParam("key").empty())
setParam("key", key_prefix + convert<docstring>(++key_counter));
}
InsetBibitem::~InsetBibitem()
{
if (isBufferLoaded())
- buffer_->invalidateBibinfoCache();
+ buffer().invalidateBibinfoCache();
}
"it will be changed to %2$s."), new_key, key));
}
setParam("key", key);
+ buffer().invalidateBibinfoCache();
}
case LFUN_INSET_MODIFY: {
InsetCommandParams p(BIBITEM_CODE);
- InsetCommand::string2params("bibitem", to_utf8(cmd.argument()), p);
+ InsetCommand::string2params(to_utf8(cmd.argument()), p);
if (p.getCmdName().empty()) {
cur.noScreenUpdate();
break;
}
+
+ cur.recordUndo();
+
docstring const & old_key = params()["key"];
+ docstring const & old_label = params()["label"];
+ docstring label = p["label"];
+
+ // definitions for escaping
+ int previous;
+ static docstring const backslash = from_ascii("\\");
+ static docstring const lbrace = from_ascii("{");
+ static docstring const rbrace = from_ascii("}");
+ static char_type const chars_escape[6] = {
+ '&', '_', '$', '%', '#', '^'};
+ static char_type const brackets_escape[2] = {'[', ']'};
+
+ if (!label.empty()) {
+ // The characters in chars_name[] need to be changed to a command when
+ // they are in the name field.
+ for (int k = 0; k < 6; k++)
+ for (size_t i = 0, pos;
+ (pos = label.find(chars_escape[k], i)) != string::npos;
+ i = pos + 2) {
+ if (pos == 0)
+ previous = 0;
+ else
+ previous = pos - 1;
+ // only if not already escaped
+ if (label[previous] != '\\')
+ label.replace(pos, 1, backslash + chars_escape[k] + lbrace + rbrace);
+ }
+ // The characters '[' and ']' need to be put into braces
+ for (int k = 0; k < 2; k++)
+ for (size_t i = 0, pos;
+ (pos = label.find(brackets_escape[k], i)) != string::npos;
+ i = pos + 2) {
+ if (pos == 0)
+ previous = 0;
+ else
+ previous = pos - 1;
+ // only if not already escaped
+ if (label[previous] != '{')
+ label.replace(pos, 1, lbrace + brackets_escape[k] + rbrace);
+ }
+
+ if (old_label != label) {
+ p["label"] = label;
+ cur.forceBufferUpdate();
+ buffer().invalidateBibinfoCache();
+ }
+ }
+
setParam("label", p["label"]);
if (p["key"] != old_key) {
updateCommand(p["key"]);
cur.bv().buffer().changeRefsIfUnique(old_key,
params()["key"], CITE_CODE);
cur.forceBufferUpdate();
- buffer_->invalidateBibinfoCache();
+ buffer().invalidateBibinfoCache();
}
break;
}
}
-void InsetBibitem::fillWithBibKeys(BiblioInfo & keys) const
+void InsetBibitem::collectBibKeys(InsetIterator const & it) const
{
docstring const key = getParam("key");
- // false means it's not BibTeX
BibTeXInfo keyvalmap(false);
keyvalmap.label(bibLabel());
- // The indirection here is a little annoying, but
- // DocIterator(Buffer *, Inset *)
- // is private.
- InsetBibitem & me = const_cast<InsetBibitem &>(*this);
- InsetIterator it(me);
DocIterator doc_it(it);
doc_it.forwardPos();
keyvalmap[from_ascii("ref")] = doc_it.paragraph().asString();
- keys[key] = keyvalmap;
+ buffer().addBibTeXInfo(key, keyvalmap);
}
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 {
// 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("key")) + "'";
+ string const attrs = "id='" + to_utf8(getParam("label")) + "'";
xs << html::CompTag("a", attrs);
xs << html::StartTag("span", "class='bibitemlabel'");
xs << bibLabel();