#include "undo_funcs.h"
#include "buffer.h"
#include "bufferparams.h"
+#include "errorlist.h"
#include "gettext.h"
#include "BufferView.h"
#include "CutAndPaste.h"
#include "paragraph_funcs.h"
#include "insets/insetbibitem.h"
+#include "insets/insetenv.h"
#include "insets/insetfloat.h"
#include "insets/insetwrap.h"
// No, try to see if we are inside a collapsable inset
if (inset_owner && inset_owner->owner()
&& inset_owner->owner()->isOpen()) {
- bv()->unlockInset(static_cast<UpdatableInset *>(inset_owner->owner()));
+ bv()->unlockInset(inset_owner->owner());
inset_owner->owner()->close(bv());
bv()->getLyXText()->cursorRight(bv());
}
++endpit;
}
- setUndo(bv(), Undo::EDIT, sstart_cur.par(), undoendpit);
+ setUndo(bv(), Undo::EDIT, sstart_cur.par(), boost::prior(undoendpit));
// ok we have a selection. This is always between sstart_cur
// and sel_end cursor
// set layout over selection and make a total rebreak of those paragraphs
void LyXText::setLayout(string const & layout)
{
- LyXCursor tmpcursor = cursor; /* store the current cursor */
+ LyXCursor tmpcursor = cursor; // store the current cursor
// if there is no selection just set the layout
- // of the current paragraph */
+ // of the current paragraph
if (!selection.set()) {
selection.start = cursor; // dummy selection
selection.end = cursor;
}
+
+ // special handling of new environment insets
+ BufferParams const & params = bv()->buffer()->params;
+ LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
+ if (lyxlayout->is_environment) {
+ // move everything in a new environment inset
+ lyxerr << "setting layout " << layout << endl;
+ bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
+ bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
+ bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
+ Inset * inset = new InsetEnvironment(params, layout);
+ if (bv()->insertInset(inset)) {
+ //inset->edit(bv());
+ //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
+ }
+ else
+ delete inset;
+ return;
+ }
+
ParagraphList::iterator endpit = setLayout(cursor, selection.start,
selection.end, layout);
redoParagraphs(selection.start, endpit);
// we have to reset the selection, because the
// geometry could have changed
- setCursor(selection.start.par(),
- selection.start.pos(), false);
+ setCursor(selection.start.par(), selection.start.pos(), false);
selection.cursor = cursor;
setCursor(selection.end.par(), selection.end.pos(), false);
updateCounters();
ParagraphList::iterator pastend = boost::next(end);
if (!test_only)
- setUndo(bv(), Undo::EDIT, start, pastend);
+ setUndo(bv(), Undo::EDIT, start, end);
bool changed = false;
// ok we have a selection. This is always between sel_start_cursor
// and sel_end cursor
- setUndo(bv(), Undo::EDIT,
- selection.start.par(), boost::next(selection.end.par()));
+ setUndo(bv(), Undo::EDIT, selection.start.par(), selection.end.par());
freezeUndo();
cursor = selection.start;
while (cursor.par() != selection.end.par() ||
}
-// deletes and inserts again all paragaphs between the cursor
+// deletes and inserts again all paragraphs between the cursor
// and the specified par
// This function is needed after SetLayout and SetFont etc.
void LyXText::redoParagraphs(LyXCursor const & cur,
if (tmprit == rows().begin()) {
// A trick/hack for UNDO.
// This is needed because in an UNDO/REDO we could have
- // changed the ownerParagrah() so the paragraph inside
+ // changed the ownerParagraph() so the paragraph inside
// the row is NOT my really first par anymore.
// Got it Lars ;) (Jug 20011206)
first_phys_pit = ownerParagraphs().begin();
}
if (prevrit != rows().end()) {
setHeightOfRow(prevrit);
- const_cast<LyXText *>(this)->postPaint(y - prevrit->height());
+ postPaint(y - prevrit->height());
} else {
setHeightOfRow(rows().begin());
- const_cast<LyXText *>(this)->postPaint(0);
+ postPaint(0);
}
if (tmprit != rows().end())
setHeightOfRow(tmprit);
void LyXText::cursorBottom()
{
-#warning FIXME
- // This is how it should be:
- // ParagraphList::iterator lastpit = boost::prior(ownerParagraphs().end());
- ParagraphList::iterator lastpit = &ownerParagraphs().back();
- int pos = lastpit->size();
- setCursor(lastpit, pos);
+ ParagraphList::iterator lastpit =
+ boost::prior(ownerParagraphs().end());
+ setCursor(lastpit, lastpit->size());
}
++endpit;
}
- setUndo(bv(), Undo::EDIT, selection.start.par(), undoendpit);
+ setUndo(bv(), Undo::EDIT, selection.start.par(),
+ boost::prior(undoendpit));
ParagraphList::iterator tmppit = selection.end.par();
isOK = true;
break;
} else {
- tmppit = in->parOwner();
+ tmppit = std::find(ownerParagraphs().begin(), ownerParagraphs().end(), *in->parOwner());
}
}
string const oldLabel = pit->params().labelString();
- int maxdepth = 0;
+ size_t maxdepth = 0;
if (pit != ownerParagraphs().begin())
maxdepth = boost::prior(pit)->getMaxDepthAfter();
{
if (!cursor.par()->insetAllowed(inset->lyxCode()))
return;
- setUndo(bv(), Undo::FINISH, cursor.par(),
- boost::next(cursor.par()));
+ setUndo(bv(), Undo::FINISH, cursor.par());
freezeUndo();
cursor.par()->insertInset(cursor.pos(), inset);
// Just to rebreak and refresh correctly.
++endpit;
}
- setUndo(bv(), Undo::DELETE, selection.start.par(), undoendpit);
+ setUndo(bv(), Undo::DELETE, selection.start.par(),
+ boost::prior(undoendpit));
endpit = selection.end.par();
if (!CutAndPaste::checkPastePossible())
return;
- setUndo(bv(), Undo::INSERT,
- cursor.par(), boost::next(cursor.par()));
+ setUndo(bv(), Undo::INSERT, cursor.par());
ParagraphList::iterator endpit;
PitPosPair ppp;
+ ErrorList el;
+
boost::tie(ppp, endpit) =
CutAndPaste::pasteSelection(ownerParagraphs(),
cursor.par(), cursor.pos(),
- bv()->buffer()->params.textclass);
+ bv()->buffer()->params.textclass,
+ el);
+ bv()->setErrorList(el);
+ bv()->showErrorList(_("Paste"));
redoParagraphs(cursor, endpit);
void LyXText::setCursorIntern(ParagraphList::iterator pit,
pos_type pos, bool setfont, bool boundary)
{
- InsetText * it = static_cast<InsetText *>(pit->inInset());
+ UpdatableInset * it = pit->inInset();
if (it) {
if (it != inset_owner) {
lyxerr[Debug::INSETS] << "InsetText is " << it
y -= topy;
Inset * inset_hit = checkInsetHit(x, y1);
if (inset_hit && isHighlyEditableInset(inset_hit)) {
- inset_hit->edit(bv(), x, y - (y2 - y1), mouse_button::none);
+ inset_hit->localDispatch(
+ FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
}
}
#else
y -= topy;
Inset * inset_hit = checkInsetHit(x, y1);
if (inset_hit && isHighlyEditableInset(inset_hit)) {
- inset_hit->edit(bv(), x, y - (y2 - y1), mouse_button::none);
+ FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
+ inset_hit->localDispatch(cmd);
}
}
#else
++endpit;
}
- setUndo(bv(), Undo::DELETE, old_cursor.par(), endpit);
+ setUndo(bv(), Undo::DELETE, old_cursor.par(),
+ boost::prior(endpit));
cursor = tmpcursor;
// delete old row
++endpit;
}
- setUndo(bv(), Undo::DELETE, old_cursor.par(), endpit);
+ setUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
cursor = tmpcursor;
// delete old row