/// Cache for Find Next
FuncRequest search_request_cache_;
+
+ ///
+ map<string, Inset *> edited_insets_;
};
flag.setEnabled(!cur.inset().getLayout().isPassThru());
break;
+ case LFUN_CITATION_INSERT: {
+ FuncRequest fr(LFUN_INSET_INSERT, "citation");
+ // FIXME: This could turn in a recursive hell.
+ // Shouldn't we use Buffer::getStatus() instead?
+ flag.setEnabled(lyx::getStatus(fr).enabled());
+ break;
+ }
+ case LFUN_INSET_APPLY: {
+ string const name = cmd.getArg(0);
+ Inset * inset = editedInset(name);
+ if (inset) {
+ FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
+ FuncStatus fs;
+ if (!inset->getStatus(cur, fr, fs)) {
+ // Every inset is supposed to handle this
+ LASSERT(false, break);
+ }
+ flag |= fs;
+ } else {
+ FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
+ flag |= lyx::getStatus(fr);
+ }
+ break;
+ }
+
default:
flag.setEnabled(false);
return false;
}
+Inset * BufferView::editedInset(string const & name) const
+{
+ map<string, Inset *>::const_iterator it = d->edited_insets_.find(name);
+ return it == d->edited_insets_.end() ? 0 : it->second;
+}
+
+
+void BufferView::editInset(string const & name, Inset * inset)
+{
+ d->edited_insets_[name] = inset;
+}
+
+
bool BufferView::dispatch(FuncRequest const & cmd)
{
//lyxerr << [ cmd = " << cmd << "]" << endl;
getIntl().toggleKeyMap();
break;
+ case LFUN_DIALOG_SHOW_NEW_INSET: {
+ string const name = cmd.getArg(0);
+ string data = trim(to_utf8(cmd.argument()).substr(name.size()));
+ if (decodeInsetParam(name, data, buffer_))
+ lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
+ else
+ lyxerr << "Inset type '" << name <<
+ "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl;
+ break;
+ }
+
+ case LFUN_CITATION_INSERT: {
+ if (argument.empty()) {
+ lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
+ break;
+ }
+ // we can have one optional argument, delimited by '|'
+ // citation-insert <key>|<text_before>
+ // this should be enhanced to also support text_after
+ // and citation style
+ string arg = argument;
+ string opt1;
+ if (contains(argument, "|")) {
+ arg = token(argument, '|', 0);
+ opt1 = token(argument, '|', 1);
+ }
+ InsetCommandParams icp(CITE_CODE);
+ icp["key"] = from_utf8(arg);
+ if (!opt1.empty())
+ icp["before"] = from_utf8(opt1);
+ string icstr = InsetCommand::params2string("citation", icp);
+ FuncRequest fr(LFUN_INSET_INSERT, icstr);
+ lyx::dispatch(fr);
+ break;
+ }
+
+ case LFUN_INSET_APPLY: {
+ string const name = cmd.getArg(0);
+ Inset * inset = editedInset(name);
+ if (!inset) {
+ FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
+ lyx::dispatch(fr);
+ break;
+ }
+ // put cursor in front of inset.
+ if (!setCursorFromInset(inset)) {
+ LASSERT(false, break);
+ }
+ // useful if we are called from a dialog.
+ cur.beginUndoGroup();
+ cur.recordUndo();
+ FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
+ inset->dispatch(cur, fr);
+ cur.endUndoGroup();
+ processUpdateFlags(Update::SinglePar | Update::FitCursor);
+ break;
+ }
+
+
default:
return false;
}