more ParagraphList work

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6362 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-03-06 10:02:40 +00:00
parent 01ecde6ab8
commit 3bee5faf12
13 changed files with 114 additions and 66 deletions

View File

@ -1315,13 +1315,13 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
beforeChange(bv_->text);
if (!lout.empty()) {
update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
bv_->text->breakParagraph(bv_);
bv_->text->breakParagraph(bv_, bv_->buffer()->paragraphs);
update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
if (!bv_->text->cursor.par()->empty()) {
bv_->text->cursorLeft(bv_);
bv_->text->breakParagraph(bv_);
bv_->text->breakParagraph(bv_, bv_->buffer()->paragraphs);
update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
}

View File

@ -1,3 +1,27 @@
2003-03-06 Lars Gullik Bjønnes <larsbj@gullik.net>
* text3.C (dispatch): adjust
* text.C (breakParagraph): add a ParagraphList as arg
* paragraph_funcs.C (breakParagraph): change to take a
BufferParams and a ParagraphList as args.
(breakParagraphConservative): ditto
(mergeParagraph): ditto
(TeXDeeper): add a ParagraphList arg
(TeXEnvironment): ditto
(TeXOnePar): ditto
* buffer.C (readLyXformat2): adjust
(insertStringAsLines): adjust
(latexParagraphs): adjust
* CutAndPaste.C (cutSelection): use 'true' not '1' as truth value.
(cutSelection): adjust
(pasteSelection): adjust
* BufferView_pimpl.C (insertInset): adjust
2003-03-05 Angus Leeming <leeming@lyx.org>
* commandtags.h:

View File

@ -113,7 +113,7 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
Paragraph * pit = startpar->next();
while (1) {
while (true) {
// *endpar can be 0
if (!pit)
break;
@ -165,7 +165,11 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
// paste the paragraphs again, if possible
if (startpar->hasSameLayout(startpar->next()) ||
startpar->next()->empty()) {
mergeParagraph(buffer, startpar);
#warning This is suspect. (Lgb)
// When doing this merge we must know if the par really
// belongs to an inset, and if it does then we have to use
// the insets paragraphs, and not the buffers. (Lgb)
mergeParagraph(buffer->params, buffer->paragraphs, startpar);
// this because endpar gets deleted here!
(*endpar) = startpar;
}
@ -361,7 +365,7 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
// if necessary
if (((*par)->size() > pos) || !(*par)->next()) {
breakParagraphConservative(
current_view->buffer(), *par, pos);
current_view->buffer()->params, current_view->buffer()->paragraphs, *par, pos);
paste_the_end = true;
}
// set the end for redoing later
@ -377,20 +381,23 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
if ((*par)->next() == lastbuffer)
lastbuffer = *par;
mergeParagraph(current_view->buffer(), *par);
mergeParagraph(current_view->buffer()->params,
current_view->buffer()->paragraphs, *par);
// store the new cursor position
*par = lastbuffer;
pos = lastbuffer->size();
// maybe some pasting
if (lastbuffer->next() && paste_the_end) {
if (lastbuffer->next()->hasSameLayout(lastbuffer)) {
mergeParagraph(current_view->buffer(), lastbuffer);
mergeParagraph(current_view->buffer()->params,
current_view->buffer()->paragraphs, lastbuffer);
} else if (!lastbuffer->next()->size()) {
lastbuffer->next()->makeSameLayout(lastbuffer);
mergeParagraph(current_view->buffer(), lastbuffer);
mergeParagraph(current_view->buffer()->params, current_view->buffer()->paragraphs, lastbuffer);
} else if (!lastbuffer->size()) {
lastbuffer->makeSameLayout(lastbuffer->next());
mergeParagraph(current_view->buffer(), lastbuffer);
mergeParagraph(current_view->buffer()->params,
current_view->buffer()->paragraphs, lastbuffer);
} else
lastbuffer->next()->stripLeadingSpaces();
}

View File

@ -317,7 +317,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
par->layout(params.getLyXTextClass().defaultLayout());
} else {
// We are inserting into an existing document
users->text->breakParagraph(users);
users->text->breakParagraph(users, paragraphs);
first_par = users->text->ownerParagraph();
pos = 0;
markDirty();
@ -1030,7 +1030,7 @@ void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
cit != str.end(); ++cit) {
if (*cit == '\n') {
if (autobreakrows && (!par->empty() || layout->keepempty)) {
breakParagraph(this, par, pos,
breakParagraph(params, paragraphs, par, pos,
layout->isEnvironment());
par = par->next();
pos = 0;
@ -1867,12 +1867,12 @@ void Buffer::latexParagraphs(ostream & ofs,
if (layout->isEnvironment() ||
!par->params().leftIndent().zero())
{
par = TeXEnvironment(this, params, par, ofs, texrow);
par = TeXEnvironment(this, params, paragraphs, par, ofs, texrow);
} else {
par = TeXOnePar(this, params, par, ofs, texrow, moving_arg);
par = TeXOnePar(this, params, paragraphs, par, ofs, texrow, moving_arg);
}
} else {
par = TeXOnePar(this, params, par, ofs, texrow, moving_arg);
par = TeXOnePar(this, params, paragraphs, par, ofs, texrow, moving_arg);
}
}
// It might be that we only have a title in this document

View File

@ -1,3 +1,10 @@
2003-03-06 Lars Gullik Bjønnes <larsbj@gullik.net>
* insettext.C (updateLocal): un-const function
(updateLocal): adjust
(collapseParagraphs): un-const function
(collapseParagraphs): adjust
2003-03-05 Angus Leeming <leeming@lyx.org>
* insetwrap.[Ch]: define a new class InsetWrapMailer and use

View File

@ -635,7 +635,7 @@ void InsetText::setUpdateStatus(BufferView * bv, int what) const
}
void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty)
{
if (!autoBreakRows && paragraphs.begin()->next())
collapseParagraphs(bv);
@ -1448,7 +1448,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
result = DISPATCHED;
break;
}
lt->breakParagraph(bv, 0);
lt->breakParagraph(bv, paragraphs, 0);
updwhat = CURSOR | FULL;
updflag = true;
break;
@ -1457,7 +1457,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
result = DISPATCHED;
break;
}
lt->breakParagraph(bv, 1);
lt->breakParagraph(bv, paragraphs, 1);
updwhat = CURSOR | FULL;
updflag = true;
break;
@ -2388,7 +2388,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
t->first_y = bv->screen().topCursorVisible(t->cursor, t->first_y);
if (!owner()) {
updateLocal(bv, FULL, false);
const_cast<InsetText*>(this)->updateLocal(bv, FULL, false);
// this will scroll the screen such that the cursor becomes visible
bv->updateScrollbar();
} else {
@ -2427,7 +2427,7 @@ void InsetText::reinitLyXText() const
}
t->first_y = bv->screen().topCursorVisible(t->cursor, t->first_y);
if (!owner()) {
updateLocal(bv, FULL, false);
const_cast<InsetText*>(this)->updateLocal(bv, FULL, false);
// this will scroll the screen such that the cursor becomes visible
bv->updateScrollbar();
} else {
@ -2768,7 +2768,7 @@ bool InsetText::checkInsertChar(LyXFont & font)
}
void InsetText::collapseParagraphs(BufferView * bv) const
void InsetText::collapseParagraphs(BufferView * bv)
{
LyXText * llt = getLyXText(bv);
@ -2790,7 +2790,7 @@ void InsetText::collapseParagraphs(BufferView * bv) const
llt->selection.end.pos() + paragraphs.begin()->size());
}
}
mergeParagraph(bv->buffer(), paragraphs.begin());
mergeParagraph(bv->buffer()->params, paragraphs, paragraphs.begin());
}
reinitLyXText();
}
@ -2837,7 +2837,7 @@ void InsetText::appendParagraphs(Buffer * buffer,
// paste it!
lastbuffer->next(buf);
buf->previous(lastbuffer);
mergeParagraph(buffer, lastbuffer);
mergeParagraph(buffer->params, paragraphs, lastbuffer);
reinitLyXText();
}

