From: André Pönitz Date: Thu, 15 Aug 2002 14:33:14 +0000 (+0000) Subject: streamlining interaction mathed <-> rest of the world X-Git-Tag: 1.6.10~18555 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0b86a117fb238ae412770e984ef237f676b1412a;p=features.git streamlining interaction mathed <-> rest of the world remove unneeded lfun general cleanup git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4996 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 301285fe51..0ccdb69ecb 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -2915,40 +2915,15 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) } break; - case LFUN_MATH: - mathDispatch(bv_, ev.argument); - break; - case LFUN_MATH_MACRO: - mathDispatchMathMacro(bv_, ev.argument); - break; - case LFUN_MATH_DELIM: - mathDispatchMathDelim(bv_, ev.argument); - break; - case LFUN_INSERT_MATRIX: - mathDispatchInsertMatrix(bv_, ev.argument); - break; - case LFUN_INSERT_MATH: - mathDispatchInsertMath(bv_, ev.argument); - break; - case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection - mathDispatchMathImportSelection(bv_, ev.argument); - break; - case LFUN_MATH_DISPLAY: // Open or create a displayed math inset - mathDispatchMathDisplay(bv_, ev.argument); - break; - case LFUN_MATH_MODE: // Open or create an inlined math inset - mathDispatchMathMode(bv_, ev.argument); - break; - case LFUN_GREEK: // Insert a single greek letter - mathDispatchGreek(bv_, ev.argument); + mathDispatch(FuncRequest(bv_, ev.action, ev.argument)); break; case LFUN_CITATION_INSERT: diff --git a/src/ChangeLog b/src/ChangeLog index 3803a3d198..c81b1372e7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ + + * lyxfunc.C: + BufferView_pimpl.C: streamlining mathed <-> outer world interaction + + * commandtags.h: + LyXAction.C: remove unused LFUN_MATH + + 2002-08-15 Lars Gullik Bjønnes * paragraph.[Ch]: add some NO_NEXT ifdefs. diff --git a/src/LyXAction.C b/src/LyXAction.C index ba7b6aeae0..348f935d1c 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -278,7 +278,6 @@ void LyXAction::init() { LFUN_MARK_OFF, "mark-off", "", ReadOnly }, { LFUN_MARK_ON, "mark-on", "", ReadOnly }, { LFUN_SETMARK, "mark-toggle", "", ReadOnly }, - { LFUN_MATH, "math", "", Noop }, { LFUN_MATH_DELIM, "math-delim", "", Noop }, { LFUN_MATH_DISPLAY, "math-display", "", Noop }, { LFUN_GREEK, "math-greek", N_("Math Greek"), Noop }, diff --git a/src/commandtags.h b/src/commandtags.h index 8eb6c6c830..5f69248f98 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -131,7 +131,6 @@ enum kb_action { LFUN_INSERT_MATH, LFUN_INSERT_MATRIX, LFUN_GREEK, // 110 - LFUN_MATH, // Andre' 2002-06-14 LFUN_MATH_LIMITS, LFUN_GREEK_TOGGLE, LFUN_MATH_DELIM, // Alejandro 180696 diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 44e2093f1f..30f2d89da1 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -428,7 +428,7 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap void MenuInsertLabel(BufferView * bv, string const & arg) { - string label(arg); + string label = arg; bv->owner()->prohibitInput(); if (label.empty()) { Paragraph * par = bv->getLyXText()->cursor.par(); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 9e10195da2..0b05ccc93f 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -417,7 +417,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const disable = !IsFileReadable(buf->getLogName().second); break; case LFUN_MATH_VALIGN: - if (mathcursor && mathcursor->formula()->hullType() != "simple") { + if (mathcursor) { char align = mathcursor->valign(); if (align == '\0') { disable = true; @@ -437,7 +437,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; case LFUN_MATH_HALIGN: - if (mathcursor && mathcursor->formula()->hullType() != "simple") { + if (mathcursor) { char align = mathcursor->halign(); if (align == '\0') { disable = true; @@ -457,8 +457,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; case LFUN_MATH_MUTATE: - if (tli && (tli->lyxCode() == Inset::MATH_CODE)) - flag.setOnOff(mathcursor->formula()->hullType() == ev.argument); + if (mathcursor) + //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument); + flag.setOnOff(false); else disable = true; break; @@ -479,8 +480,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_MATH_ROW_DELETE: case LFUN_MATH_COLUMN_INSERT: case LFUN_MATH_COLUMN_DELETE: - disable = !mathcursor || !mathcursor->halign() || - mathcursor->formula()->hullType() == "simple"; + disable = !mathcursor || !mathcursor->halign(); break; default: diff --git a/src/mathed/formula.C b/src/mathed/formula.C index dc1d45e8e0..5bbd64be6c 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -216,7 +216,6 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font, pi.pain.image(x, y - a, w, h, *(preview_->pimage()->image(*this, *bv))); } else { - //pi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT; pi.base.style = LM_ST_TEXT; pi.base.font = font; pi.base.font.setColor(LColor::math); @@ -250,65 +249,6 @@ vector const InsetFormula::getLabelList() const } -UpdatableInset::RESULT -InsetFormula::localDispatch(FuncRequest const & ev) -{ - RESULT result = DISPATCHED; - BufferView * bv = ev.view(); - - switch (ev.action) { - - case LFUN_MATH_MUTATE: - { - bv->lockedInsetStoreUndo(Undo::EDIT); - int x; - int y; - mathcursor->getPos(x, y); - mutate(ev.argument); - mathcursor->setPos(x, y); - mathcursor->normalize(); - updateLocal(bv, true); - break; - } - - - case LFUN_MATH_DISPLAY: - { - int x = 0; - int y = 0; - mathcursor->getPos(x, y); - if (hullType() == "simple") - mutate("equation"); - else - mutate("simple"); - mathcursor->setPos(x, y); - mathcursor->normalize(); - updateLocal(bv, true); - break; - } - - case LFUN_PASTESELECTION: - { - string const clip = bv->getClipboard(); - if (!clip.empty()) - mathed_parse_normal(par_, clip); - break; - } - - default: - result = InsetFormulaBase::localDispatch(ev); - } - - return result; -} - - -bool InsetFormula::display() const -{ - return hullType() != "simple" && hullType() != "none"; -} - - Inset::Code InsetFormula::lyxCode() const { return Inset::MATH_CODE; @@ -324,7 +264,7 @@ void InsetFormula::validate(LaTeXFeatures & features) const bool InsetFormula::insetAllowed(Inset::Code code) const { return - (code == Inset::LABEL_CODE && display()) + (code == Inset::LABEL_CODE) || code == Inset::REF_CODE || code == Inset::ERT_CODE; } @@ -355,16 +295,12 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const } -string InsetFormula::hullType() const -{ - return par()->getType(); -} - - +/* void InsetFormula::mutate(string const & type) { par_.nucleus()->mutate(type); } +*/ // diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 846ade741b..f52a6c2e9c 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -26,8 +26,6 @@ #include -class MathHullInset; - /// class InsetFormula : public InsetFormulaBase { public: @@ -72,12 +70,8 @@ public: /// bool insetAllowed(Inset::Code code) const; /// - virtual RESULT localDispatch(FuncRequest const &); - /// std::vector const getLabelList() const; /// - string hullType() const; - /// MathAtom const & par() const { return par_; } /// MathAtom & par() { return par_; } @@ -86,11 +80,9 @@ public: /// void addPreview(grfx::PreviewLoader &) const; /// - void mutate(string const & type); + //void mutate(string const & type); private: - /// Is this a displayed environment? - bool display() const; /// available in AMS only? bool ams() const; diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 63c46f9de5..e7777dd7c3 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -416,6 +416,8 @@ InsetFormulaBase::localDispatch(FuncRequest const & ev) switch (ev.action) { + case LFUN_MATH_MUTATE: + case LFUN_MATH_DISPLAY: case LFUN_MATH_HALIGN: case LFUN_MATH_VALIGN: case LFUN_MATH_ROW_INSERT: @@ -533,6 +535,15 @@ InsetFormulaBase::localDispatch(FuncRequest const & ev) break; } +/* + case LFUN_PASTESELECTION: { + string const clip = bv->getClipboard(); + if (!clip.empty()) + mathed_parse_normal(par_, clip); + break; + } +*/ + case LFUN_PASTE: if (was_macro) mathcursor->macroModeClose(); @@ -892,14 +903,18 @@ bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what, } +bool InsetFormulaBase::display() const +{ + return par()->asHullInset() && par()->asHullInset()->display(); +} + + ///////////////////////////////////////////////////////////////////// -void mathDispatchCreation(BufferView * bv, string const & arg, bool display) +void mathDispatchCreation(FuncRequest const & cmd, bool display) { - if (!bv->available()) - return; - + BufferView * bv = cmd.view(); // use selection if available.. //string sel; //if (action == LFUN_MATH_IMPORT_SELECTION) @@ -911,13 +926,14 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display) if (sel.empty()) { InsetFormula * f = new InsetFormula(bv); if (openNewInset(bv, f)) { - f->mutate("simple"); + bv->theLockingInset()-> + localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple")); // don't do that also for LFUN_MATH_MODE unless you want end up with // always changing to mathrm when opening an inlined inset // -- I really hate "LyXfunc overloading"... if (display) f->localDispatch(FuncRequest(bv, LFUN_MATH_DISPLAY)); - f->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, arg)); + f->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, cmd.argument)); } } else { // create a macro if we see "\\newcommand" somewhere, and an ordinary @@ -935,91 +951,50 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display) } -void mathDispatchMathDisplay(BufferView * bv, string const & arg) -{ - mathDispatchCreation(bv, arg, true); -} - - -void mathDispatchMathMode(BufferView * bv, string const & arg) -{ - mathDispatchCreation(bv, arg, false); -} - - -void mathDispatchMathImportSelection(BufferView * bv, string const & arg) -{ - mathDispatchCreation(bv, arg, true); -} - - -void mathDispatchMathMacro(BufferView * bv, string const & arg) -{ - if (!bv->available()) - return; - if (arg.empty()) - bv->owner()->getLyXFunc().setErrorMessage(N_("Missing argument")); - else { - string s = arg; - string const s1 = token(s, ' ', 1); - int const na = s1.empty() ? 0 : lyx::atoi(s1); - openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na)); - } -} - - -void mathDispatchMathDelim(BufferView * bv, string const & arg) +void mathDispatch(FuncRequest const & cmd) { + BufferView * bv = cmd.view(); if (!bv->available()) return; - InsetFormula * f = new InsetFormula(bv); - if (openNewInset(bv, f)) { - f->mutate("simple"); - bv->theLockingInset()->localDispatch(FuncRequest(bv, LFUN_MATH_DELIM, arg)); - } -} - -void mathDispatchInsertMatrix(BufferView * bv, string const & arg) -{ - if (!bv->available()) - return; - InsetFormula * f = new InsetFormula(bv); - if (openNewInset(bv, f)) { - f->mutate("simple"); - bv->theLockingInset()->localDispatch(FuncRequest(bv, LFUN_INSERT_MATRIX, arg)); - } -} + switch (cmd.action) { + case LFUN_MATH_DISPLAY: + mathDispatchCreation(cmd, true); + break; -void mathDispatchInsertMath(BufferView * bv, string const & arg) -{ - if (!bv->available()) - return; - InsetFormula * f = new InsetFormula(bv); - if (openNewInset(bv, f)) { - f->mutate("simple"); - bv->theLockingInset()->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, arg)); - } -} + case LFUN_MATH_MODE: + mathDispatchCreation(cmd, false); + break; + case LFUN_MATH_IMPORT_SELECTION: + mathDispatchCreation(cmd, false); + break; -void mathDispatchGreek(BufferView * bv, string const & arg) -{ - if (!bv->available()) - return; - InsetFormula * f = new InsetFormula(bv); - if (openNewInset(bv, f)) { - f->mutate("simple"); - bv->theLockingInset()->localDispatch(FuncRequest(bv, LFUN_GREEK, arg)); - bv->unlockInset(f); + case LFUN_MATH_MACRO: + if (cmd.argument.empty()) + bv->owner()->getLyXFunc().setErrorMessage(N_("Missing argument")); + else { + string s = cmd.argument; + string const s1 = token(s, ' ', 1); + int const na = s1.empty() ? 0 : lyx::atoi(s1); + openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na)); + } + break; + + case LFUN_GREEK: + case LFUN_INSERT_MATH: + case LFUN_INSERT_MATRIX: + case LFUN_MATH_DELIM: { + InsetFormula * f = new InsetFormula(bv); + if (openNewInset(bv, f)) { + bv->theLockingInset()-> + localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple")); + bv->theLockingInset()->localDispatch(cmd); + } + break; + } + default: + break; } } - - -void mathDispatch(BufferView *, kb_action, string const &) -{} - - -void mathDispatch(BufferView *, string const &) -{} diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index 2cfb57aea4..b7ab439939 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -43,8 +43,6 @@ public: virtual int width(BufferView *, LyXFont const &) const = 0; /// virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0; - /// - virtual string hullType() const { return "none"; } /// lowest x coordinate virtual int xlow() const; /// highest x coordinate @@ -90,6 +88,8 @@ public: /// To allow transparent use of math editing functions virtual RESULT localDispatch(FuncRequest const &); + /// To allow transparent use of math editing functions + //virtual void status(FuncRequest const &); /// virtual std::vector const getLabelList() const; @@ -116,6 +116,8 @@ public: virtual void revealCodes(BufferView *) const; /// virtual Inset::EDITABLE editable() const { return HIGHLY_EDITABLE; } + /// + bool display() const; private: /// unimplemented @@ -145,27 +147,6 @@ protected: // We don't really mess want around with mathed stuff outside mathed. // So do it here. -// -void mathDispatchCreation(BufferView *, string const &, bool); -// -void mathDispatchMathDisplay(BufferView *, string const &); -// -void mathDispatchMathMode(BufferView *, string const &); -// -void mathDispatchMathMacro(BufferView *, string const &); -// -void mathDispatchMathDelim(BufferView *, string const &); -// -void mathDispatchInsertMath(BufferView *, string const &); -// -void mathDispatchInsertMatrix(BufferView *, string const &); -// -void mathDispatchGreek(BufferView *, string const &); -// -void mathDispatchMathImportSelection(BufferView *, string const &); -// -void mathDispatch(BufferView *, FuncRequest const &); -// -void mathDispatch(BufferView *, string const &); +void mathDispatch(FuncRequest const &); #endif diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 4488dd9cc0..8b1c556c5c 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -809,6 +809,25 @@ MathInset::result_type MathHullInset::dispatch doExtern(cmd, idx, pos); return DISPATCHED_POP; + case LFUN_MATH_MUTATE: { + row_type r = row(idx); + col_type c = col(idx); + mutate(cmd.argument); + idx = r * ncols() + c; + if (idx >= nargs()) + idx = nargs() - 1; + if (pos > cell(idx).size()) + pos = cell(idx).size(); + return DISPATCHED_POP; + } + + case LFUN_MATH_DISPLAY: { + mutate(type_ == "simple" ? "equation" : "simple"); + idx = 0; + pos = cell(idx).size(); + return DISPATCHED_POP; + } + default: return MathGridInset::dispatch(cmd, idx, pos);