X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftext3.C;h=7f0e8465726625e9381ab528e8290b07c0e51a14;hb=8ebf862adbe377d032f888a82d88d4393aebc929;hp=d0aea0fc32fcc04fccb5b20d4ee1aa25ca4d02a9;hpb=1fc0c01877f19d8194b6b22e61aa3db5fa2b1671;p=lyx.git diff --git a/src/text3.C b/src/text3.C index d0aea0fc32..7f0e846572 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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 @@ -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; @@ -144,7 +140,7 @@ namespace { void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display) { recordUndo(cur); - string sel = cur.selectionAsString(false); + string sel = lyx::to_utf8(cur.selectionAsString(false)); //lyxerr << "selection is: '" << sel << "'" << endl; // It may happen that sel is empty but there is a selection @@ -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(cursorX(cur.top(), cur.boundary())) + ' ' - + convert(cursorY(cur.top(), cur.boundary()))); + cur.message(lyx::from_utf8( + convert(cursorX(cur.top(), cur.boundary())) + ' ' + + convert(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; } @@ -904,7 +883,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_CLIPBOARD_PASTE: { cur.clearSelection(); - string const clip = bv->owner()->gui().clipboard().get(); + docstring const clip = bv->owner()->gui().clipboard().get(); if (!clip.empty()) { recordUndo(cur); if (cmd.argument() == "paragraph") @@ -917,7 +896,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_PRIMARY_SELECTION_PASTE: { cur.clearSelection(); - string const clip = bv->owner()->gui().selection().get(); + docstring const clip = bv->owner()->gui().selection().get(); if (!clip.empty()) { recordUndo(cur); if (cmd.argument() == "paragraph") @@ -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; @@ -1449,7 +1428,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) } case LFUN_THESAURUS_ENTRY: { - string arg = lyx::to_utf8(cmd.argument()); + docstring arg = cmd.argument(); if (arg.empty()) { arg = cur.selectionAsString(false); // FIXME @@ -1459,7 +1438,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) arg = cur.selectionAsString(false); } } - bv->owner()->getDialogs().show("thesaurus", arg); + bv->owner()->getDialogs().show("thesaurus", lyx::to_utf8(arg)); 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 = &cur.inset() && cur.inTexted(); + case LFUN_INSET_DISSOLVE: + enable = !isMainText() && cur.inset().nargs() == 1; break; - } case LFUN_WORD_DELETE_FORWARD: case LFUN_WORD_DELETE_BACKWARD: