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); }
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 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; } }
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 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; } }
void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd) { LYXERR(Debug::ACTION, "InsetText::doDispatch(): cmd: " << cmd); // See bug #9042, for instance. if (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 = 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 (!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); }
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; }
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 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); } }
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 InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_MODIFY: { if (cmd.getArg(0) == "changetype") { cur.recordUndo(); p_.setCmdName(cmd.getArg(1)); cur.forceBufferUpdate(); initView(); break; } InsetCommandParams p(p_.code()); InsetCommand::string2params(to_utf8(cmd.argument()), p); if (p.getCmdName().empty()) cur.noScreenUpdate(); else { cur.recordUndo(); setParams(p); } // FIXME We might also want to check here if this one is in the TOC. // But I think most of those are labeled. if (isLabeled()) cur.forceBufferUpdate(); break; } case LFUN_INSET_DIALOG_UPDATE: { string const name = to_utf8(cmd.argument()); cur.bv().updateDialog(name, params2string(params())); break; } default: Inset::doDispatch(cur, cmd); break; } }
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 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; } }
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 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; } }
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; } }
bool InsetInfo::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action()) { case LFUN_INSET_SETTINGS: return InsetCollapsable::getStatus(cur, cmd, flag); case LFUN_INSET_DIALOG_UPDATE: case LFUN_INSET_COPY_AS: flag.setEnabled(true); return true; case LFUN_INSET_MODIFY: if (validateModifyArgument(cmd.argument())) { flag.setEnabled(true); return true; } //fall through default: return false; } }
void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd) { //lyxerr << "*** InsetMathCases: request: " << cmd << endl; switch (cmd.action()) { case LFUN_INSET_MODIFY: { istringstream is(to_utf8(cmd.argument())); string s; is >> s; if (s != "tabular") break; is >> s; // vertical lines and adding/deleting columns is not allowed for \cases if (s == "append-column" || s == "delete-column" || s == "add-vline-left" || s == "add-vline-right") { cur.undispatched(); break; } cur.recordUndo(); } default: break; } InsetMathGrid::doDispatch(cur, cmd); }
bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action()) { case LFUN_INSET_MODIFY: // disallow comment and greyed out in commands flag.setEnabled(!cur.paragraph().layout().isCommand() || cmd.getArg(2) == "Note"); if (cmd.getArg(0) == "note") { InsetNoteParams params; string2params(to_utf8(cmd.argument()), params); flag.setOnOff(params_.type == params.type); } return true; case LFUN_INSET_DIALOG_UPDATE: flag.setEnabled(true); return true; default: return InsetCollapsable::getStatus(cur, cmd, flag); } }
bool InsetMathSubstack::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; string const name = "substack"; if (s == "add-vline-left" || s == "add-vline-right") { flag.message(bformat( from_utf8(N_("Can't add vertical grid lines in '%1$s'")), from_utf8(name))); flag.setEnabled(false); return true; } // in contrary to \subaray, the columns in \substack // are always centered and this cannot be changed if (s == "align-left" || s == "align-right") { flag.message(bformat( from_utf8(N_("Can't change horizontal alignment in '%1$s'")), from_utf8(name))); flag.setEnabled(false); return true; } break; } default: break; } return InsetMathGrid::getStatus(cur, cmd, flag); }
bool InsetMathSplit::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.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 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; } case LFUN_ARGUMENT_INSERT: { string const arg = cmd.getArg(0); if (arg.empty()) { status.setEnabled(false); return true; } if (&buffer().inset() == this || !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); ParagraphList::const_iterator pit = paragraphs().begin(); for (; pit != paragraphs().end(); ++pit) { InsetList::const_iterator it = pit->insetList().begin(); InsetList::const_iterator end = pit->insetList().end(); for (; it != end; ++it) { if (it->inset->lyxCode() == ARG_CODE) { InsetArgument const * ins = static_cast<InsetArgument const *>(it->inset); 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; } }