]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
Fix breakage caused by bad commits.
[lyx.git] / src / text3.C
index 29c791407a3b9273ec557f942f411b3fada56c30..7f0e8465726625e9381ab528e8290b07c0e51a14 100644 (file)
@@ -65,8 +65,8 @@
 #include "support/convert.h"
 #include "support/lyxtime.h"
 
-#include "mathed/math_hullinset.h"
-#include "mathed/math_macrotemplate.h"
+#include "mathed/InsetMathHull.h"
+#include "mathed/MathMacroTemplate.h"
 
 #include <boost/current_function.hpp>
 
@@ -79,16 +79,12 @@ using lyx::pos_type;
 
 using lyx::cap::copySelection;
 using lyx::cap::cutSelection;
-using lyx::cap::pasteParagraphList;
 using lyx::cap::pasteSelection;
 using lyx::cap::replaceSelection;
 
 using lyx::support::isStrUnsignedInt;
 using lyx::support::token;
 
-using lyx::frontend::Gui;
-using lyx::frontend::Clipboard;
-
 using std::endl;
 using std::string;
 using std::istringstream;
@@ -152,7 +148,7 @@ namespace {
 
                if (sel.empty()) {
                        const int old_pos = cur.pos();
-                       cur.insert(new MathHullInset("simple"));
+                       cur.insert(new InsetMathHull(hullSimple));
                        BOOST_ASSERT(old_pos == cur.pos());
                        cur.nextInset()->edit(cur, true);
                        // don't do that also for LFUN_MATH_MODE
@@ -174,19 +170,19 @@ namespace {
                        if (sel.find("\\newcommand") == string::npos
                            && sel.find("\\def") == string::npos)
                        {
-                               MathHullInset * formula = new MathHullInset;
+                               InsetMathHull * formula = new InsetMathHull;
                                LyXLex lex(0, 0);
                                lex.setStream(is);
                                formula->read(cur.buffer(), lex);
-                               if (formula->getType() == "none")
+                               if (formula->getType() == hullNone)
                                        // Don't create pseudo formulas if
                                        // delimiters are left out
-                                       formula->mutate("simple");
+                                       formula->mutate(hullSimple);
                                cur.insert(formula);
                        } else
                                cur.insert(new MathMacroTemplate(is));
                }
-               cur.message(N_("Math editor mode"));
+               cur.message(lyx::from_utf8(N_("Math editor mode")));
        }
 
 } // namespace anon
@@ -278,8 +274,15 @@ bool doInsertInset(LCursor & cur, LyXText * text,
        if (edit)
                inset->edit(cur, true);
 
-       if (gotsel && pastesel)
+       if (gotsel && pastesel) {
                cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
+               // reset first par to default
+               if (cur.lastpit() != 0 || cur.lastpos() != 0) {
+                       LyXLayout_ptr const layout =
+                               cur.buffer().params().getLyXTextClass().defaultLayout();
+                       cur.text()->paragraphs().begin()->layout(layout);
+               }
+       }
        return true;
 }
 
