void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd) { LYXERR(Debug::ACTION, "InsetText::doDispatch()" << " [ cmd.action() = " << cmd.action() << ']'); if (getLayout().isPassThru()) { // Force any new text to latex_language FIXME: This // should only be necessary in constructor, but new // paragraphs that are created by pressing enter at // the start of an existing paragraph get the buffer // language and not latex_language, so we take this // brute force approach. cur.current_font.setLanguage(latex_language); cur.real_current_font.setLanguage(latex_language); } switch (cmd.action()) { case LFUN_PASTE: case LFUN_CLIPBOARD_PASTE: case LFUN_SELECTION_PASTE: case LFUN_PRIMARY_SELECTION_PASTE: text_.dispatch(cur, cmd); // If we we can only store plain text, we must reset all // attributes. // FIXME: Change only the pasted paragraphs fixParagraphsFont(); break; case LFUN_INSET_DISSOLVE: { bool const main_inset = &buffer().inset() == this; bool const target_inset = cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode()); bool const one_cell = nargs() == 1; if (!main_inset && target_inset && one_cell) { // Text::dissolveInset assumes that the cursor // is inside the Inset. if (&cur.inset() != this) cur.pushBackward(*this); cur.beginUndoGroup(); text_.dispatch(cur, cmd); cur.endUndoGroup(); } else cur.undispatched(); break; } default: text_.dispatch(cur, cmd); } if (!cur.result().dispatched()) Inset::doDispatch(cur, cmd); }
void Inset::doDispatch(Cursor & cur, FuncRequest &cmd) { switch (cmd.action()) { case LFUN_MOUSE_RELEASE: // if the derived inset did not explicitly handle mouse_release, // we assume we request the settings dialog if (!cur.selection() && cmd.button() == mouse_button::button1 && hasSettings()) { FuncRequest tmpcmd(LFUN_INSET_SETTINGS); dispatch(cur, tmpcmd); } break; case LFUN_INSET_SETTINGS: if (cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode())) { showInsetDialog(&cur.bv()); cur.dispatched(); } else cur.undispatched(); break; default: cur.noScreenUpdate(); cur.undispatched(); break; } }
bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action()) { case LFUN_INSET_MODIFY: flag.setEnabled(true); break; case LFUN_BRANCH_ACTIVATE: flag.setEnabled(!isBranchSelected()); break; case LFUN_BRANCH_DEACTIVATE: flag.setEnabled(isBranchSelected()); break; case LFUN_INSET_TOGGLE: if (cmd.argument() == "assign") flag.setEnabled(true); else return InsetCollapsable::getStatus(cur, cmd, flag); break; default: return InsetCollapsable::getStatus(cur, cmd, flag); } return true; }
void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_MODIFY: setInfo(to_utf8(cmd.argument())); break; case LFUN_INSET_COPY_AS: { cap::clearSelection(); Cursor copy(cur); copy.pushBackward(*this); copy.pit() = 0; copy.pos() = 0; copy.resetAnchor(); copy.pit() = copy.lastpit(); copy.pos() = copy.lastpos(); copy.setSelection(); cap::copySelection(copy); break; } default: InsetCollapsable::doDispatch(cur, cmd); break; } }
bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action()) { case LFUN_INSET_MODIFY: { istringstream is(to_utf8(cmd.argument())); string s; is >> s; if (s != "tabular") break; is >> s; if (s == "add-vline-left" || s == "add-vline-right") { flag.setEnabled(false); flag.message(bformat( from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")), from_utf8(s))); return true; } if (s == "append-column" || s == "delete-column") { flag.setEnabled(false); flag.message(bformat( from_utf8(N_("Changing number of columns not allowed in " "'cases': feature %1$s")), from_utf8(s))); return true; } break; } default: break; } return InsetMathGrid::getStatus(cur, cmd, flag); }
bool InsetCommand::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action()) { // suppress these case LFUN_ERT_INSERT: status.setEnabled(false); return true; // we handle these case LFUN_INSET_MODIFY: if (cmd.getArg(0) == "changetype") { string const newtype = cmd.getArg(1); status.setEnabled(p_.isCompatibleCommand(p_.code(), newtype)); status.setOnOff(newtype == p_.getCmdName()); } status.setEnabled(true); return true; case LFUN_INSET_DIALOG_UPDATE: status.setEnabled(true); return true; default: return Inset::getStatus(cur, cmd, status); } }
bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action()) { case LFUN_INSET_DISSOLVE: { bool const main_inset = &buffer().inset() == this; bool const target_inset = cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode()); bool const one_cell = nargs() == 1; if (target_inset) status.setEnabled(!main_inset && one_cell); return target_inset; } default: // Dispatch only to text_ if the cursor is inside // the text_. It is not for context menus (bug 5797). bool ret = false; if (cur.text() == &text_) ret = text_.getStatus(cur, cmd, status); if (!ret) ret = Inset::getStatus(cur, cmd, status); return ret; } }
bool InsetCaption::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action()) { case LFUN_INSET_MODIFY: { string const first_arg = cmd.getArg(0); if (first_arg == "changetype") { string const type = cmd.getArg(1); status.setOnOff(type == type_); bool varia = type != "Unnumbered"; // check if the immediate parent inset allows caption variation if (cur.depth() > 1) { varia = cur[cur.depth() - 2].inset().allowsCaptionVariation(type); } status.setEnabled(varia && buffer().params().documentClass().hasInsetLayout( from_ascii("Caption:" + type))); return true; } return InsetText::getStatus(cur, cmd, status); } case LFUN_INSET_TOGGLE: // pass back to owner cur.undispatched(); return false; default: return InsetText::getStatus(cur, cmd, status); } }
void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd) { if (cmd.action() == LFUN_INSET_MODIFY) { buffer().removeBiblioTempFiles(); cache.recalculate = true; } InsetCommand::doDispatch(cur, cmd); }
void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_MODIFY: { InsetBranchParams params; InsetBranch::string2params(to_utf8(cmd.argument()), params); cur.recordUndoInset(ATOMIC_UNDO, this); params_.branch = params.branch; // what we really want here is a TOC update, but that means // a full buffer update cur.forceBufferUpdate(); break; } case LFUN_BRANCH_ACTIVATE: case LFUN_BRANCH_DEACTIVATE: { // FIXME: I do not like this cast, but have no other idea... Buffer const * buf = buffer().masterBuffer(); BranchList const & branchlist = buf->params().branchlist(); Branch * our_branch = const_cast<Branch *>(branchlist.find(params_.branch)); if (!our_branch) { // child only? our_branch = buffer().params().branchlist().find(params_.branch); if (!our_branch) break; } bool const activate = (cmd.action() == LFUN_BRANCH_ACTIVATE); if (our_branch->isSelected() != activate) { our_branch->setSelected(activate); cur.forceBufferUpdate(); } break; } case LFUN_INSET_TOGGLE: if (cmd.argument() == "assign") setStatus(cur, isBranchSelected() ? Open : Collapsed); else InsetCollapsable::doDispatch(cur, cmd); break; default: InsetCollapsable::doDispatch(cur, cmd); break; } }
bool Inset::getStatus(Cursor &, FuncRequest const & cmd, FuncStatus & flag) const { // LFUN_INSET_APPLY is sent from the dialogs when the data should // be applied. This is either changed to LFUN_INSET_MODIFY (if the // dialog belongs to us) or LFUN_INSET_INSERT (if the dialog does // not belong to us, i. e. the dialog was open, and the user moved // the cursor in our inset) in lyx::getStatus(). // Dialogs::checkStatus() ensures that the dialog is deactivated if // LFUN_INSET_APPLY is disabled. switch (cmd.action()) { case LFUN_INSET_MODIFY: // Allow modification of our data. // This needs to be handled in the doDispatch method of our // instantiatable children. // FIXME: Why don't we let the insets determine whether this // should be enabled or not ? Now we need this check for // the tabular features. (vfr) if (cmd.getArg(0) == "tabular") return false; flag.setEnabled(true); return true; case LFUN_INSET_INSERT: // Don't allow insertion of new insets. // Every inset that wants to allow new insets from open // dialogs needs to override this. flag.setEnabled(false); return true; case LFUN_INSET_SETTINGS: if (cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode())) { bool const enable = hasSettings(); flag.setEnabled(enable); return true; } else { return false; } case LFUN_IN_MATHMACROTEMPLATE: // By default we're not in a MathMacroTemplate inset flag.setEnabled(false); return true; case LFUN_IN_IPA: // By default we're not in an IPA inset flag.setEnabled(false); return true; default: break; } return false; }
void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd) { Inset * inset = itemInset(); FuncRequest tmpcmd(cmd); QModelIndex const & index = tocTV->currentIndex(); TocItem const & item = gui_view_.tocModels().currentItem(current_type_, index); // Start an undo group. cur.beginUndoGroup(); switch (cmd.action()) { case LFUN_CHANGE_ACCEPT: case LFUN_CHANGE_REJECT: case LFUN_SECTION_SELECT: dispatch(item.action()); cur.dispatch(tmpcmd); break; case LFUN_LABEL_COPY_AS_REF: { // For labels in math, we need to supply the label as a string FuncRequest label_copy(LFUN_LABEL_COPY_AS_REF, item.asString()); if (inset) inset->dispatch(cur, label_copy); break; } case LFUN_OUTLINE_UP: case LFUN_OUTLINE_DOWN: case LFUN_OUTLINE_IN: case LFUN_OUTLINE_OUT: outline(cmd.action()); break; default: if (inset) inset->dispatch(cur, tmpcmd); } cur.endUndoGroup(); }
bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action()) { case LFUN_INSET_DISSOLVE: { bool const main_inset = text_.isMainText(); bool const target_inset = cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode()); // cur.inset() is the tabular when this is a single cell (bug #9954) bool const one_cell = cur.inset().nargs() == 1; if (target_inset) status.setEnabled(!main_inset && one_cell); return target_inset; } case LFUN_ARGUMENT_INSERT: { string const arg = cmd.getArg(0); if (arg.empty()) { status.setEnabled(false); return true; } if (text_.isMainText() || !cur.paragraph().layout().args().empty()) return text_.getStatus(cur, cmd, status); Layout::LaTeXArgMap args = getLayout().args(); Layout::LaTeXArgMap::const_iterator const lait = args.find(arg); if (lait != args.end()) { status.setEnabled(true); for (Paragraph const & par : paragraphs()) for (auto const & table : par.insetList()) if (InsetArgument const * ins = table.inset->asInsetArgument()) if (ins->name() == arg) { // we have this already status.setEnabled(false); return true; } } else status.setEnabled(false); return true; } default: // Dispatch only to text_ if the cursor is inside // the text_. It is not for context menus (bug 5797). bool ret = false; if (cur.text() == &text_) ret = text_.getStatus(cur, cmd, status); if (!ret) ret = Inset::getStatus(cur, cmd, status); return ret; } }
bool InsetLine::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action()) { case LFUN_INSET_DIALOG_UPDATE: case LFUN_INSET_MODIFY: status.setEnabled(true); return true; default: return InsetCommand::getStatus(cur, cmd, status); } }
bool InsetHyperlink::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action()) { case LFUN_INSET_EDIT: flag.setEnabled(getParam("type").empty() || getParam("type") == "file:"); return true; default: return InsetCommand::getStatus(cur, cmd, flag); } }
void InsetTOC::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_MOUSE_RELEASE: if (!cur.selection() && cmd.button() == mouse_button::button1) { cur.bv().showDialog("toc", params2string(params())); cur.dispatched(); } break; default: InsetCommand::doDispatch(cur, cmd); } }
void InsetHyperlink::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_EDIT: viewTarget(); break; default: InsetCommand::doDispatch(cur, cmd); break; } }
bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action()) { case LFUN_INSET_MODIFY: case LFUN_INSET_DIALOG_UPDATE: status.setEnabled(true); return true; case LFUN_CAPTION_INSERT: status.setEnabled(!params().isInline()); return true; default: return InsetCollapsable::getStatus(cur, cmd, status); } }
bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action()) { case LFUN_INSET_MODIFY: if (cmd.getArg(0) == "ert") { status.setEnabled(true); return true; } //fall through default: return InsetCollapsable::getStatus(cur, cmd, status); } }
void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_MODIFY: if (cmd.getArg(0) == "ert") { cur.recordUndoInset(ATOMIC_UNDO, this); setStatus(cur, string2params(to_utf8(cmd.argument()))); break; } //fall-through default: InsetCollapsable::doDispatch(cur, cmd); break; } }
void InsetCaption::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_MODIFY: { if (cmd.getArg(0) == "changetype") { cur.recordUndoInset(ATOMIC_UNDO, this); type_ = cmd.getArg(1); cur.forceBufferUpdate(); break; } } default: InsetText::doDispatch(cur, cmd); break; } }
void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_MODIFY: { cur.recordUndoInset(ATOMIC_UNDO, this); InsetListings::string2params(to_utf8(cmd.argument()), params()); break; } case LFUN_INSET_DIALOG_UPDATE: cur.bv().updateDialog("listings", params2string(params())); break; default: InsetCollapsable::doDispatch(cur, cmd); break; } }
bool InsetMathAMSArray::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action()) { case LFUN_TABULAR_FEATURE: { string s = cmd.getArg(0); if (s == "add-vline-left" || s == "add-vline-right") { flag.message(bformat( from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_)); flag.setEnabled(false); return true; } break; } default: break; } return InsetMathGrid::getStatus(cur, cmd, flag); }
bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action()) { case LFUN_INSET_DISSOLVE: if (!cmd.argument().empty()) { InsetLayout const & il = getLayout(); InsetLayout::InsetLyXType const type = translateLyXType(to_utf8(cmd.argument())); if (il.lyxtype() == type) { FuncRequest temp_cmd(LFUN_INSET_DISSOLVE); return InsetCollapsable::getStatus(cur, temp_cmd, flag); } else return false; } // fall-through default: return InsetCollapsable::getStatus(cur, cmd, flag); } }
bool InsetInfo::validateModifyArgument(docstring const & arg) const { string type; string const name = trim(split(to_utf8(arg), type, ' ')); switch (nameTranslator().find(type)) { case UNKNOWN_INFO: return false; case SHORTCUT_INFO: case SHORTCUTS_INFO: case MENU_INFO: case ICON_INFO: { FuncRequest func = lyxaction.lookupFunc(name); return func.action() != LFUN_UNKNOWN_ACTION; } case LYXRC_INFO: { ostringstream oss; lyxrc.write(oss, true, name); return !oss.str().empty(); } case PACKAGE_INFO: case TEXTCLASS_INFO: return true; case BUFFER_INFO: if (name == "name" || name == "path" || name == "class") return true; if (name == "vcs-revision" || name == "vcs-tree-revision" || name == "vcs-author" || name == "vcs-date" || name == "vcs-time") return buffer().lyxvc().inUse(); return false; case LYX_INFO: return name == "version"; } return false; }
CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name, string const & def) { string const name2 = trim(name); if (name2.empty()) return CmdDefNameEmpty; if (cmdDefMap.find(name) != cmdDefMap.end()) return CmdDefExists; FuncRequest func = lyxaction.lookupFunc(def); if (func.action() == LFUN_NOACTION || func.action() == LFUN_UNKNOWN_ACTION) { return CmdDefInvalid; } cmdDefMap[name2] = func; return CmdDefOk; }
void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_MODIFY: cur.recordUndoInset(ATOMIC_UNDO, this); string2params(to_utf8(cmd.argument()), params_); setButtonLabel(); // what we really want here is a TOC update, but that means // a full buffer update cur.forceBufferUpdate(); break; case LFUN_INSET_DIALOG_UPDATE: cur.bv().updateDialog("note", params2string(params())); break; default: InsetCollapsable::doDispatch(cur, cmd); break; } }
void InsetPrintNomencl::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_MODIFY: { InsetCommandParams p(NOMENCL_PRINT_CODE); // FIXME UNICODE InsetCommand::string2params("nomencl_print", to_utf8(cmd.argument()), p); if (p.getCmdName().empty()) { cur.noScreenUpdate(); break; } setParams(p); break; } default: InsetCommand::doDispatch(cur, cmd); break; } }
void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_DISSOLVE: if (!cmd.argument().empty()) { InsetLayout const & il = getLayout(); InsetLayout::InsetLyXType const type = translateLyXType(to_utf8(cmd.argument())); if (il.lyxtype() == type) { FuncRequest temp_cmd(LFUN_INSET_DISSOLVE); InsetCollapsable::doDispatch(cur, temp_cmd); } else cur.undispatched(); break; } // fall-through default: InsetCollapsable::doDispatch(cur, cmd); break; } }
void InsetLine::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_MODIFY: { InsetCommandParams p(LINE_CODE); // FIXME UNICODE InsetCommand::string2params(to_utf8(cmd.argument()), p); if (p.getCmdName().empty()) { cur.noScreenUpdate(); break; } cur.recordUndo(); setParams(p); break; } default: InsetCommand::doDispatch(cur, cmd); break; } }