#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());
}
}
// CHECK if this is really needed. (Lgb)
bv()->buffer()->params.getLyXTextClass().counters().reset();
- for (; pit != ownerParagraphs().end(); ++pit) {
+ ParagraphList::iterator beg = ownerParagraphs().begin();
+ ParagraphList::iterator end = ownerParagraphs().end();
+ for (; pit != end; ++pit) {
while (rowit->par() != pit)
++rowit;
string const oldLabel = pit->params().labelString();
- int maxdepth = 0;
- if (pit != ownerParagraphs().begin())
+ size_t maxdepth = 0;
+ if (pit != beg)
maxdepth = boost::prior(pit)->getMaxDepthAfter();
if (pit->params().depth() > maxdepth)
{
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();
int endpos = selection.end.pos();
boost::tie(endpit, endpos) = realcut ?
- CutAndPaste::cutSelection(ownerParagraphs(),
+ CutAndPaste::cutSelection(bv()->buffer()->params,
+ ownerParagraphs(),
selection.start.par(), endpit,
selection.start.pos(), endpos,
bv()->buffer()->params.textclass,
doclear)
- : CutAndPaste::eraseSelection(ownerParagraphs(),
+ : CutAndPaste::eraseSelection(bv()->buffer()->params,
+ ownerParagraphs(),
selection.start.par(), endpit,
selection.start.pos(), endpos,
doclear);
}
-void LyXText::pasteSelection()
+void LyXText::pasteSelection(size_t sel_index)
{
// this does not make sense, if there is nothing to paste
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(),
+ CutAndPaste::pasteSelection(*bv()->buffer(),
+ ownerParagraphs(),
cursor.par(), cursor.pos(),
- bv()->buffer()->params.textclass);
+ bv()->buffer()->params.textclass,
+ sel_index, el);
+ bv()->setErrorList(el);
+ bv()->showErrorList(_("Paste"));
redoParagraphs(cursor, endpit);
selection.start.pos());
// Insert the new string
- for (string::const_iterator cit = str.begin(); cit != str.end(); ++cit) {
+ string::const_iterator cit = str.begin();
+ string::const_iterator end = str.end();
+ for (; cit != end; ++cit) {
selection.end.par()->insertChar(pos, (*cit), font);
++pos;
}
{
string linestr(str);
bool newline_inserted = false;
- for (string::size_type i = 0; i < linestr.length(); ++i) {
+ string::size_type const siz = linestr.length();
+
+ for (string::size_type i = 0; i < siz; ++i) {
if (linestr[i] == '\n') {
if (newline_inserted) {
// we know that \r will be ignored by
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
boundary = false;
// This (rtl_support test) is not needed, but gives
// some speedup if rtl_support=false
+ RowList::iterator next_rit = boost::next(rit);
+
bool const lastrow = lyxrc.rtl_support &&
- (boost::next(rit) == rowlist_.end() ||
- boost::next(rit)->par() != rit_par);
+ (next_rit == rowlist_.end() ||
+ next_rit->par() != rit_par);
+
// If lastrow is false, we don't need to compute
// the value of rtl.
bool const rtl = (lastrow)
* and the next row is filled by an inset that spans an entire
* row.
*/
- bool beforeFullRowInset(LyXText & lt, LyXCursor const & cur) {
+ bool beforeFullRowInset(LyXText & lt, LyXCursor const & cur)
+ {
RowList::iterator row = cur.row();
if (boost::next(row) == lt.rows().end())
return false;
+
Row const & next = *boost::next(row);
if (next.pos() != cur.pos() || next.par() != cur.par())
if (cur.pos() == cur.par()->size()
|| !cur.par()->isInset(cur.pos()))
return false;
+
Inset const * inset = cur.par()->getInset(cur.pos());
if (inset->needFullRow() || inset->display())
return true;
+
return false;
}
}
cur.row(row);
if (beforeFullRowInset(*this, cur)) {
- pos_type last = lastPrintablePos(*this, row);
- float x = getCursorX(boost::next(row), cur.pos(), last, bound);
+ pos_type const last = lastPrintablePos(*this, row);
+ RowList::iterator next_row = boost::next(row);
+
+ float x = getCursorX(next_row, cur.pos(), last, bound);
cur.ix(int(x));
- cur.iy(y + row->height() + boost::next(row)->baseline());
- cur.irow(boost::next(row));
+ cur.iy(y + row->height() + next_row->baseline());
+ cur.irow(next_row);
} else {
cur.iy(cur.y());
cur.ix(cur.x());
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
void LyXText::cursorDownParagraph()
{
- if (boost::next(cursor.par()) != ownerParagraphs().end()) {
- setCursor(boost::next(cursor.par()), 0);
+ ParagraphList::iterator par = cursor.par();
+ ParagraphList::iterator next_par = boost::next(par);
+
+ if (next_par != ownerParagraphs().end()) {
+ setCursor(next_par, 0);
} else {
- setCursor(cursor.par(), cursor.par()->size());
+ setCursor(par, par->size());
}
}
return false;
// Do not delete empty paragraphs with keepempty set.
- if (old_cursor.par()->layout()->keepempty)
+ if (old_cursor.par()->allowEmpty())
return false;
// only do our magic if we changed paragraph
++endpit;
}
- setUndo(bv(), Undo::DELETE, old_cursor.par(), endpit);
+ setUndo(bv(), Undo::DELETE, old_cursor.par(),
+ boost::prior(endpit));
cursor = tmpcursor;
// delete old row
* the parindent that can occur or dissappear.
* The next row can change its height, if
* there is another layout before */
- if (boost::next(prevrow) != rows().end()) {
- breakAgain(boost::next(prevrow));
+ RowList::iterator tmprit = boost::next(prevrow);
+ if (tmprit != rows().end()) {
+ breakAgain(tmprit);
updateCounters();
}
setHeightOfRow(prevrow);
++endpit;
}
- setUndo(bv(), Undo::DELETE, old_cursor.par(), endpit);
+ setUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
cursor = tmpcursor;
// delete old row