X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FText3.cpp;h=3dd736b9dd698d399466b69d843bb7d5568cb530;hb=f7feff9fb34928d2b3d16984527bd1f6fe7f9343;hp=4f5d3dcf426a277795281bbd5957e2a3934495aa;hpb=40f58da65a2adda0fa0bebe6ab714fe347ead302;p=lyx.git diff --git a/src/Text3.cpp b/src/Text3.cpp index 4f5d3dcf42..3dd736b9dd 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -57,6 +57,8 @@ #include "insets/InsetSpecialChar.h" #include "insets/InsetText.h" #include "insets/InsetInfo.h" +#include "insets/InsetGraphics.h" +#include "insets/InsetGraphicsParams.h" #include "support/convert.h" #include "support/debug.h" @@ -131,7 +133,9 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display) const int old_pos = cur.pos(); #endif cur.insert(new InsetMathHull(hullSimple)); - BOOST_ASSERT(old_pos == cur.pos()); +#ifdef ENABLE_ASSERTIONS + LASSERT(old_pos == cur.pos(), /**/); +#endif cur.nextInset()->edit(cur, true); // don't do that also for LFUN_MATH_MODE // unless you want end up with always changing @@ -154,7 +158,7 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display) { InsetMathHull * formula = new InsetMathHull; istringstream is(to_utf8(sel)); - Lexer lex(0, 0); + Lexer lex; lex.setStream(is); formula->read(lex); if (formula->getType() == hullNone) @@ -284,6 +288,9 @@ static void outline(OutlineOp mode, Cursor & cur) switch (mode) { case OutlineUp: { + if (start == pars.begin()) + // Nothing to move. + return; ParagraphList::iterator dest = start; // Move out (up) from this header if (dest == bgn) @@ -309,7 +316,19 @@ static void outline(OutlineOp mode, Cursor & cur) return; } case OutlineDown: { - ParagraphList::iterator dest = finish; + if (finish == end) + // Nothing to move. + return; + // Go one down from *this* header: + ParagraphList::iterator dest = boost::next(finish, 1); + // Go further down to find header to insert in front of: + for (; dest != end; ++dest) { + toclevel = dest->layout().toclevel; + if (toclevel != Layout::NOT_IN_TOC + && toclevel <= thistoclevel) { + break; + } + } // One such was found: pit_type newpit = distance(bgn, dest); pit_type const len = distance(start, finish); @@ -390,7 +409,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) // at the end? cur.noUpdate(); - BOOST_ASSERT(cur.text() == this); + LASSERT(cur.text() == this, /**/); CursorSlice oldTopSlice = cur.top(); bool oldBoundary = cur.boundary(); bool sel = cur.selection(); @@ -616,16 +635,26 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_WORD_RIGHT: case LFUN_WORD_RIGHT_SELECT: - //FIXME: for visual cursor mode, really move right - if (reverseDirectionNeeded(cur)) { - cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ? - LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD; + if (lyxrc.visual_cursor) { + needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_RIGHT_SELECT); + needsUpdate |= cursorVisRightOneWord(cur); + if (!needsUpdate && oldTopSlice == cur.top() + && cur.boundary() == oldBoundary) { + cur.undispatched(); + cmd = FuncRequest(LFUN_FINISHED_RIGHT); + } } else { - cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ? - LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD; + if (reverseDirectionNeeded(cur)) { + cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ? + LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD; + } else { + cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ? + LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD; + } + dispatch(cur, cmd); + return; } - dispatch(cur, cmd); - return; + break; case LFUN_WORD_FORWARD: case LFUN_WORD_FORWARD_SELECT: @@ -635,16 +664,26 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_WORD_LEFT: case LFUN_WORD_LEFT_SELECT: - //FIXME: for visual cursor mode, really move left - if (reverseDirectionNeeded(cur)) { - cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ? - LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD; + if (lyxrc.visual_cursor) { + needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_LEFT_SELECT); + needsUpdate |= cursorVisLeftOneWord(cur); + if (!needsUpdate && oldTopSlice == cur.top() + && cur.boundary() == oldBoundary) { + cur.undispatched(); + cmd = FuncRequest(LFUN_FINISHED_LEFT); + } } else { - cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ? - LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD; + if (reverseDirectionNeeded(cur)) { + cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ? + LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD; + } else { + cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ? + LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD; + } + dispatch(cur, cmd); + return; } - dispatch(cur, cmd); - return; + break; case LFUN_WORD_BACKWARD: case LFUN_WORD_BACKWARD_SELECT: @@ -836,17 +875,47 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) break; case LFUN_INSET_SETTINGS: { - // if there is an inset at cursor, access this - Inset * inset = cur.nextInset(); - if (inset) { - inset->showInsetDialog(bv); + Inset & inset = cur.inset(); + if (cmd.getArg(0) == insetName(inset.lyxCode())) { + // This inset dialog has been explicitely requested. + inset.showInsetDialog(bv); + break; + } + // else, if there is an inset at the cursor, access this + Inset * next_inset = cur.nextInset(); + if (next_inset) { + next_inset->showInsetDialog(bv); break; } - // if not work, access the underlying inset. - cur.inset().showInsetDialog(bv); + // if not then access the underlying inset. + inset.showInsetDialog(bv); break; } + case LFUN_SET_GRAPHICS_GROUP: { + Inset * instmp = &cur.inset(); + if (instmp->lyxCode() != GRAPHICS_CODE) instmp = cur.nextInset(); + if (!instmp || instmp->lyxCode() != GRAPHICS_CODE) break; + + cur.recordUndoFullDocument(); + Inset & inset = *instmp; + InsetGraphics & ins = static_cast(inset); + + string id = to_utf8(cmd.argument()); + string grp = InsetGraphics::getGroupParams(bv->buffer(), id); + InsetGraphicsParams tmp, inspar = ins.getParams(); + + if (id.empty()) + inspar.groupId = to_utf8(cmd.argument()); + else { + InsetGraphics::string2params(grp, bv->buffer(), tmp); + tmp.filename = inspar.filename; + inspar = tmp; + } + + ins.setParams(inspar); + } + case LFUN_SPACE_INSERT: if (cur.paragraph().layout().free_spacing) insertChar(cur, ' '); @@ -924,7 +993,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) else if (arg == "linkback") type = Clipboard::LinkBackGraphicsType; else - BOOST_ASSERT(false); + LASSERT(false, /**/); pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type); } @@ -964,15 +1033,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) break; } - case LFUN_SERVER_GET_FONT: - if (cur.current_font.fontInfo().shape() == ITALIC_SHAPE) - cur.message(from_ascii("E")); - else if (cur.current_font.fontInfo().shape() == SMALLCAPS_SHAPE) - cur.message(from_ascii("N")); - else - cur.message(from_ascii("0")); - break; - case LFUN_SERVER_GET_LAYOUT: cur.message(cur.paragraph().layout().name()); break; @@ -1170,6 +1230,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) cur.updateFlags(Update::SinglePar | Update::FitCursor); break; } + default: + break; } // switch (cmd.button()) break; @@ -1285,7 +1347,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) } p["target"] = (cmd.argument().empty()) ? content : cmd.argument(); - string const data = InsetCommandMailer::params2string("href", p); + string const data = InsetCommand::params2string("href", p); if (p["target"].empty()) { bv->showDialog("href", data); } else { @@ -1301,7 +1363,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) p["name"] = (cmd.argument().empty()) ? cur.getPossibleLabel() : cmd.argument(); - string const data = InsetCommandMailer::params2string("label", p); + string const data = InsetCommand::params2string("label", p); if (cmd.argument().empty()) { bv->showDialog("label", data); @@ -1485,7 +1547,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) cap::replaceSelection(cur); cur.insert(new InsetMathHull(hullSimple)); checkAndActivateInset(cur, true); - BOOST_ASSERT(cur.inMathed()); + LASSERT(cur.inMathed(), /**/); cur.dispatch(cmd); break; } @@ -1671,8 +1733,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) breakParagraph(cur); } - //FIXME Check if this should be emptyLayout() - setLayout(cur, tclass.defaultLayoutName()); + docstring const laystr = cur.inset().useEmptyLayout() ? + tclass.emptyLayoutName() : + tclass.defaultLayoutName(); + setLayout(cur, laystr); ParagraphParameters p; setParagraphs(cur, p); // FIXME This should be simplified when InsetFloatList takes a @@ -1823,7 +1887,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { - BOOST_ASSERT(cur.text() == this); + LASSERT(cur.text() == this, /**/); Font const & font = cur.real_current_font; FontInfo const & fontinfo = font.fontInfo(); @@ -2163,7 +2227,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_CHARS_TRANSPOSE: case LFUN_SERVER_GET_XY: case LFUN_SERVER_SET_XY: - case LFUN_SERVER_GET_FONT: case LFUN_SERVER_GET_LAYOUT: case LFUN_LAYOUT: case LFUN_DATE_INSERT: @@ -2214,6 +2277,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_BUFFER_BEGIN_SELECT: case LFUN_BUFFER_END_SELECT: case LFUN_UNICODE_INSERT: + case LFUN_SET_GRAPHICS_GROUP: // these are handled in our dispatch() enable = true; break;