Re: [patch] undo (partial...)

2003-06-04 Thread Lars Gullik Bjønnes
Andre Poenitz <[EMAIL PROTECTED]> writes:

| This makes undo partially work. It crashes always when used in the last
| par and after "complicated" operations, but it works if used in the middle
| of the text for simple insertions/deletions, sometimes even multi-par
| stuff. 
| 
| In any case, this is somewhat beter than what we have now.

Good... and long as it gets better we should push on.
 
| Note that I had to implement Paragraph::operator=() (Lars, you are a
| naughty boy...).

I had it implemented (with swap), but that was before the clone
fixes... so it did not really compile :-/

| Replace it with something closer to your taste if you
| want. The swap idiom is a bit more work here because the inset owners
| need to be set..

Not if a proper operator= is implemented for InsetList.
(a setOwner will still be needed though).
 
| Next change i the return type of limited_stack::top(). It's (a) used this
| way and (b) consistent with std::stack<> now.

ok.
 
| The rest is undo specific stuff, some simplification of the logic and some
| code to 'make it work'.
| 
| Ok?

Yes.

-- 
Lgb


[patch] undo (partial...)

2003-06-04 Thread Andre Poenitz

This makes undo partially work. It crashes always when used in the last
par and after "complicated" operations, but it works if used in the middle
of the text for simple insertions/deletions, sometimes even multi-par
stuff. 

In any case, this is somewhat beter than what we have now.

Note that I had to implement Paragraph::operator=() (Lars, you are a
naughty boy...). Replace it with something closer to your taste if you
want. The swap idiom is a bit more work here because the inset owners
need to be set..

Next change i the return type of limited_stack::top(). It's (a) used this
way and (b) consistent with std::stack<> now.

The rest is undo specific stuff, some simplification of the logic and some
code to 'make it work'.

Ok?

[Note that the logic might even get simpler if we would not use paragraph
ids, but ParagraphList ids and use distances from plist->begin() instead of
'first_id' and from plist->end() fo 'last_id'.

In that case, undo would not need Paragraph::id anymore and possibly no
Inset::id, too.]

Andre'


-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one. (T. Jefferson or B. Franklin or both...)
Index: buffer.h
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v
retrieving revision 1.143
diff -u -p -r1.143 buffer.h
--- buffer.h2 Jun 2003 14:02:58 -   1.143
+++ buffer.h4 Jun 2003 06:09:49 -
@@ -23,7 +23,6 @@
 #include "author.h"
 #include "iterators.h"
 
-#include 
 #include 
 
 class BufferView;
@@ -273,10 +272,10 @@ public:
bool isMultiLingual();
 
/// Does this mean that this is buffer local?
-   limited_stack > undostack;
+   limited_stack undostack;
 
/// Does this mean that this is buffer local?
-   limited_stack > redostack;
+   limited_stack redostack;
 
///
BufferParams params;
Index: lyxfunc.C
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.448
diff -u -p -r1.448 lyxfunc.C
--- lyxfunc.C   2 Jun 2003 14:19:29 -   1.448
+++ lyxfunc.C   4 Jun 2003 06:09:49 -
@@ -501,7 +501,7 @@ FuncStatus LyXFunc::getStatus(FuncReques
// jump back to owner if an InsetText, so
// we get back to the InsetTabular or whatever
if (inset->lyxCode() == Inset::TEXT_CODE)
-   inset = static_cast(inset->owner());
+   inset = inset->owner();
 
Inset::Code code = inset->lyxCode();
switch (code) {
Index: paragraph.C
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.280
diff -u -p -r1.280 paragraph.C
--- paragraph.C 3 Jun 2003 15:10:07 -   1.280
+++ paragraph.C 4 Jun 2003 06:09:49 -
@@ -97,6 +97,31 @@ Paragraph::Paragraph(Paragraph const & l
 }
 
 
+void Paragraph::operator=(Paragraph const & lp)
+{
+   if (&lp != this)
+   return;
+   lyxerr << "Paragraph::operator=()\n";
+   delete pimpl_;
+   pimpl_ = new Pimpl(*lp.pimpl_, this);
+
+   enumdepth = lp.enumdepth;
+   itemdepth = lp.itemdepth;
+   // this is because of the dummy layout of the paragraphs that
+   // follow footnotes
+   layout_ = lp.layout();
+
+   // copy everything behind the break-position to the new paragraph
+   insetlist = lp.insetlist;
+   InsetList::iterator it = insetlist.begin();
+   InsetList::iterator end = insetlist.end();
+   for (; it != end; ++it) {
+   it->inset = it->inset->clone();
+   // tell the new inset who is the boss now
+   it->inset->parOwner(this);
+   }
+}
+
 // the destructor removes the new paragraph from the list
 Paragraph::~Paragraph()
 {
@@ -1205,14 +1230,14 @@ string const Paragraph::asString(Buffer 
 }
 
 
-void Paragraph::setInsetOwner(Inset * i)
+void Paragraph::setInsetOwner(UpdatableInset * inset)
 {
-   pimpl_->inset_owner = i;
+   pimpl_->inset_owner = inset;
InsetList::iterator it = insetlist.begin();
InsetList::iterator end = insetlist.end();
for (; it != end; ++it)
if (it->inset)
-   it->inset->setOwner(i);
+   it->inset->setOwner(inset);
 }
 
 
@@ -1350,7 +1375,7 @@ void Paragraph::layout(LyXLayout_ptr con
 }
 
 
-Inset * Paragraph::inInset() const
+UpdatableInset * Paragraph::inInset() const
 {
return pimpl_->inset_owner;
 }
Index: paragraph.h
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v
retrieving revision 1.86
diff -u -p -r1.86 paragraph.h
--- paragraph.h 3 Jun 2003 15:10:07 -   1.86
+++ paragraph.h 4 Jun 2003 06:09:49 -
@@ -31,6 +31,7 @@ class LatexRu