Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread Abdelrazak Younes

Abdelrazak Younes wrote:

http://bugzilla.lyx.org/show_bug.cgi?id=3860

SVN Log:

Polish the Toc and labels updating when loading a child document. Fix 
Bug 3860: Toc crash when loading a child documents.


* BufferView::loadLyXFile(): simplify, transfer last part to 
LyXView::loadLyXFile()


* LyXView:
- setBuffer(): properly update the labels and the Toc if this is [LOAD 
Child Document] command.
- loadLyXFile(): get some code from BufferView::loadLyXFile() and from 
LyXFunc::LFUN_BUFFER_CHILD, properly handle the child document case.


* LyXFunc: simplify LFUN_BUFFER_CHILD.

* LyX: adapt to loadLyXFile() API change.


With this in place, the only thing missing for proper multipart document 
support is to automatically update the parent Buffer when switching from 
the parent Buffer. This would be very useful when you work with multiple 
document sharing the same child documents (as I often do).


Seeking two OKs. As this is a critical bug fixing patch I reckon this 
should go before RC2. Once this is in, I'll look at the automatic 
updating of LOF, LOT and LOL... LOL!


I won't be able to commit it this week-end so could anyone show a little 
bit of interest please?


Patch updated to latest svn attached...

Abdel.
Index: Buffer.cpp
===
--- Buffer.cpp  (revision 18780)
+++ Buffer.cpp  (working copy)
@@ -1613,7 +1613,11 @@
 
 void Buffer::setParentName(string const  name)
 {
-   params().parentname = name;
+   if (name == pimpl_-filename.absFilename())
+   // Avoids recursive include.
+   params().parentname.clear();
+   else
+   params().parentname = name;
 }
 
 
Index: BufferView.cpp
===
--- BufferView.cpp  (revision 18780)
+++ BufferView.cpp  (working copy)
@@ -233,8 +233,8 @@
graphics::Previews::get().generateBufferPreviews(*buffer_);
 }
 
-
-bool BufferView::loadLyXFile(FileName const  filename, bool tolastfiles)
+// FIXME: all of this should go in a helper file in buffer_func.
+bool BufferView::loadLyXFile(FileName const  filename)
 {
// File already open?
if (theBufferList().exists(filename.absFilename())) {
@@ -280,27 +280,7 @@
}
 
setBuffer(b);
-   // Send the errors signal in case of parsing errors
-   b-errors(Parse);
 
-   // Update the labels and section numbering.
-   updateLabels(*buffer_);
-   // scroll to the position when the file was last closed
-   if (lyxrc.use_lastfilepos) {
-   pit_type pit;
-   pos_type pos;
-   boost::tie(pit, pos) = 
LyX::ref().session().lastFilePos().load(filename);
-   // if successfully move to pit (returned par_id is not zero), 
update metrics and reset font
-   if (moveToPosition(pit, pos, 0, 0).get1()) {
-   if (fitCursor())
-   updateMetrics(false);
-   buffer_-text().setCurrentFont(cursor_);
-   }
-   }
-
-   if (tolastfiles)
-   LyX::ref().session().lastFiles().add(FileName(b-fileName()));
-
return true;
 }
 
Index: BufferView.h
===
--- BufferView.h(revision 18780)
+++ BufferView.h(working copy)
@@ -94,7 +94,7 @@
void resize();
 
/// load a buffer into the view.
-   bool loadLyXFile(support::FileName const  name, bool tolastfiles = 
true);
+   bool loadLyXFile(support::FileName const  name);
 
