code shuffle, part 2

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5466 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-10-22 11:13:40 +00:00
parent 85e653e4e2
commit 4768f36a2f
4 changed files with 40 additions and 114 deletions

View File

@ -621,7 +621,7 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
case LFUN_GREEK:
handleFont(bv, cmd.argument, "lyxgreek1");
if (cmd.argument.size())
mathcursor->interpret(cmd.argument);
mathcursor->insert(asArray(cmd.argument));
break;
case LFUN_MATH_MODE:
@ -644,13 +644,22 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
#endif
break;
case LFUN_INSERT_MATRIX:
if (!cmd.argument.empty()) {
bv->lockedInsetStoreUndo(Undo::EDIT);
mathcursor->interpret("matrix " + cmd.argument);
case LFUN_INSERT_MATRIX: {
bv->lockedInsetStoreUndo(Undo::EDIT);
unsigned int m = 1;
unsigned int n = 1;
string v_align;
string h_align;
istringstream is(argument);
is >> m >> n >> v_align >> h_align;
m = max(1u, m);
n = max(1u, n);
v_align += 'c';
mathcursor->niceInsert(
MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
updateLocal(bv, true);
}
break;
}
case LFUN_SUPERSCRIPT:
case LFUN_SUBSCRIPT:
@ -707,15 +716,23 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
argument = "\n";
// fall through
case -1:
// FIXME: We probably should swap parts of "math-insert" and "self-insert"
// handling such that "self-insert" works on "arbitrary stuff" too, and
// math-insert only handles special math things like "matrix".
case LFUN_INSERT_MATH:
bv->lockedInsetStoreUndo(Undo::EDIT);
mathcursor->insert(asArray(argument));
updateLocal(bv, true);
break;
case -1:
case LFUN_SELFINSERT:
if (!argument.empty()) {
bv->lockedInsetStoreUndo(Undo::EDIT);
if (argument.size() == 1)
result = mathcursor->interpret(argument[0]) ? DISPATCHED : FINISHED_RIGHT;
else
result = mathcursor->interpret(argument) ? DISPATCHED : FINISHED_RIGHT;
mathcursor->insert(asArray(argument));
updateLocal(bv, true);
}
break;

View File

@ -32,13 +32,12 @@
#include "formulabase.h"
#include "funcrequest.h"
#include "math_autocorrect.h"
#include "math_arrayinset.h"
#include "math_braceinset.h"
#include "math_commentinset.h"
#include "math_charinset.h"
#include "math_extern.h"
#include "math_factory.h"
#include "math_hullinset.h"
#include "math_gridinset.h"
#include "math_iterator.h"
#include "math_macroarg.h"
#include "math_macrotemplate.h"
@ -431,20 +430,6 @@ void MathCursor::backspace()
}
}
/*
if (prevAtom()->asScriptInset()) {
// simply enter nucleus
left();
return;
}
if (inNucleus()) {
// we are in nucleus
if (pos() == 1) {
}
}
*/
--pos();
plainErase();
}
@ -472,29 +457,6 @@ void MathCursor::erase()
return;
}
/*
// if we are standing in front of a script inset, grab item before us and
// move it into nucleus
// and remove first thing.
if (hasNextAtom() && nextAtom()->asScriptInset()) {
if (hasPrevAtom()) {
MathAtom at = prevAtom();
--pos();
array().erase(pos());
pushLeft(nextAtom());
if (array().empty())
array().push_back(at);
else
array()[0] = at;
pos() = 1;
} else {
pushLeft(nextAtom());
array().clear();
}
return;
}
*/
plainErase();
}
@ -536,8 +498,19 @@ void MathCursor::macroModeClose()
string s = p->name();
--pos();
array().erase(pos());
if (s != "\\")
interpret(s);
// do nothing if the macro name is empty
if (s == "\\")
return;
string name = s.substr(1);
// prevent entering of recursive macros
if (formula()->lyxCode() == Inset::MATHMACRO_CODE
&& formula()->getInsetName() == name)
lyxerr << "can't enter recursive macro\n";
niceInsert(createMathInset(name));
}
@ -1111,68 +1084,6 @@ bool MathCursor::idxRight()
}
bool MathCursor::interpret(string const & s)
{
//lyxerr << "interpret 1: '" << s << "'\n";
if (s.empty())
return true;
//lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
//owner_->getIntl()->getTransManager().TranslateAndInsert(s[0], lt);
//lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
unsigned int m = 1;
unsigned int n = 1;
string v_align;
string h_align;
istringstream is(s.substr(6).c_str());
is >> m >> n >> v_align >> h_align;
m = max(1u, m);
n = max(1u, n);
v_align += 'c';
niceInsert(MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
return true;
}
if (s.size() >= 7 && s.substr(0, 7) == "replace") {
ReplaceData rep;
istringstream is(s.substr(7).c_str());
string from, to;
is >> from >> to;
mathed_parse_cell(rep.from, from);
mathed_parse_cell(rep.to, to);
lyxerr << "replacing '" << from << "' with '" << to << "'\n";
par()->replace(rep);
return true;
}
string name = s.substr(1);
if (name == "over" || name == "choose" || name == "atop") {
MathAtom t(createMathInset(name));
t.nucleus()->asNestInset()->cell(0) = array();
array().clear();
pos() = 0;
niceInsert(t);
popRight();
left();
return true;
}
// prevent entering of recursive macros
if (formula()->lyxCode() == Inset::MATHMACRO_CODE
&& formula()->getInsetName() == name)
{
lyxerr << "can't enter recursive macro\n";
return true;
}
niceInsert(createMathInset(name));
return true;
}
bool MathCursor::script(bool up)
{
// Hack to get \\^ and \\_ working
@ -1548,3 +1459,4 @@ void releaseMathCursor(BufferView * bv)
delete mathcursor;
mathcursor = 0;
}

View File

@ -123,8 +123,6 @@ public:
size_type size() const;
///
bool script(bool);
///
bool interpret(string const &);
///
bool interpret(char);
/// interpret name a name of a macro

View File

@ -3,7 +3,6 @@
#endif
#include "math_fracbase.h"
#include "math_mathmlstream.h"
MathFracbaseInset::MathFracbaseInset()