@@ -603,7 +606,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_CHAR_DELETE_BACKWARD:
                if (!cur.selection()) {
-                       if (bv->owner()->getIntl().getTransManager().backspace()) {
+                       if (bv->getIntl().getTransManager().backspace()) {
                                // Par boundary, full-screen update
                                if (cur.pos() == 0)
                                        singleParUpdate = false;
@@ -691,7 +694,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                } else if (tmp == "default") {
                        new_spacing = Spacing::Default;
                } else {
-                       lyxerr << _("Unknown spacing argument: ")
+                       lyxerr << lyx::to_utf8(_("Unknown spacing argument: "))
                               << lyx::to_utf8(cmd.argument()) << endl;
                }
                if (cur_spacing != new_spacing || cur_value != new_value)
@@ -709,34 +712,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_INSET_DISSOLVE: {
-               recordUndoInset(cur);
-               cur.selHandle(false);
-               // save position
-               lyx::pos_type spos = cur.pos();
-               lyx::pit_type spit = cur.pit();
-               ParagraphList plist;
-               if (cur.lastpit() != 0 || cur.lastpos() != 0) 
-                       plist = paragraphs();
-               cur.popLeft();
-               // store cursor offset
-               if (spit == 0)
-                       spos += cur.pos();
-               spit += cur.pit();
-               cur.paragraph().erase(cur.pos());
-               if (!plist.empty()) {
-                       Buffer * b = bv->buffer();
-                       pasteParagraphList(cur, plist, b->params().textclass, 
-                                          b->errorList("Paste"));
-                       // restore position
-                       cur.pit() = std::min(cur.lastpit(), spit);
-                       cur.pos() = std::min(cur.lastpos(), spos);
-               }
-               cur.clearSelection();
-               cur.resetAnchor();
-               needsUpdate = true;
+       case LFUN_INSET_DISSOLVE:
+               needsUpdate = dissolveInset(cur);
                break;
-       }
 
        case LFUN_INSET_SETTINGS:
                cur.inset().showInsetDialog(bv);
@@ -814,8 +792,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_SERVER_GET_XY:
-               cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
-                         + convert<string>(cursorY(cur.top(), cur.boundary())));
+               cur.message(lyx::from_utf8(
+                       convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
+                         + convert<string>(cursorY(cur.top(), cur.boundary()))));
                break;
 
        case LFUN_SERVER_SET_XY: {
@@ -833,15 +812,15 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_SERVER_GET_FONT:
                if (current_font.shape() == LyXFont::ITALIC_SHAPE)
-                       cur.message("E");
+                       cur.message(lyx::from_utf8("E"));
                else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
-                       cur.message("N");
+                       cur.message(lyx::from_utf8("N"));
                else
-                       cur.message("0");
+                       cur.message(lyx::from_utf8("0"));
                break;
 
        case LFUN_SERVER_GET_LAYOUT:
-               cur.message(cur.paragraph().layout()->name());
+               cur.message(lyx::from_utf8(cur.paragraph().layout()->name()));
                break;
 
        case LFUN_LAYOUT: {
@@ -872,8 +851,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                }
 
                if (!hasLayout) {
-                       cur.errorMessage(string(N_("Layout ")) + lyx::to_utf8(cmd.argument()) +
-                               N_(" not known"));
+                       cur.errorMessage(lyx::from_utf8(N_("Layout ")) + cmd.argument() +
+                               lyx::from_utf8(N_(" not known")));
                        break;
                }
 
@@ -1098,7 +1077,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                docstring::const_iterator end = cmd.argument().end();
                for (; cit != end; ++cit)
 #if 0
-                       bv->owner()->getIntl().getTransManager().
+                       bv->getIntl().getTransManager().
                                translateAndInsert(*cit, this);
 #else
                        insertChar(bv->cursor(), *cit);
@@ -1227,7 +1206,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_MATH_MACRO:
                if (cmd.argument().empty())
-                       cur.errorMessage(N_("Missing argument"));
+                       cur.errorMessage(lyx::from_utf8(N_("Missing argument")));
                else {
                        string s = lyx::to_utf8(cmd.argument());
                        string const s1 = token(s, ' ', 1);
@@ -1251,7 +1230,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_MATH_MATRIX:
        case LFUN_MATH_DELIM:
        case LFUN_MATH_BIGDELIM: {
-               cur.insert(new MathHullInset("simple"));
+               cur.insert(new InsetMathHull(hullSimple));
                cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
                cur.dispatch(cmd);
                break;
@@ -1410,7 +1389,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
                if (!cmd.argument().empty())
                        // FIXME: Are all these characters encoded in one byte in utf8?
-                       bv->owner()->getIntl().getTransManager()
+                       bv->getIntl().getTransManager()
                                .translateAndInsert(cmd.argument()[0], this);
                break;
 
@@ -1720,20 +1699,17 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
                enable = lyx::cap::numberOfSelections() > 0;
                break;
 
-       case LFUN_PARAGRAPH_MOVE_UP: {
+       case LFUN_PARAGRAPH_MOVE_UP:
                enable = cur.pit() > 0 && !cur.selection();
                break;
-       }
 
-       case LFUN_PARAGRAPH_MOVE_DOWN: {
+       case LFUN_PARAGRAPH_MOVE_DOWN:
                enable = cur.pit() < cur.lastpit() && !cur.selection();
                break;
-       }
 
-       case LFUN_INSET_DISSOLVE: {
-               enable = !isMainText() && cur.inTexted();
+       case LFUN_INSET_DISSOLVE:
+               enable = !isMainText() && cur.inset().nargs() == 1;
                break;
-       }
 
        case LFUN_WORD_DELETE_FORWARD:
        case LFUN_WORD_DELETE_BACKWARD: