+ if (!new_label.empty())
+ SetNumber(true);
+
+ if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
+ bv->redraw();
+
+ if (is_multi_numbered(par->GetType())) {
+ mathcursor->setLabel(new_label);
+ // MathMatrixInset *mt = (MathMatrixInset*)par;
+ // mt->SetLabel(new_label);
+ } else
+ label = new_label;
+
+ UpdateLocal(bv);
+ break;
+ }
+
+ case LFUN_MATH_DISPLAY:
+ bv->lockedInsetStoreUndo(Undo::EDIT);
+ display(!disp_flag);
+ UpdateLocal(bv);
+ break;
+
+ // Invalid actions under math mode
+ case LFUN_MATH_MODE:
+ if (mathcursor->getLastCode()!= LM_TC_TEXTRM) {
+ bv->owner()->getMiniBuffer()->Set(_("math text mode"));
+ varcode = LM_TC_TEXTRM;
+ } else {
+ varcode = LM_TC_VAR;
+ }
+ mathcursor->setLastCode(varcode);
+ break;
+
+ case LFUN_UNDO:
+ bv->owner()->getMiniBuffer()->Set(_("Invalid action in math mode!"));
+ break;
+
+ //------- dummy actions
+ case LFUN_EXEC_COMMAND:
+ bv->owner()->getMiniBuffer()->PrepareForCommand();
+ break;
+
+ default:
+ if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
+ unsigned char c = arg[0];
+ bv->lockedInsetStoreUndo(Undo::INSERT);
+
+ if (c == ' ' && mathcursor->getAccent() == LM_hat) {
+ c = '^';
+ mathcursor->setAccent(0);
+ }
+
+ if (c == 0) { // Dead key, do nothing
+ //lyxerr << "deadkey" << endl;
+ break;
+ }
+
+ if (isalpha(c)) {
+ if (mathcursor->getLastCode() == LM_TC_TEX) {
+ mathcursor->MacroModeOpen();
+ mathcursor->clearLastCode();
+ varcode = LM_TC_MIN;
+ } else if (!varcode) {
+ short f = (mathcursor->getLastCode()) ?
+ mathcursor->getLastCode() :
+ static_cast<MathedTextCodes>(mathcursor->GetFCode());
+ varcode = MathIsAlphaFont(f) ?
+ static_cast<MathedTextCodes>(f) :
+ LM_TC_VAR;
+ }
+
+ // lyxerr << "Varcode << vardoce;
+ MathedTextCodes char_code = varcode;
+ if (greek_kb_flag) {
+ char greek[26] =
+ {'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
+ 'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
+ 'Y', 0, 0, 0, 0 , 'Z' };
+
+ if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
+ char_code = LM_TC_RM;
+ c = greek[c - 'A'];
+ } else
+ char_code = LM_TC_SYMB;
+ }
+
+ mathcursor->Insert(c, char_code);
+
+ if (greek_kb_flag && char_code == LM_TC_RM )
+ mathcursor->setLastCode(LM_TC_VAR);
+
+ varcode = LM_TC_MIN;
+
+ if (greek_kb_flag<2)
+ greek_kb_flag = 0;
+
+ } else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
+ mathcursor->Insert(c, LM_TC_TEX);
+ if (c == '{') {
+ mathcursor->Insert('}', LM_TC_TEX);
+ mathcursor->Left();
+ }
+ mathcursor->clearLastCode();
+ // varcode = LM_TC_MIN;
+ } else if (c == '_' && varcode == LM_TC_TEX) {
+ mathcursor->Insert(c, LM_TC_SPECIAL);
+ mathcursor->clearLastCode();
+ // varcode = LM_TC_MIN;
+ } else if (('0'<= c && c<= '9') && (varcode == LM_TC_TEX||was_macro)) {
+ mathcursor->MacroModeOpen();
+ mathcursor->clearLastCode();
+ mathcursor->Insert(c, LM_TC_MIN);
+ } else if (('0'<= c && c<= '9') || strchr(";:!|[]().,?", c)) {
+ mathcursor->Insert(c, LM_TC_CONST);
+ } else if (strchr("+/-*<>=", c)) {
+ mathcursor->Insert(c, LM_TC_BOP);
+ } else if (strchr(latex_special_chars, c) && c!= '_') {
+ mathcursor->Insert(c, LM_TC_SPECIAL);
+ } else if (c == '_' || c == '^') {
+ char s[2];
+ s[0] = c;
+ s[1] = 0;
+ mathcursor->Interpret(s);
+ } else if (c == ' ') {
+ if (!varcode) {
+ short f = (mathcursor->getLastCode()) ?
+ mathcursor->getLastCode() :
+ static_cast<MathedTextCodes>(mathcursor->GetFCode());
+ varcode = MathIsAlphaFont(f) ?
+ static_cast<MathedTextCodes>(f) :
+ LM_TC_VAR;
+ }
+
+ if (varcode == LM_TC_TEXTRM) {
+ mathcursor->Insert(c, LM_TC_TEXTRM);
+ } else if (was_macro) {
+ mathcursor->MacroModeClose();
+ } else if (sp) {
+ int isp = (sp->GetSpace()<5) ? sp->GetSpace()+1: 0;
+ sp->SetSpace(isp);
+ space_on = true;
+ } else if (!mathcursor->Pop() && mathcursor->IsEnd())
+ result = FINISHED;
+ } else if (c == '\'' || c == '@') {
+ mathcursor->Insert (c, LM_TC_VAR);
+ } else if (c == '\\') {
+ if (was_macro)
+ mathcursor->MacroModeClose();
+ bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
+ mathcursor->setLastCode(LM_TC_TEX);
+ }
+ UpdateLocal(bv);
+ } else if (action == LFUN_MATH_PANEL) {
+ result = UNDISPATCHED;
+ } else {
+ // lyxerr << "Closed by action " << action << endl;
+ result = FINISHED;
+ }