+docstring InsetRef::layoutName() const
+{
+ return from_ascii("Ref");
+}
+
+
+void InsetRef::changeTarget(docstring const & new_label)
+{
+ // With change tracking, we insert a new ref
+ // and delete the old one
+ if (buffer().masterParams().track_changes) {
+ InsetCommandParams icp(REF_CODE, "ref");
+ icp["reference"] = new_label;
+ string const data = InsetCommand::params2string(icp);
+ lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
+ lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_FORWARD));
+ } else
+ setParam("reference", new_label);
+}
+
+
+
+void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
+{
+ string const inset = cmd.getArg(0);
+ string const arg = cmd.getArg(1);
+ string pstring;
+ if (cmd.action() == LFUN_INSET_MODIFY && inset == "ref") {
+ if (arg == "toggle-plural")
+ pstring = "plural";
+ else if (arg == "toggle-caps")
+ pstring = "caps";
+ else if (arg == "toggle-noprefix")
+ pstring = "noprefix";
+ else if (arg == "changetarget") {
+ string const oldtarget = cmd.getArg(2);
+ string const newtarget = cmd.getArg(3);
+ if (!oldtarget.empty() && !newtarget.empty()
+ && getParam("reference") == from_utf8(oldtarget))
+ changeTarget(from_utf8(newtarget));
+ cur.forceBufferUpdate();
+ return;
+ }
+ }
+ // otherwise not for us
+ if (pstring.empty())
+ return InsetCommand::doDispatch(cur, cmd);
+
+ bool const isSet = (getParam(pstring) == "true");
+ setParam(pstring, from_ascii(isSet ? "false" : "true"));
+}
+
+
+bool InsetRef::getStatus(Cursor & cur, FuncRequest const & cmd,
+ FuncStatus & status) const
+{
+ if (cmd.action() != LFUN_INSET_MODIFY)
+ return InsetCommand::getStatus(cur, cmd, status);
+ if (cmd.getArg(0) != "ref")
+ return InsetCommand::getStatus(cur, cmd, status);
+
+ string const arg = cmd.getArg(1);
+ string pstring;
+ if (arg == "changetarget")
+ return true;
+ if (arg == "toggle-plural")
+ pstring = "plural";
+ else if (arg == "toggle-caps")
+ pstring = "caps";
+ if (!pstring.empty()) {
+ status.setEnabled(buffer().params().use_refstyle &&
+ params().getCmdName() == "formatted");
+ bool const isSet = (getParam(pstring) == "true");
+ status.setOnOff(isSet);
+ return true;
+ }
+ if (arg == "toggle-noprefix") {
+ status.setEnabled(params().getCmdName() == "labelonly");
+ bool const isSet = (getParam("noprefix") == "true");
+ status.setOnOff(isSet);
+ return true;
+ }
+ // otherwise not for us
+ return InsetCommand::getStatus(cur, cmd, status);
+}
+
+
+namespace {
+
+void capitalize(docstring & s) {
+ char_type t = uppercase(s[0]);
+ s[0] = t;
+}
+
+} // namespace
+
+