#include "InsetLabel.h"
+#include "InsetRef.h"
+
#include "Buffer.h"
#include "BufferView.h"
#include "DispatchResult.h"
#include "FuncRequest.h"
-#include "InsetList.h"
-#include "Text.h"
-#include "Paragraph.h"
+#include "InsetIterator.h"
#include "ParIterator.h"
#include "sgml.h"
+#include "Text.h"
+#include "TocBackend.h"
+
+#include "frontends/alert.h"
-#include "support/lstrings.h"
#include "support/lyxalgo.h"
-#include "support/std_ostream.h"
+#include "support/gettext.h"
+#include "support/lstrings.h"
+using namespace std;
+using namespace lyx::support;
namespace lyx {
-using support::escape;
-
-using std::string;
-using std::ostream;
-using std::vector;
-
InsetLabel::InsetLabel(InsetCommandParams const & p)
: InsetCommand(p, "label")
{}
-std::auto_ptr<Inset> InsetLabel::doClone() const
+ParamInfo const & InsetLabel::findInfo(string const & /* cmdName */)
{
- return std::auto_ptr<Inset>(new InsetLabel(params()));
+ static ParamInfo param_info_;
+ if (param_info_.empty()) {
+ param_info_.add("name", ParamInfo::LATEX_REQUIRED);
+ }
+ return param_info_;
}
-void InsetLabel::getLabelList(Buffer const &, std::vector<docstring> & list) const
+void InsetLabel::getLabelList(vector<docstring> & list) const
{
list.push_back(getParam("name"));
}
-docstring const InsetLabel::getScreenLabel(Buffer const &) const
+docstring InsetLabel::screenLabel() const
{
return getParam("name");
}
+void InsetLabel::updateLabels(ParIterator const & it)
+{
+ docstring const & label = getParam("name");
+ if (buffer().insetLabel(label))
+ // Problem: We already have an InsetLabel with the same name!
+ return;
+ buffer().setInsetLabel(label, this);
+}
+
+
+void InsetLabel::addToToc(ParConstIterator const & cpit) const
+{
+ docstring const & label = getParam("name");
+ Toc & toc = buffer().tocBackend().toc("label");
+ if (buffer().insetLabel(label) != this) {
+ toc.push_back(TocItem(cpit, 0, _("DUPLICATE: ") + label));
+ return;
+ }
+ toc.push_back(TocItem(cpit, 0, label));
+ Buffer::References const & refs = buffer().references(label);
+ Buffer::References::const_iterator it = refs.begin();
+ Buffer::References::const_iterator end = refs.end();
+ for (; it != end; ++it) {
+ ParConstIterator const ref_pit(it->second);
+ toc.push_back(TocItem(ref_pit, 1, it->first->screenLabel()));
+ }
+}
+
+
void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
- InsetCommandParams p("label");
+ InsetCommandParams p(LABEL_CODE);
// FIXME UNICODE
InsetCommandMailer::string2params("label", to_utf8(cmd.argument()), p);
if (p.getCmdName().empty()) {
break;
}
if (p["name"] != params()["name"])
- cur.bv().buffer()->changeRefsIfUnique(params()["name"],
- p["name"], Inset::REF_CODE);
+ cur.bv().buffer().changeRefsIfUnique(params()["name"],
+ p["name"], REF_CODE);
setParams(p);
break;
}
}
-int InsetLabel::latex(Buffer const &, odocstream & os,
- OutputParams const &) const
+int InsetLabel::latex(odocstream & os, OutputParams const &) const
{
os << escape(getCommand());
return 0;
}
-int InsetLabel::plaintext(Buffer const &, odocstream & os,
- OutputParams const &) const
+int InsetLabel::plaintext(odocstream & os, OutputParams const &) const
{
docstring const str = getParam("name");
os << '<' << str << '>';
}
-int InsetLabel::docbook(Buffer const & buf, odocstream & os,
- OutputParams const & runparams) const
+int InsetLabel::docbook(odocstream & os, OutputParams const & runparams) const
{
os << "<!-- anchor id=\""
- << sgml::cleanID(buf, runparams, getParam("name"))
- << "\" -->";
+ << sgml::cleanID(buffer(), runparams, getParam("name"))
+ << "\" -->";
return 0;
}