View File

@ -262,7 +262,7 @@ public:
ParagraphList paragraphs;
protected:
///
void updateLocal(BufferView *, int what, bool mark_dirty) const;
void updateLocal(BufferView *, int what, bool mark_dirty);
/// set parameters for an initial lock of this inset
void lockInset(BufferView *);
/// lock an inset inside this one
@ -358,7 +358,7 @@ private:
///
void reinitLyXText() const;
///
void collapseParagraphs(BufferView *) const;
void collapseParagraphs(BufferView *);
/* Private structures and variables */
///

View File

@ -28,6 +28,7 @@ class Spacing;
class UpdatableInset;
class VSpace;
class WordLangTuple;
class ParagraphList;
/**
@ -106,7 +107,8 @@ public:
///
void breakAgainOneRow(BufferView *, Row * row);
/// what you expect when pressing <enter> at cursor position
void breakParagraph(BufferView *, char keep_layout = 0);
void breakParagraph(BufferView *,
ParagraphList & paragraphs, char keep_layout = 0);
/** set layout over selection and make a total rebreak of
those paragraphs

View File

@ -817,7 +817,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
case LFUN_INSET_APPLY: {
string const name = cmd.getArg(0);
InsetBase * base =
InsetBase * base =
bv->owner()->getDialogs().getOpenInset(name);
if (base) {

View File

@ -29,16 +29,15 @@ using lyx::pos_type;
using std::endl;
using std::ostream;
void breakParagraph(Buffer * buf,
void breakParagraph(BufferParams const & bparams,
ParagraphList & paragraphs,
ParagraphList::iterator par,
pos_type pos,
int flag)
{
BufferParams const & bparams = buf->params;
// create a new paragraph, and insert into the list
ParagraphList::iterator tmp = buf->paragraphs.insert(boost::next(par),
new Paragraph);
ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
new Paragraph);
// without doing that we get a crash when typing <Return> at the
// end of a paragraph
@ -130,15 +129,14 @@ void breakParagraph(Buffer * buf,
}
void breakParagraphConservative(Buffer * buf,
void breakParagraphConservative(BufferParams const & bparams,
ParagraphList & paragraphs,
ParagraphList::iterator par,
pos_type pos)
{
BufferParams const & bparams = buf->params;
// create a new paragraph
ParagraphList::iterator tmp = buf->paragraphs.insert(boost::next(par),
new Paragraph);
ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
new Paragraph);
tmp->makeSameLayout(&*par);
// When can pos > Last()?
@ -161,10 +159,10 @@ void breakParagraphConservative(Buffer * buf,
}
void mergeParagraph(Buffer * buf, ParagraphList::iterator par)
void mergeParagraph(BufferParams const & bparams,
ParagraphList & paragraphs,
ParagraphList::iterator par)
{
BufferParams const & bparams = buf->params;
ParagraphList::iterator the_next = boost::next(par);
// first the DTP-stuff
@ -182,7 +180,7 @@ void mergeParagraph(Buffer * buf, ParagraphList::iterator par)
++j;
}
buf->paragraphs.erase(the_next);
paragraphs.erase(the_next);
}
@ -255,18 +253,19 @@ int getEndLabel(Paragraph * para, BufferParams const & bparams)
ParagraphList::iterator
TeXDeeper(Buffer const * buf,
BufferParams const & bparams,
ParagraphList const & paragraphs,
ParagraphList::iterator pit,
ostream & os, TexRow & texrow)
{
lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
ParagraphList::iterator par = pit;
while (par != buf->paragraphs.end()&& par->params().depth() == pit->params().depth()) {
while (par != paragraphs.end()&& par->params().depth() == pit->params().depth()) {
if (par->layout()->isEnvironment()) {
par = TeXEnvironment(buf, bparams, par,
par = TeXEnvironment(buf, bparams, paragraphs, par,
os, texrow);
} else {
par = TeXOnePar(buf, bparams, par,
par = TeXOnePar(buf, bparams, paragraphs, par,
os, texrow, false);
}
}
@ -279,6 +278,7 @@ TeXDeeper(Buffer const * buf,
ParagraphList::iterator
TeXEnvironment(Buffer const * buf,
BufferParams const & bparams,
ParagraphList const & paragraphs,
ParagraphList::iterator pit,
ostream & os, TexRow & texrow)
{
@ -289,7 +289,7 @@ TeXEnvironment(Buffer const * buf,
Language const * language = pit->getParLanguage(bparams);
Language const * doc_language = bparams.language;
Language const * previous_language =
(pit != buf->paragraphs.begin())
(pit != paragraphs.begin())
? boost::prior(pit)->getParLanguage(bparams)
: doc_language;
if (language->babel() != previous_language->babel()) {
@ -338,9 +338,9 @@ TeXEnvironment(Buffer const * buf,
}
ParagraphList::iterator par = pit;
do {
par = TeXOnePar(buf, bparams, par, os, texrow, false);
par = TeXOnePar(buf, bparams, paragraphs, par, os, texrow, false);
if (par != buf->paragraphs.end()&& par->params().depth() > pit->params().depth()) {
if (par != paragraphs.end()&& par->params().depth() > pit->params().depth()) {
if (par->layout()->isParagraph()) {
// Thinko!
@ -360,9 +360,9 @@ TeXEnvironment(Buffer const * buf,
os << '\n';
texrow.newline();
}
par = TeXDeeper(buf, bparams, par, os, texrow);
par = TeXDeeper(buf, bparams, paragraphs, par, os, texrow);
}
} while (par != buf->paragraphs.end()
} while (par != paragraphs.end()
&& par->layout() == pit->layout()
&& par->params().depth() == pit->params().depth()
&& par->params().leftIndent() == pit->params().leftIndent());
@ -404,6 +404,7 @@ InsetOptArg * optArgInset(Paragraph const & par)
ParagraphList::iterator
TeXOnePar(Buffer const * buf,
BufferParams const & bparams,
ParagraphList const & paragraphs,
ParagraphList::iterator pit,
ostream & os, TexRow & texrow,
bool moving_arg)
@ -426,7 +427,7 @@ TeXOnePar(Buffer const * buf,
}
if (!pit->params().spacing().isDefault()
&& (pit == buf->paragraphs.begin() || !boost::prior(pit)->hasSameLayout(&*pit))) {
&& (pit == paragraphs.begin() || !boost::prior(pit)->hasSameLayout(&*pit))) {
os << pit->params().spacing().writeEnvirBegin() << '\n';
texrow.newline();
}
@ -462,14 +463,14 @@ TeXOnePar(Buffer const * buf,
Language const * language = pit->getParLanguage(bparams);
Language const * doc_language = bparams.language;
Language const * previous_language =
(pit != buf->paragraphs.begin())
(pit != paragraphs.begin())
? boost::prior(pit)->getParLanguage(bparams)
: doc_language;
if (language->babel() != previous_language->babel()
// check if we already put language command in TeXEnvironment()
&& !(style->isEnvironment()
&& (pit == buf->paragraphs.begin() ||
&& (pit == paragraphs.begin() ||
(boost::prior(pit)->layout() != pit->layout() &&
boost::prior(pit)->getDepth() <= pit->getDepth())
|| boost::prior(pit)->getDepth() < pit->getDepth())))
@ -543,7 +544,7 @@ TeXOnePar(Buffer const * buf,
bool is_command = style->isCommand();
if (style->resfont.size() != font.size()
&& boost::next(pit) != buf->paragraphs.end()
&& boost::next(pit) != paragraphs.end()
&& !is_command) {
if (!need_par)
os << '{';
@ -556,7 +557,7 @@ TeXOnePar(Buffer const * buf,
switch (style->latextype) {
case LATEX_ITEM_ENVIRONMENT:
case LATEX_LIST_ENVIRONMENT:
if (boost::next(pit) != buf->paragraphs.end()
if (boost::next(pit) != paragraphs.end()
&& (pit->params().depth() < boost::next(pit)->params().depth())) {
os << '\n';
texrow.newline();
@ -565,14 +566,14 @@ TeXOnePar(Buffer const * buf,
case LATEX_ENVIRONMENT:
// if its the last paragraph of the current environment
// skip it otherwise fall through
if (boost::next(pit) != buf->paragraphs.end()
if (boost::next(pit) != paragraphs.end()
&& (boost::next(pit)->layout() != pit->layout()
|| boost::next(pit)->params().depth() != pit->params().depth()))
break;
// fall through possible
default:
// we don't need it for the last paragraph!!!
if (boost::next(pit) != buf->paragraphs.end()) {
if (boost::next(pit) != paragraphs.end()) {
os << '\n';
texrow.newline();
}
@ -601,14 +602,14 @@ TeXOnePar(Buffer const * buf,
}
if (!pit->params().spacing().isDefault()
&& (boost::next(pit) == buf->paragraphs.end()|| !boost::next(pit)->hasSameLayout(&*pit))) {
&& (boost::next(pit) == paragraphs.end()|| !boost::next(pit)->hasSameLayout(&*pit))) {
os << pit->params().spacing().writeEnvirEnd() << '\n';
texrow.newline();
}
}
// we don't need it for the last paragraph!!!
if (boost::next(pit) != buf->paragraphs.end()) {
if (boost::next(pit) != paragraphs.end()) {
os << '\n';
texrow.newline();
} else {

View File

@ -21,13 +21,15 @@ class Paragraph;
class TexRow;
///
void breakParagraph(Buffer * buf,
void breakParagraph(BufferParams const & bparams,
ParagraphList & paragraphs,
ParagraphList::iterator par,
lyx::pos_type pos,
int flag);
///
void breakParagraphConservative(Buffer * buf,
void breakParagraphConservative(BufferParams const & bparams,
ParagraphList & paragraphs,
ParagraphList::iterator par,
lyx::pos_type pos);
@ -35,7 +37,8 @@ void breakParagraphConservative(Buffer * buf,
* Append the next paragraph onto the tail of this one.
* Be careful, this doesent make any check at all.
*/
void mergeParagraph(Buffer * buf,
void mergeParagraph(BufferParams const & bparams,
ParagraphList & paragraphs,
ParagraphList::iterator par);
@ -56,18 +59,21 @@ int getEndLabel(Paragraph * para, BufferParams const & bparams);
ParagraphList::iterator
TeXDeeper(Buffer const * buf,
BufferParams const & bparams,
ParagraphList const & paragraphs,
ParagraphList::iterator pit,
std::ostream & os, TexRow & texrow);
ParagraphList::iterator
TeXEnvironment(Buffer const * buf,
BufferParams const & bparams,
ParagraphList const & paragraphs,
ParagraphList::iterator pit,
std::ostream & os, TexRow & texrow);
ParagraphList::iterator
TeXOnePar(Buffer const * buf,
BufferParams const & bparams,
ParagraphList const & paragraphs,
ParagraphList::iterator pit,
std::ostream & os, TexRow & texrow,
bool moving_arg);

View File

@ -1324,7 +1324,8 @@ void LyXText::breakAgainOneRow(BufferView * bview, Row * row)
}
void LyXText::breakParagraph(BufferView * bview, char keep_layout)
void LyXText::breakParagraph(BufferView * bview,
ParagraphList & paragraphs, char keep_layout)
{
// allow only if at start or end, or all previous is new text
if (cursor.pos() && cursor.pos() != cursor.par()->size()
@ -1363,7 +1364,7 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
// paragraph before or behind and we should react on that one
// but we can fix this in 1.3.0 (Jug 20020509)
bool const isempty = (layout->keepempty && cursor.par()->empty());
::breakParagraph(bview->buffer(), cursor.par(), cursor.pos(),
::breakParagraph(bview->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
keep_layout);
// well this is the caption hack since one caption is really enough
@ -2444,7 +2445,7 @@ void LyXText::backspace(BufferView * bview)
&& cursor.par()->getAlign() == tmppar->getAlign()) {
removeParagraph(tmprow);
removeRow(tmprow);
mergeParagraph(bview->buffer(), cursor.par());
mergeParagraph(bview->buffer()->params, bview->buffer()->paragraphs, cursor.par());
if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
; //cursor.par()->insertChar(cursor.pos(), ' ');

View File

@ -830,7 +830,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
case LFUN_BREAKPARAGRAPH:
bv->beforeChange(this);
breakParagraph(bv, 0);
breakParagraph(bv, bv->buffer()->paragraphs, 0);
update(bv);
selection.cursor = cursor;
bv->switchKeyMap();
@ -839,7 +839,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
bv->beforeChange(this);
breakParagraph(bv, 1);
breakParagraph(bv, bv->buffer()->paragraphs, 1);
update(bv);
selection.cursor = cursor;
bv->switchKeyMap();
@ -867,7 +867,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
}
}
else {
breakParagraph(bv, 0);
breakParagraph(bv, bv->buffer()->paragraphs, 0);
//update(bv);
}
update(bv);