[EMAIL PROTECTED] wrote:
Author: younes
Date: Tue Jun 19 18:03:47 2007
New Revision: 18828

URL: http://www.lyx.org/trac/changeset/18828
Log:
Polish revision 18825 and fix some remaining issues with child documents. The 
diff is bigger than it should because of white space issues.
That was me. I was having editor problems, now fixed, but didn't catch them all, apparently.

rh

* buffer_funcs.{h,cpp}: new checkAndLoadLyXFile() transferred from 
BufferView::loadLyXFile().

* BufferView::loadLyXFile(): deleted.

* LyXView::loadLyXFile(): simplify logic and fix some issues:
  - buggy child document leads to crash due to error list dialog.
  - ensure that we switch to buffer if there's some errors.
  - use LyXView::setBuffer() instead of repeating code.


Modified:
    lyx-devel/trunk/src/BufferView.cpp
    lyx-devel/trunk/src/BufferView.h
    lyx-devel/trunk/src/buffer_funcs.cpp
    lyx-devel/trunk/src/buffer_funcs.h
    lyx-devel/trunk/src/frontends/LyXView.cpp

Modified: lyx-devel/trunk/src/BufferView.cpp
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/BufferView.cpp?rev=18828
==============================================================================
--- lyx-devel/trunk/src/BufferView.cpp (original)
+++ lyx-devel/trunk/src/BufferView.cpp Tue Jun 19 18:03:47 2007
@@ -233,61 +233,6 @@
                graphics::Previews::get().generateBufferPreviews(*buffer_);
 }