/// perform pending metrics updates.
/** \c Update::FitCursor means first to do a FitCursor, and to
Index: frontends/LyXView.cpp
===
--- frontends/LyXView.cpp   (revision 18780)
+++ frontends/LyXView.cpp   (working copy)
@@ -20,6 +20,7 @@
 #include Gui.h
 
 #include Buffer.h
+#include buffer_funcs.h
 #include BufferList.h
 #include BufferParams.h
 #include BufferView.h
@@ -31,6 +32,7 @@
 #include gettext.h
 #include Intl.h
 #include callback.h
+#include LyX.h
 #include LyXFunc.h
 #include LyXRC.h
 #include Text.h
@@ -122,27 +124,44 @@
 }
 
 
-void LyXView::setBuffer(Buffer * b)
+void LyXView::setBuffer(Buffer * b, bool child_document)
 {
busy(true);
 
BOOST_ASSERT(work_area_);
-   if (work_area_-bufferView().buffer())
+   Buffer * oldBuffer = work_area_-bufferView().buffer();
+   // parentfilename will be used in case when we switch to a child
+   // document (hence when child_document is true)
+   string parentfilename;
+   if (oldBuffer) {
+   parentfilename = oldBuffer-fileName();
disconnectBuffer();
+   }
 
if (!b  theBufferList().empty())
getDialogs().hideBufferDependent();
 
work_area_-bufferView().setBuffer(b);
-   // Make sure the TOC is updated 

Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread Richard Heck

Abdelrazak Younes wrote:
I won't be able to commit it this week-end so could anyone show a 
little bit of interest please?

I've patched and am compiling now.

rh

--
==
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto



Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread José Matos
On Friday 15 June 2007 18:57:44 Richard Heck wrote:
 I've patched and am compiling now.

 rh

If it fixes the crash you have my OK. :-)

-- 
José Abílio


Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread Stefan Schimanski

Abdelrazak Younes wrote:
I won't be able to commit it this week-end so could anyone show a  
little bit of interest please?

I've patched and am compiling now.



Me too.

Stefan


PGP.sig
Description: Signierter Teil der Nachricht


Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread Stefan Schimanski

Tried it a bit with child documents. Looks fine.

Stefan



PGP.sig
Description: Signierter Teil der Nachricht


Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread Abdelrazak Younes

Stefan Schimanski wrote:

Tried it a bit with child documents. Looks fine.


OK, thanks.

Abdel.



Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread Abdelrazak Younes

Abdelrazak Younes wrote:

http://bugzilla.lyx.org/show_bug.cgi?id=3860

SVN Log:

Polish the Toc and labels updating when loading a child document. Fix 
Bug 3860: Toc crash when loading a child documents.


* BufferView::loadLyXFile(): simplify, transfer last part to 
LyXView::loadLyXFile()


* LyXView:
- setBuffer(): properly update the labels and the Toc if this is [LOAD 
Child Document] command.
- loadLyXFile(): get some code from BufferView::loadLyXFile() and from 
LyXFunc::LFUN_BUFFER_CHILD, properly handle the child document case.


* LyXFunc: simplify LFUN_BUFFER_CHILD.

* LyX: adapt to loadLyXFile() API change.


With this in place, the only thing missing for proper multipart document 
support is to automatically update the parent Buffer when switching from 
the parent Buffer. This would be very useful when you work with multiple 
document sharing the same child documents (as I often do).


Seeking two OKs. As this is a critical bug fixing patch I reckon this 
should go before RC2. Once this is in, I'll look at the automatic 
updating of LOF, LOT and LOL... LOL!


I won't be able to commit it this week-end so could anyone show a little 
bit of interest please?


Patch updated to latest svn attached...

Abdel.
Index: Buffer.cpp
===
--- Buffer.cpp  (revision 18780)
+++ Buffer.cpp  (working copy)
@@ -1613,7 +1613,11 @@
 
 void Buffer::setParentName(string const & name)
 {
-   params().parentname = name;
+   if (name == pimpl_->filename.absFilename())
+   // Avoids recursive include.
+   params().parentname.clear();
+   else
+   params().parentname = name;
 }
 
 
Index: BufferView.cpp
===
--- BufferView.cpp  (revision 18780)
+++ BufferView.cpp  (working copy)
@@ -233,8 +233,8 @@
graphics::Previews::get().generateBufferPreviews(*buffer_);
 }
 
-
-bool BufferView::loadLyXFile(FileName const & filename, bool tolastfiles)
+// FIXME: all of this should go in a helper file in buffer_func.
+bool BufferView::loadLyXFile(FileName const & filename)
 {
// File already open?
if (theBufferList().exists(filename.absFilename())) {
@@ -280,27 +280,7 @@
}
 
setBuffer(b);
-   // Send the "errors" signal in case of parsing errors
-   b->errors("Parse");
 
-   // Update the labels and section numbering.
-   updateLabels(*buffer_);
-   // scroll to the position when the file was last closed
-   if (lyxrc.use_lastfilepos) {
-   pit_type pit;
-   pos_type pos;
-   boost::tie(pit, pos) = 
LyX::ref().session().lastFilePos().load(filename);
-   // if successfully move to pit (returned par_id is not zero), 
update metrics and reset font
-   if (moveToPosition(pit, pos, 0, 0).get<1>()) {
-   if (fitCursor())
-   updateMetrics(false);
-   buffer_->text().setCurrentFont(cursor_);
-   }
-   }
-
-   if (tolastfiles)
-   LyX::ref().session().lastFiles().add(FileName(b->fileName()));
-
return true;
 }
 
Index: BufferView.h
===
--- BufferView.h(revision 18780)
+++ BufferView.h(working copy)
@@ -94,7 +94,7 @@
void resize();
 
/// load a buffer into the view.
-   bool loadLyXFile(support::FileName const & name, bool tolastfiles = 
true);
+   bool loadLyXFile(support::FileName const & name);
 
/// perform pending metrics updates.
/** \c Update::FitCursor means first to do a FitCursor, and to
Index: frontends/LyXView.cpp
===
--- frontends/LyXView.cpp   (revision 18780)
+++ frontends/LyXView.cpp   (working copy)
@@ -20,6 +20,7 @@
 #include "Gui.h"
 
 #include "Buffer.h"
+#include "buffer_funcs.h"
 #include "BufferList.h"
 #include "BufferParams.h"
 #include "BufferView.h"
@@ -31,6 +32,7 @@
 #include "gettext.h"
 #include "Intl.h"
 #include "callback.h"
+#include "LyX.h"
 #include "LyXFunc.h"
 #include "LyXRC.h"
 #include "Text.h"
@@ -122,27 +124,44 @@
 }
 
 
-void LyXView::setBuffer(Buffer * b)
+void LyXView::setBuffer(Buffer * b, bool child_document)
 {
busy(true);
 
BOOST_ASSERT(work_area_);
-   if (work_area_->bufferView().buffer())
+   Buffer * oldBuffer = work_area_->bufferView().buffer();
+   // parentfilename will be used in case when we switch to a child
+   // document (hence when child_document is true)
+   string parentfilename;
+   if (oldBuffer) {
+   parentfilename = oldBuffer->fileName();
disconnectBuffer();
+   }
 
if (!b && theBufferList().empty())
getDialogs().hideBufferDependent();
 

Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread Richard Heck

Abdelrazak Younes wrote:
I won't be able to commit it this week-end so could anyone show a 
little bit of interest please?

I've patched and am compiling now.

rh

--
==
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto



Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread José Matos
On Friday 15 June 2007 18:57:44 Richard Heck wrote:
> I've patched and am compiling now.
>
> rh

If it fixes the crash you have my OK. :-)

-- 
José Abílio


Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread Stefan Schimanski

Abdelrazak Younes wrote:
I won't be able to commit it this week-end so could anyone show a  
little bit of interest please?

I've patched and am compiling now.



Me too.

Stefan


PGP.sig
Description: Signierter Teil der Nachricht


Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread Stefan Schimanski

Tried it a bit with child documents. Looks fine.

Stefan



PGP.sig
Description: Signierter Teil der Nachricht


Re: [PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-15 Thread Abdelrazak Younes

Stefan Schimanski wrote:

Tried it a bit with child documents. Looks fine.


OK, thanks.

Abdel.



[PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-14 Thread Abdelrazak Younes

http://bugzilla.lyx.org/show_bug.cgi?id=3860

SVN Log:

Polish the Toc and labels updating when loading a child document. Fix 
Bug 3860: Toc crash when loading a child documents.


* BufferView::loadLyXFile(): simplify, transfer last part to 
LyXView::loadLyXFile()


* LyXView:
- setBuffer(): properly update the labels and the Toc if this is [LOAD 
Child Document] command.
- loadLyXFile(): get some code from BufferView::loadLyXFile() and from 
LyXFunc::LFUN_BUFFER_CHILD, properly handle the child document case.


* LyXFunc: simplify LFUN_BUFFER_CHILD.

* LyX: adapt to loadLyXFile() API change.


With this in place, the only thing missing for proper multipart document 
support is to automatically update the parent Buffer when switching from 
the parent Buffer. This would be very useful when you work with multiple 
document sharing the same child documents (as I often do).


Seeking two OKs. As this is a critical bug fixing patch I reckon this 
should go before RC2. Once this is in, I'll look at the automatic 
updating of LOF, LOT and LOL... LOL!


Abdel.

Index: BufferView.cpp
===
--- BufferView.cpp  (revision 18766)
+++ BufferView.cpp  (working copy)
@@ -233,8 +233,8 @@
graphics::Previews::get().generateBufferPreviews(*buffer_);
 }
 
-
-bool BufferView::loadLyXFile(FileName const  filename, bool tolastfiles)
+// FIXME: all of this should go in a helper file in buffer_func.
+bool BufferView::loadLyXFile(FileName const  filename)
 {
// File already open?
if (theBufferList().exists(filename.absFilename())) {
@@ -280,27 +280,7 @@
}
 
setBuffer(b);
-   // Send the errors signal in case of parsing errors
-   b-errors(Parse);
 
-   // Update the labels and section numbering.
-   updateLabels(*buffer_);
-   // scroll to the position when the file was last closed
-   if (lyxrc.use_lastfilepos) {
-   pit_type pit;
-   pos_type pos;
-   boost::tie(pit, pos) = 
LyX::ref().session().lastFilePos().load(filename);
-   // if successfully move to pit (returned par_id is not zero), 
update metrics and reset font
-   if (moveToPosition(pit, pos, 0, 0).get1()) {
-   if (fitCursor())
-   updateMetrics(false);
-   buffer_-text().setCurrentFont(cursor_);
-   }
-   }
-
-   if (tolastfiles)
-   LyX::ref().session().lastFiles().add(FileName(b-fileName()));
-
return true;
 }
 
Index: BufferView.h
===
--- BufferView.h(revision 18766)
+++ BufferView.h(working copy)
@@ -94,7 +94,7 @@
void resize();
 
/// load a buffer into the view.
-   bool loadLyXFile(support::FileName const  name, bool tolastfiles = 
true);
+   bool loadLyXFile(support::FileName const  name);
 
/// perform pending metrics updates.
/** \c Update::FitCursor means first to do a FitCursor, and to
Index: frontends/LyXView.cpp
===
--- frontends/LyXView.cpp   (revision 18766)
+++ frontends/LyXView.cpp   (working copy)
@@ -20,6 +20,7 @@
 #include Gui.h
 
 #include Buffer.h
+#include buffer_funcs.h
 #include BufferList.h
 #include BufferParams.h
 #include BufferView.h
@@ -31,6 +32,7 @@
 #include gettext.h
 #include Intl.h
 #include callback.h
+#include LyX.h
 #include LyXFunc.h
 #include LyXRC.h
 #include Text.h
@@ -122,27 +124,44 @@
 }
 
 
-void LyXView::setBuffer(Buffer * b)
+void LyXView::setBuffer(Buffer * b, bool child_document)
 {
busy(true);
 
BOOST_ASSERT(work_area_);
-   if (work_area_-bufferView().buffer())
+   Buffer * oldBuffer = work_area_-bufferView().buffer();
+   // parentfilename will be used in case when we switch to a child
+   // document (hence when child_document is true)
+   string parentfilename;
+   if (oldBuffer) {
+   parentfilename = oldBuffer-fileName();
disconnectBuffer();
+   }
 
if (!b  theBufferList().empty())
getDialogs().hideBufferDependent();
 
work_area_-bufferView().setBuffer(b);
-   // Make sure the TOC is updated before anything else.
-   updateToc();
 
-   if (work_area_-bufferView().buffer()) {
+   Buffer * newbuf = work_area_-bufferView().buffer();
+   if (newbuf) {
+   if (child_document) {
+   // Set the parent name of the child document.
+   // This makes insertion of citations and references in 
the child work,
+   // when the target is in the parent or another child 
document.
+   newbuf-setParentName(parentfilename);
+   // updateLabels() will emit Buffer::structureChanged() 
so better
+ 

[PATCH] Bug 3860 Toc crash when loading a child documents

2007-06-14 Thread Abdelrazak Younes

http://bugzilla.lyx.org/show_bug.cgi?id=3860

SVN Log:

Polish the Toc and labels updating when loading a child document. Fix 
Bug 3860: Toc crash when loading a child documents.


* BufferView::loadLyXFile(): simplify, transfer last part to 
LyXView::loadLyXFile()


* LyXView:
- setBuffer(): properly update the labels and the Toc if this is [LOAD 
Child Document] command.
- loadLyXFile(): get some code from BufferView::loadLyXFile() and from 
LyXFunc::LFUN_BUFFER_CHILD, properly handle the child document case.


* LyXFunc: simplify LFUN_BUFFER_CHILD.

* LyX: adapt to loadLyXFile() API change.


With this in place, the only thing missing for proper multipart document 
support is to automatically update the parent Buffer when switching from 
the parent Buffer. This would be very useful when you work with multiple 
document sharing the same child documents (as I often do).


Seeking two OKs. As this is a critical bug fixing patch I reckon this 
should go before RC2. Once this is in, I'll look at the automatic 
updating of LOF, LOT and LOL... LOL!


Abdel.

Index: BufferView.cpp
===
--- BufferView.cpp  (revision 18766)
+++ BufferView.cpp  (working copy)
@@ -233,8 +233,8 @@
graphics::Previews::get().generateBufferPreviews(*buffer_);
 }
 
-
-bool BufferView::loadLyXFile(FileName const & filename, bool tolastfiles)
+// FIXME: all of this should go in a helper file in buffer_func.
+bool BufferView::loadLyXFile(FileName const & filename)
 {
// File already open?
if (theBufferList().exists(filename.absFilename())) {
@@ -280,27 +280,7 @@
}
 
setBuffer(b);
-   // Send the "errors" signal in case of parsing errors
-   b->errors("Parse");
 
-   // Update the labels and section numbering.
-   updateLabels(*buffer_);
-   // scroll to the position when the file was last closed
-   if (lyxrc.use_lastfilepos) {
-   pit_type pit;
-   pos_type pos;
-   boost::tie(pit, pos) = 
LyX::ref().session().lastFilePos().load(filename);
-   // if successfully move to pit (returned par_id is not zero), 
update metrics and reset font
-   if (moveToPosition(pit, pos, 0, 0).get<1>()) {
-   if (fitCursor())
-   updateMetrics(false);
-   buffer_->text().setCurrentFont(cursor_);
-   }
-   }
-
-   if (tolastfiles)
-   LyX::ref().session().lastFiles().add(FileName(b->fileName()));
-
return true;
 }
 
Index: BufferView.h
===
--- BufferView.h(revision 18766)
+++ BufferView.h(working copy)
@@ -94,7 +94,7 @@
void resize();
 
/// load a buffer into the view.
-   bool loadLyXFile(support::FileName const & name, bool tolastfiles = 
true);
+   bool loadLyXFile(support::FileName const & name);
 
/// perform pending metrics updates.
/** \c Update::FitCursor means first to do a FitCursor, and to
Index: frontends/LyXView.cpp
===
--- frontends/LyXView.cpp   (revision 18766)
+++ frontends/LyXView.cpp   (working copy)
@@ -20,6 +20,7 @@
 #include "Gui.h"
 
 #include "Buffer.h"
+#include "buffer_funcs.h"
 #include "BufferList.h"
 #include "BufferParams.h"
 #include "BufferView.h"
@@ -31,6 +32,7 @@
 #include "gettext.h"
 #include "Intl.h"
 #include "callback.h"
+#include "LyX.h"
 #include "LyXFunc.h"
 #include "LyXRC.h"
 #include "Text.h"
@@ -122,27 +124,44 @@
 }
 
 
-void LyXView::setBuffer(Buffer * b)
+void LyXView::setBuffer(Buffer * b, bool child_document)
 {
busy(true);
 
BOOST_ASSERT(work_area_);
-   if (work_area_->bufferView().buffer())
+   Buffer * oldBuffer = work_area_->bufferView().buffer();
+   // parentfilename will be used in case when we switch to a child
+   // document (hence when child_document is true)
+   string parentfilename;
+   if (oldBuffer) {
+   parentfilename = oldBuffer->fileName();
disconnectBuffer();
+   }
 
if (!b && theBufferList().empty())
getDialogs().hideBufferDependent();
 
work_area_->bufferView().setBuffer(b);
-   // Make sure the TOC is updated before anything else.
-   updateToc();
 
-   if (work_area_->bufferView().buffer()) {
+   Buffer * newbuf = work_area_->bufferView().buffer();
+   if (newbuf) {
+   if (child_document) {
+   // Set the parent name of the child document.
+   // This makes insertion of citations and references in 
the child work,
+   // when the target is in the parent or another child 
document.
+   newbuf->setParentName(parentfilename);
+   // updateLabels() will emit