-// FIXME There is now no need for this to be in BufferView. It should all
-// be moved to buffer_func.cpp. (Abdel)
-Buffer * BufferView::loadLyXFile(FileName const & filename, bool auto_open)
-{
-       // File already open?
-       if (theBufferList().exists(filename.absFilename())) {
-               docstring const file = makeDisplayPath(filename.absFilename(), 
20);
-               docstring text = bformat(_("The document %1$s is already "
-                                                    "loaded.\n\nDo you want to 
revert "
-                                                    "to the saved version?"), 
file);
-               int const ret = Alert::prompt(_("Revert to saved document?"),
-                       text, 0, 1,  _("&Revert"), _("&Switch to document"));
-
-               if (ret != 0) {
-      Buffer * buf = theBufferList().getBuffer(filename.absFilename());
-                       setBuffer(buf);
-                       return buf;
-               }
-               // FIXME: should be LFUN_REVERT
-               if 
(!theBufferList().close(theBufferList().getBuffer(filename.absFilename()), 
false))
-                       return 0;
-               // Fall through to new load. (Asger)
-               buffer_ = 0;
-       }
-
-       Buffer * b = 0;
-
-       if (isFileReadable(filename)) {
-               b = theBufferList().newBuffer(filename.absFilename());
-               if (!lyx::loadLyXFile(b, filename)) {
-                       theBufferList().release(b);
-                       return 0;
-               }
-       } else {
-               docstring text = bformat(_("The document %1$s does not yet "
-                                                    "exist.\n\nDo you want to 
create "
-                                                    "a new document?"), 
from_utf8(filename.absFilename()));
-               int const ret = Alert::prompt(_("Create new document?"),
-                        text, 0, 1, _("&Create"), _("Cancel"));
-
-               if (ret == 0) {
-                       b = newFile(filename.absFilename(), string(), true);
-                       if (!b)
-                               return 0;
-               } else
-                       return 0;
-       }
-
-  if (!auto_open)
-       setBuffer(b);
-
-       return b;
-}
-
-
 void BufferView::resize()
 {
        if (!buffer_)

Modified: lyx-devel/trunk/src/BufferView.h
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/BufferView.h?rev=18828
==============================================================================
--- lyx-devel/trunk/src/BufferView.h (original)
+++ lyx-devel/trunk/src/BufferView.h Tue Jun 19 18:03:47 2007
@@ -93,10 +93,6 @@
        /// resize the BufferView.
        void resize();
- /// load a buffer into the view.
-  /// returns the buffer or 0 if not loaded
-       Buffer * loadLyXFile(support::FileName const & name, bool auto_open = 
false);
-
        /// perform pending metrics updates.
        /** \c Update::FitCursor means first to do a FitCursor, and to
         * force an update if screen position changes.

Modified: lyx-devel/trunk/src/buffer_funcs.cpp
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/buffer_funcs.cpp?rev=18828
==============================================================================
--- lyx-devel/trunk/src/buffer_funcs.cpp (original)
+++ lyx-devel/trunk/src/buffer_funcs.cpp Tue Jun 19 18:03:47 2007
@@ -180,6 +180,47 @@
        return false;
 }
+
+Buffer * checkAndLoadLyXFile(FileName const & filename)
+{
+       // File already open?
+       if (theBufferList().exists(filename.absFilename())) {
+               docstring const file = makeDisplayPath(filename.absFilename(), 
20);
+               docstring text = bformat(_("The document %1$s is already "
+                                                    "loaded.\n\nDo you want to 
revert "
+                                                    "to the saved version?"), 
file);
+               if (Alert::prompt(_("Revert to saved document?"),
+                               text, 0, 1,  _("&Revert"), _("&Switch to 
document")))
+                       return 
theBufferList().getBuffer(filename.absFilename());
+
+               // FIXME: should be LFUN_REVERT
+               if 
(theBufferList().close(theBufferList().getBuffer(filename.absFilename()), 
false))
+                       // Load it again.
+                       return checkAndLoadLyXFile(filename);
+               else
+                       // The file could not be closed.
+                       return 0;
+       }
+
+       if (isFileReadable(filename)) {
+               Buffer * b = theBufferList().newBuffer(filename.absFilename());
+               if (!lyx::loadLyXFile(b, filename)) {
+                       theBufferList().release(b);
+                       return 0;
+               }
+               return b;
+       }
+
+       docstring text = bformat(_("The document %1$s does not yet "
+               "exist.\n\nDo you want to create a new document?"),
+               from_utf8(filename.absFilename()));
+       if (Alert::prompt(_("Create new document?"),
+                       text, 0, 1, _("&Create"), _("Cancel")))
+               return newFile(filename.absFilename(), string(), true);
+
+       return 0;
+}
+
 // FIXME newFile() should probably be a member method of Application...
 Buffer * newFile(string const & filename, string const & templatename,
                 bool const isNamed)

Modified: lyx-devel/trunk/src/buffer_funcs.h
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/buffer_funcs.h?rev=18828
==============================================================================
--- lyx-devel/trunk/src/buffer_funcs.h (original)
+++ lyx-devel/trunk/src/buffer_funcs.h Tue Jun 19 18:03:47 2007
@@ -33,6 +33,13 @@
  *  and \return success status.
  */
 bool loadLyXFile(Buffer *, support::FileName const & filename);
+
+/**
+ *  Checks and loads a LyX file \param filename.
+ *  \retval the newly created \c Buffer pointer if successful or 0.
+ *  \retval 0 if the \c Buffer could not be created.
+ */
+Buffer * checkAndLoadLyXFile(support::FileName const & filename);
/* Make a new file (buffer) with name \c filename based on a template
  * named \c templatename

Modified: lyx-devel/trunk/src/frontends/LyXView.cpp
URL: 
http://www.lyx.org/trac/file/lyx-devel/trunk/src/frontends/LyXView.cpp?rev=18828
==============================================================================
--- lyx-devel/trunk/src/frontends/LyXView.cpp (original)
+++ lyx-devel/trunk/src/frontends/LyXView.cpp Tue Jun 19 18:03:47 2007
@@ -190,71 +190,52 @@
        if (oldBuffer)
                parentfilename = oldBuffer->fileName();
- Buffer * newBuffer =
-               work_area_->bufferView().loadLyXFile(filename, auto_open);
-
-  if (!newBuffer) {
+       Buffer * newBuffer = checkAndLoadLyXFile(filename);
+
+       if (!newBuffer) {
                message(_("Document not loaded."));
-    updateStatusBar();
-    busy(false);
-    work_area_->redraw();
-    return false;
-  }
- - if (!auto_open) {
-    disconnectBuffer();
-    connectBuffer(*newBuffer);
-  }
-
-  showErrorList("Parse");
-
-  if (child_document && newBuffer != oldBuffer) {
-    // 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.
-    newBuffer->setParentName(parentfilename);
-    message(bformat(_("Opening child document %1$s..."),
-      makeDisplayPath(filename.absFilename())));
-  }
- - // Update the labels and section numbering.
-  updateLabels(*newBuffer->getMasterBuffer());
-
-  // scroll to the position when the file was last closed
-  if (!auto_open && 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 (work_area_->bufferView().moveToPosition(pit, pos, 0, 0).get<1>()) {
-      if (work_area_->bufferView().fitCursor())
-        work_area_->bufferView().updateMetrics(false);
-      newBuffer->text().setCurrentFont(work_area_->bufferView().cursor());
-    }
-  }
-
-  if (tolastfiles)
-    LyX::ref().session().lastFiles().add(filename);
-
-  // FIXME We definitely don't have to do all of this if auto_open...
-  // The question is: What do we have to do here if we've loaded a new
-  // file but haven't switched buffers? I'm guessing we can skip the
-  // layout bit and the title.
-  // and if we have already switched buffers...won't all of this have been
-  // done already in setBuffer()? So why does it also need doing here?
-  // In fact, won't a lot of what's above already have been done?  E.g.,
-  // the connecting and disconnecting of buffers will have been done
- // already in setBuffer(). - // This bit of cleanup is post-1.5.0....
-       updateMenubar();
-       updateToolbars();
-       updateLayoutChoice();
-       updateWindowTitle();
-       updateTab();
-       updateStatusBar();
+               updateStatusBar();
+               busy(false);
+               work_area_->redraw();
+               return false;
+       }
+
+       if (child_document && newBuffer != oldBuffer) {
+               // 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.
+               newBuffer->setParentName(parentfilename);
+               message(bformat(_("Opening child document %1$s..."),
+                       makeDisplayPath(filename.absFilename())));
+       }
+
+       bool const parse_error = !newBuffer->errorList("Parse").empty();
+       if (parse_error || !auto_open) {
+               setBuffer(newBuffer, child_document);
+               showErrorList("Parse");
+       }
+
+       // Update the labels and section numbering.
+       updateLabels(*newBuffer->getMasterBuffer());
+
+       // scroll to the position when the file was last closed
+       if (!auto_open && 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 (work_area_->bufferView().moveToPosition(pit, pos, 0, 
0).get<1>()) {
+                       if (work_area_->bufferView().fitCursor())
+                               work_area_->bufferView().updateMetrics(false);
+                       
newBuffer->text().setCurrentFont(work_area_->bufferView().cursor());
+               }
+       }
+
+       if (tolastfiles)
+               LyX::ref().session().lastFiles().add(filename);
+
        busy(false);
-       work_area_->redraw();
        return true;
 }

_______________________________________________
Cvslog mailing list
[EMAIL PROTECTED]
http://www.lyx.org/mailman/listinfo/cvslog


--
==================================================================
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

Reply via email to