]> git.lyx.org Git - features.git/commitdiff
take several functions out of BufferList, and split functionality
authorAlfredo Braunstein <abraunst@lyx.org>
Fri, 20 Jun 2003 12:46:28 +0000 (12:46 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Fri, 20 Jun 2003 12:46:28 +0000 (12:46 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7195 a592a061-630c-0410-9148-cb99ea01b6c8

21 files changed:
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/BufferView_pimpl.h
src/ChangeLog
src/Makefile.am
src/buffer.C
src/buffer_funcs.C [new file with mode: 0644]
src/buffer_funcs.h [new file with mode: 0644]
src/bufferlist.C
src/bufferlist.h
src/frontends/qt2/ChangeLog
src/frontends/qt2/lyx_gui.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/lyx_gui.C
src/importer.C
src/insets/ChangeLog
src/insets/insetinclude.C
src/lyx_cb.C
src/lyx_main.C
src/lyxfunc.C

index 7b8a4cfa33a8e5cacf7ba0301b4e22ff404566e7..6e3d8ba3c9773f650a8b67fb21866e5878fa3920 100644 (file)
@@ -104,11 +104,17 @@ void BufferView::buffer(Buffer * b)
 }
 
 
+bool BufferView::loadLyXFile(string const & fn, bool tl)
+{
+       return pimpl_->loadLyXFile(fn, tl);
+}
+
+
 void BufferView::reload()
 {
        string const fn = buffer()->fileName();
        if (bufferlist.close(buffer(), false))
-               buffer(bufferlist.loadLyXFile(fn));
+               loadLyXFile(fn);
 }
 
 
index 419f807b772bc96e2df694fb4003a7ac793b4313..a2fbaed17011e3da9c677b01bfe58614dc29ab66 100644 (file)
@@ -81,6 +81,8 @@ public:
 
        /// reload the contained buffer
        void reload();
+       /// load a buffer into the view
+       bool loadLyXFile(string const & name, bool tolastfiles = true);
 
        /// fit the user cursor within the visible view
        bool fitCursor();
index 6f325142723b510f387f8fcef63cc40a094fcc36..f2c3be9d81219075fe9240bc149933b0bd004769 100644 (file)
@@ -11,6 +11,7 @@
 #include "BufferView_pimpl.h"
 #include "bufferlist.h"
 #include "buffer.h"
+#include "buffer_funcs.h"
 #include "bufferview_funcs.h"
 #include "lfuns.h"
 #include "debug.h"
@@ -28,6 +29,7 @@
 #include "lyxtext.h"
 #include "lyxrc.h"
 #include "lyxrow.h"
+#include "lastfiles.h"
 #include "paragraph.h"
 #include "ParagraphParameters.h"
 #include "TextCache.h"
@@ -128,6 +130,62 @@ BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner,
 }
 
 
+
+bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
+{
+       // get absolute path of file and add ".lyx" to the filename if
+       // necessary
+       string s = FileSearch(string(), filename, "lyx");
+       if (s.empty()) {
+               s = filename;
+       }
+
+       // file already open?
+       if (bufferlist.exists(s)) {
+               string const file = MakeDisplayPath(s, 20);
+               string 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(bufferlist.getBuffer(s));
+                       return true;
+               } else {
+                       // FIXME: should be LFUN_REVERT
+                       if (!bufferlist.close(bufferlist.getBuffer(s), false))
+                               return false;
+                       // Fall through to new load. (Asger)
+               }
+       }
+       Buffer * b = bufferlist.newBuffer(s);
+
+       //this is the point to attach to the error signal in the buffer
+
+       if (!::loadLyXFile(b, s)) {
+               bufferlist.release(b);
+               string text = bformat(_("The document %1$s does "
+                                       "not yet exist.\n\n"
+                                       "Do you want to create "
+                                       "a new document?"), s);
+               int const ret = Alert::prompt(_("Create new document?"),
+                        text, 0, 1, _("&Create"), _("Cancel"));
+
+               if (ret == 0) {
+                       bufferlist.close(buffer_, false);
+                       buffer(newFile(s, string(), true));
+               }
+       }
+
+       buffer(b);
+
+       if (tolastfiles)
+               lastfiles->newFile(b->fileName());
+
+       return true;
+}
+
 WorkArea & BufferView::Pimpl::workarea() const
 {
        return *workarea_.get();
@@ -286,8 +344,8 @@ int BufferView::Pimpl::resizeCurrentBuffer()
                mark_set = bv_->text->selection.mark();
                the_locking_inset = bv_->theLockingInset();
                buffer_->resizeInsets(bv_);
-               // I don't think the delete and new are necessary here we just could
-               // call only init! (Jug 20020419)
+               // I don't think the delete and new are necessary here we 
+               // just could call only init! (Jug 20020419)
                delete bv_->text;
                bv_->text = new LyXText(bv_);
                bv_->text->init(bv_);
@@ -641,10 +699,15 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
        beforeChange(bv_->text);
 
        if (fname != buffer_->fileName()) {
-               Buffer * b = bufferlist.exists(fname) ?
-                       bufferlist.getBuffer(fname) :
-                       bufferlist.loadLyXFile(fname); // don't ask, just load it
-               if (b != 0) buffer(b);
+               Buffer * b;
+               if (bufferlist.exists(fname))
+                       b = bufferlist.getBuffer(fname);
+               else {
+                       b = bufferlist.newBuffer(fname);
+                       ::loadLyXFile(b, fname); // don't ask, just load it
+               }
+               if (b != 0) 
+                       buffer(b);
        }
 
        ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
index 5f4baf4f635fbb657009473fd8cfdee7fd95b3e4..7dea067f9345c6368a99155c3a0a9a9bc8484c28 100644 (file)
@@ -54,6 +54,9 @@ struct BufferView::Pimpl : public boost::signals::trackable {
         * Repaint pixmap. Used for when we've made a visible
         * change but don't need the full update() logic
         */
+       ///
+       bool loadLyXFile(string const &, bool);
+       ///
        void repaint();
        ///
        void workAreaResize();
index f1215d608ec1e7ea08acb9a405b783220b70123e..5abfb2681c7a6aff87891204fd8b0480585ac6c8 100644 (file)
@@ -1,3 +1,16 @@
+
+2003-06-19  Alfredo Braunstein  <abraunst@libero.it>
+
+       * bufferlist.[Ch] (loadLyXFile, readFile, newFile): removed the 
+       ability to create a buffer and to return an existing one from 
+       the list. Moved these functions to...
+       * buffer_funcs.[Ch]: added
+       * BufferView.[Ch] (loadLyXFile): added
+       * BufferView_pimpl.[Ch] (loadLyXFile): Added. Does the guessing 
+       job removed from bufferlist::loadLyXFile.
+       * buffer.C (setReadOnly): make it work without view 
+       (i.e added an if (users))
+       
 2003-06-19  Angus Leeming  <leeming@lyx.org>
 
        * lfuns.h:
index 5d775d034279312d405714bee44c92284d0f2579..cdafd15d4c1edaddd01e6645c842a2639f2d8f20 100644 (file)
@@ -105,6 +105,8 @@ lyx_SOURCES = \
        broken_headers.h \
        buffer.C \
        buffer.h \
+       buffer_funcs.C \
+       buffer_funcs.h \
        bufferlist.C \
        bufferlist.h \
        bufferparams.C \
index 04e7e1ef14b42603a3208eaa173a8147cbec7a6e..808f3149b2435ba80c469b072260ed91ee2d87d7 100644 (file)
@@ -206,7 +206,8 @@ void Buffer::setReadonly(bool flag)
        if (read_only != flag) {
                read_only = flag;
                updateTitles();
-               users->owner()->getDialogs().updateBufferDependent(false);
+               if (users)
+                       users->owner()->getDialogs().updateBufferDependent(false);
        }
 }
 
diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C
new file mode 100644 (file)
index 0000000..3590c77
--- /dev/null
@@ -0,0 +1,196 @@
+/**
+ * \file buffer_funcs.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ * \author Alfredo Braunstein
+ *
+ * Full author contact details are available in file CREDITS
+ *
+ */
+
+#include <config.h>
+
+#include "buffer_funcs.h"
+#include "bufferlist.h"
+#include "buffer.h"
+#include "gettext.h"
+#include "vc-backend.h"
+#include "lyxlex.h"
+#include "ParagraphList.h"
+#include "paragraph.h"
+
+#include "frontends/Alert.h"
+
+#include "support/filetools.h"
+#include "support/FileInfo.h"
+#include "support/lyxlib.h"
+
+
+extern BufferList bufferlist;
+
+
+namespace {
+
+bool readFile(Buffer * b, string const & s)
+{
+       string ts(s);
+       string e = OnlyPath(s);
+       string a = e;
+       // File information about normal file
+       FileInfo fileInfo(s);
+
+       if (!fileInfo.exist()) {
+               string const file = MakeDisplayPath(s, 50);
+               string text = bformat(_("The specified document\n%1$s"
+                                       "\ncould not be read."), file);
+               Alert::error(_("Could not read document"), text);
+               return false;
+       }
+
+       // Check if emergency save file exists and is newer.
+       e += OnlyFilename(s) + ".emergency";
+       FileInfo fileInfoE(e);
+
+       bool use_emergency = false;
+
+       if (fileInfoE.exist() && fileInfo.exist()) {
+               if (fileInfoE.getModificationTime()
+                   > fileInfo.getModificationTime()) {
+                       string const file = MakeDisplayPath(s, 20);
+                       string text = bformat(_("An emergency save of the document %1$s exists.\n"
+                               "\nRecover emergency save?"), file);
+                       int const ret = Alert::prompt(_("Load emergency save?"),
+                               text, 0, 1, _("&Recover"), _("&Load Original"));
+
+                       if (ret == 0) {
+                               ts = e;
+                               // the file is not saved if we load the
+                               // emergency file.
+                               b->markDirty();
+                               use_emergency = true;
+                       }
+               }
+       }
+
+       if (!use_emergency) {
+               // Now check if autosave file is newer.
+               a += '#';
+               a += OnlyFilename(s);
+               a += '#';
+               FileInfo fileInfoA(a);
+               if (fileInfoA.exist() && fileInfo.exist()) {
+                       if (fileInfoA.getModificationTime()
+                           > fileInfo.getModificationTime()) {
+                               string const file = MakeDisplayPath(s, 20);
+                               string text = bformat(_("The backup of the document %1$s is newer.\n\n"
+                                       "Load the backup instead?"), file);
+                               int const ret = Alert::prompt(_("Load backup?"),
+                                       text, 0, 1, _("&Load backup"), _("Load &original"));
+
+                               if (ret == 0) {
+                                       ts = a;
+                                       // the file is not saved if we load the
+                                       // autosave file.
+                                       b->markDirty();
+                               } else {
+                                       // Here, we should delete the autosave
+                                       lyx::unlink(a);
+                               }
+                       }
+               }
+       }
+       // not sure if this is the correct place to begin LyXLex
+       LyXLex lex(0, 0);
+       lex.setFile(ts);
+
+       return b->readFile(lex, ts);
+}
+
+
+} // namespace anon
+
+
+
+bool loadLyXFile(Buffer * b, string const & s)
+{
+       switch (IsFileWriteable(s)) {
+       case 0:
+               b->setReadonly(true);
+               // Fall through
+       case 1:
+               if (readFile(b, s)) {
+                       b->lyxvc.file_found_hook(s);
+                       return true;
+               }
+               break; 
+       case -1: 
+               string const file = MakeDisplayPath(s, 20);
+               // Here we probably should run
+               if (LyXVC::file_not_found_hook(s)) {
+                       string text = bformat(_("Do you want to retrieve the document"
+                               " %1$s from version control?"), file);
+                       int const ret = Alert::prompt(_("Retrieve from version control?"),
+                               text, 0, 1, _("&Retrieve"), _("&Cancel"));
+
+                       if (ret == 0) {
+                               // How can we know _how_ to do the checkout?
+                               // With the current VC support it has to be,
+                               // a RCS file since CVS do not have special ,v files.
+                               RCS::retrieve(s);
+                               return loadLyXFile(b, s);
+                       }
+               }
+               break;
+       }
+       return false;
+}
+
+
+Buffer * newFile(string const & filename, string const & templatename, 
+                bool isNamed)
+{
+       // get a free buffer
+       Buffer * b = bufferlist.newBuffer(filename);
+
+       string tname;
+       // use defaults.lyx as a default template if it exists.
+       if (templatename.empty())
+               tname = LibFileSearch("templates", "defaults.lyx");
+       else
+               tname = templatename;
+
+       if (!tname.empty()) {
+               bool templateok = false;
+               LyXLex lex(0, 0);
+               lex.setFile(tname);
+               if (lex.isOK()) {
+                       if (b->readFile(lex, tname)) {
+                               templateok = true;
+                       }
+               }
+               if (!templateok) {
+                       string const file = MakeDisplayPath(tname, 50);
+                       string text  = bformat(_("The specified document template\n%1$s\n"
+                               "could not be read."), file);
+                       Alert::error(_("Could not read template"), text);
+                       // no template, start with empty buffer
+                       b->paragraphs.push_back(Paragraph());
+                       b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout());
+               }
+       } else {  // start with empty buffer
+               b->paragraphs.push_back(Paragraph());
+               b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout());
+       }
+
+       if (!isNamed) {
+               b->setUnnamed();
+               b->setFileName(filename);
+       }
+
+       b->setReadonly(false);
+       b->updateDocLang(b->params.language);
+
+       return b;
+}
diff --git a/src/buffer_funcs.h b/src/buffer_funcs.h
new file mode 100644 (file)
index 0000000..dc6a440
--- /dev/null
@@ -0,0 +1,26 @@
+// -*- C++ -*-
+/* \file buffer_funcs.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ * \author Alfredo Braunstein
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include "LString.h"
+
+class Buffer;
+
+/**
+ *  Loads a LyX file \c filename into \c Buffer 
+ *  and \return success status.
+ */
+bool loadLyXFile(Buffer *, string const & filename);
+
+/* Make a new file (buffer) with name \c filename based on a template
+ * named \c templatename
+ */
+Buffer * newFile(string const & filename, string const & templatename, 
+                bool isNamed = false);
index a0c6cf31a239d5ce533e5d47d3cab949d75f9be5..7d7b327b4e63cf95ffa742931b4ef7fcf752c482 100644 (file)
@@ -306,89 +306,6 @@ void BufferList::emergencyWrite(Buffer * buf)
 }
 
 
-
-Buffer * BufferList::readFile(string const & s, bool ronly)
-{
-       string ts(s);
-       string e = OnlyPath(s);
-       string a = e;
-       // File information about normal file
-       FileInfo fileInfo2(s);
-
-       if (!fileInfo2.exist()) {
-               string const file = MakeDisplayPath(s, 50);
-               string text = bformat(_("The specified document\n%1$s"
-                       "\ncould not be read."),        file);
-               Alert::error(_("Could not read document"), text);
-               return 0;
-       }
-
-       Buffer * b = newBuffer(s, ronly);
-
-       // Check if emergency save file exists and is newer.
-       e += OnlyFilename(s) + ".emergency";
-       FileInfo fileInfoE(e);
-
-       bool use_emergency = false;
-
-       if (fileInfoE.exist() && fileInfo2.exist()) {
-               if (fileInfoE.getModificationTime()
-                   > fileInfo2.getModificationTime()) {
-                       string const file = MakeDisplayPath(s, 20);
-                       string text = bformat(_("An emergency save of the document %1$s exists.\n"
-                               "\nRecover emergency save?"), file);
-                       int const ret = Alert::prompt(_("Load emergency save?"),
-                               text, 0, 1, _("&Recover"), _("&Load Original"));
-
-                       if (ret == 0) {
-                               ts = e;
-                               // the file is not saved if we load the
-                               // emergency file.
-                               b->markDirty();
-                               use_emergency = true;
-                       }
-               }
-       }
-
-       if (!use_emergency) {
-               // Now check if autosave file is newer.
-               a += '#';
-               a += OnlyFilename(s);
-               a += '#';
-               FileInfo fileInfoA(a);
-               if (fileInfoA.exist() && fileInfo2.exist()) {
-                       if (fileInfoA.getModificationTime()
-                           > fileInfo2.getModificationTime()) {
-                               string const file = MakeDisplayPath(s, 20);
-                               string text = bformat(_("The backup of the document %1$s is newer.\n\n"
-                                       "Load the backup instead?"), file);
-                               int const ret = Alert::prompt(_("Load backup?"),
-                                       text, 0, 1, _("&Load backup"), _("Load &original"));
-
-                               if (ret == 0) {
-                                       ts = a;
-                                       // the file is not saved if we load the
-                                       // autosave file.
-                                       b->markDirty();
-                               } else {
-                                       // Here, we should delete the autosave
-                                       lyx::unlink(a);
-                               }
-                       }
-               }
-       }
-       // not sure if this is the correct place to begin LyXLex
-       LyXLex lex(0, 0);
-       lex.setFile(ts);
-       if (b->readFile(lex, ts))
-               return b;
-       else {
-               release(b);
-               return 0;
-       }
-}
-
-
 bool BufferList::exists(string const & s) const
 {
        return find_if(bstore.begin(), bstore.end(),
@@ -416,129 +333,6 @@ Buffer * BufferList::getBuffer(string const & s)
 }
 
 
-Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
-{
-       // get a free buffer
-       Buffer * b = newBuffer(name);
-
-       // use defaults.lyx as a default template if it exists.
-       if (tname.empty()) {
-               tname = LibFileSearch("templates", "defaults.lyx");
-       }
-       if (!tname.empty()) {
-               bool templateok = false;
-               LyXLex lex(0, 0);
-               lex.setFile(tname);
-               if (lex.isOK()) {
-                       if (b->readFile(lex, tname)) {
-                               templateok = true;
-                       }
-               }
-               if (!templateok) {
-                       string const file = MakeDisplayPath(tname, 50);
-                       string text  = bformat(_("The specified document template\n%1$s\n"
-                               "could not be read."), file);
-                       Alert::error(_("Could not read template"), text);
-                       // no template, start with empty buffer
-                       b->paragraphs.push_back(Paragraph());
-                       b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout());
-               }
-       } else {  // start with empty buffer
-               b->paragraphs.push_back(Paragraph());
-               b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout());
-       }
-
-       if (!isNamed) {
-               b->setUnnamed();
-               b->setFileName(name);
-       }
-
-       b->setReadonly(false);
-       b->updateDocLang(b->params.language);
-
-       return b;
-}
-
-
-Buffer * BufferList::loadLyXFile(string const & filename, bool tolastfiles)
-{
-       // get absolute path of file and add ".lyx" to the filename if
-       // necessary
-       string s = FileSearch(string(), filename, "lyx");
-       if (s.empty()) {
-               s = filename;
-       }
-
-       // file already open?
-       if (exists(s)) {
-               string const file = MakeDisplayPath(s, 20);
-               string text = bformat(_("The document %1$s is already loaded.\n\n"
-                       "Do 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) {
-                       // FIXME: should be LFUN_REVERT
-                       if (!close(getBuffer(s), false)) {
-                               return 0;
-                       }
-                       // Fall through to new load. (Asger)
-               } else {
-                       // Here, we pretend that we just loaded the
-                       // open document
-                       return getBuffer(s);
-               }
-       }
-
-       Buffer * b = 0;
-       bool ro = false;
-       switch (IsFileWriteable(s)) {
-       case 0:
-               ro = true;
-               // Fall through
-       case 1:
-               b = readFile(s, ro);
-               if (b) {
-                       b->lyxvc.file_found_hook(s);
-               }
-               break; //fine- it's r/w
-       case -1: {
-               string const file = MakeDisplayPath(s, 20);
-               // Here we probably should run
-               if (LyXVC::file_not_found_hook(s)) {
-                       string text = bformat(_("Do you want to retrieve the document"
-                               " %1$s from version control?"), file);
-                       int const ret = Alert::prompt(_("Retrieve from version control?"),
-                               text, 0, 1, _("&Retrieve"), _("&Cancel"));
-
-                       if (ret == 0) {
-                               // How can we know _how_ to do the checkout?
-                               // With the current VC support it has to be,
-                               // a RCS file since CVS do not have special ,v files.
-                               RCS::retrieve(s);
-                               return loadLyXFile(filename, tolastfiles);
-                       }
-               }
-
-               string text = bformat(_("The document %1$s does not yet exist.\n\n"
-                       "Do you want to create a new document?"), file);
-               int const ret = Alert::prompt(_("Create new document?"),
-                       text, 0, 1, _("&Create"), _("Cancel"));
-
-               if (ret == 0)
-                       b = newFile(s, string(), true);
-
-               break;
-               }
-       }
-
-       if (b && tolastfiles)
-               lastfiles->newFile(b->fileName());
-
-       return b;
-}
-
-
 void BufferList::setCurrentAuthor(string const & name, string const & email)
 {
        BufferStorage::iterator it = bstore.begin();
index 5ba7e6ffc581c5bb16fc9a4135ba6b140f23b051..a9f8768c1d2d9afe29d3bfb79a4fd62df46f9cd8 100644 (file)
@@ -29,17 +29,6 @@ class BufferList : boost::noncopyable {
 public:
        BufferList();
 
-       /**
-          Loads a LyX file or...
-
-          \param filename The filename to read from.
-          \param tolastfiles Wether the file should be put in the
-          last opened files list or not.
-          \return The newly loaded LyX file.
-       */
-       Buffer * loadLyXFile(string const & filename,
-                            bool tolastfiles = true);
-
        /// write all buffers, asking the user, returns false if cancelled
        bool quitWriteAll();
 
@@ -52,11 +41,6 @@ public:
        /// Close all open buffers.
        void closeAll();
 
-       /// read the given file
-       Buffer * readFile(string const &, bool ro);
-
-       /// Make a new file (buffer) using a template
-       Buffer * newFile(string const &, string, bool isNamed = false);
        /// returns a vector with all the buffers filenames
        std::vector<string> const getFileNames() const;
 
index 0efc0c12f9ded199cc0c903d6210c52e6a99379a..9b047d62b76e6dad5f8254ab776f1f2c9c80befd 100644 (file)
@@ -1,3 +1,9 @@
+
+2003-06-19  Alfredo Braunstein  <abraunst@libero.it>
+
+       * lyx_gui.C (start): call ::loadLyXFile instead 
+       of BufferList::loadLyXFile
+       
 2003-06-19  Angus Leeming  <leeming@lyx.org>
 
        * Dialogs.C:
index 38657a00b2d1026d77622e0dbc4ec32585dff5a8..08413432c01cefb96528d2298bdffade7514a331 100644 (file)
@@ -28,6 +28,7 @@
 
 // FIXME: move this stuff out again
 #include "bufferlist.h"
+#include "buffer_funcs.h"
 #include "lyxfunc.h"
 #include "lyxserver.h"
 #include "BufferView.h"
@@ -153,10 +154,9 @@ void start(string const & batch, vector<string> const & files)
        vector<string>::const_iterator cit = files.begin();
        vector<string>::const_iterator end = files.end();
        for (; cit != end; ++cit) {
-               Buffer * b = bufferlist.loadLyXFile(*cit);
-               if (b) {
+               Buffer * b = bufferlist.newBuffer(*cit);
+               if (loadLyXFile(b, *cit))
                        last = b;
-               }
        }
 
        // switch to the last buffer successfully loaded
index 01d1e4cbb016bb3c3a5daa3bb8a307e5b5bb0e5e..5744d42a83aa67ba1ebf8280080be63100f0274c 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-19  Alfredo Braunstein  <abraunst@libero.it>
+
+       * lyx_gui.C (start): call ::loadLyXFile instead 
+       of BufferList::loadLyXFile
+       
 2003-06-19  Angus Leeming  <leeming@lyx.org>
 
        * Dialogs.C:
index cb3849f5392eca46715da6529b105867ba19bbb9..ccf772656dad5a67ddff495607940ee9ee2a53b9 100644 (file)
@@ -27,6 +27,7 @@
 
 // FIXME: move this stuff out again
 #include "bufferlist.h"
+#include "buffer_funcs.h"
 #include "lyxfunc.h"
 #include "lyxserver.h"
 #include "BufferView.h"
@@ -285,10 +286,9 @@ void start(string const & batch, vector<string> const & files)
        vector<string>::const_iterator cit = files.begin();
        vector<string>::const_iterator end = files.end();
        for (; cit != end; ++cit) {
-               Buffer * b = bufferlist.loadLyXFile(*cit);
-               if (b) {
+               Buffer * b = bufferlist.newBuffer(*cit);
+               if (loadLyXFile(b, *cit))
                        last = b;
-               }
        }
 
        // switch to the last buffer successfully loaded
index d79ed4be5f1826344a142e5107c934f11c44fa83..d5b6a60f028b8cad2f044621dd12b3e98188e840 100644 (file)
@@ -18,6 +18,7 @@
 #include "funcrequest.h"
 
 #include "bufferlist.h"
+#include "buffer_funcs.h"
 #include "support/filetools.h"
 #include "frontends/Alert.h"
 #include "gettext.h"
@@ -65,11 +66,9 @@ bool Importer::Import(LyXView * lv, string const & filename,
 
 
        if (loader_format == "lyx") {
-               Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
-               if (buffer)
-                       lv->view()->buffer(buffer);
+               lv->view()->loadLyXFile(lyxfile);
        } else {
-               lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
+               lv->view()->buffer(newFile(lyxfile, string(), true));
                bool as_paragraphs = loader_format == "textparagraph";
                string filename2 = (loader_format == format) ? filename
                        : ChangeExtension(filename,
index d9333fd0dcff88bc41ee5273bdfdee9d1eca15e3..ce91287b07c5d94beba818c717d8a20516a7185c 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-19  Alfredo Braunstein  <abraunst@libero.it>
+
+       * insetinclude.C (loadIfNeeded): call ::loadLyXFile instead 
+       of BufferList::loadLyXFile
+       
 2003-06-18  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * insettext.C (update): simplify
index 4a1a773adeca30ea747aeb81a6bd03aabe681abc..774f3334392779d81232297fb0d68be6d30d8b62 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "insetinclude.h"
 #include "buffer.h"
+#include "buffer_funcs.h"
 #include "bufferlist.h"
 #include "BufferView.h"
 #include "debug.h"
@@ -293,8 +294,8 @@ bool InsetInclude::loadIfNeeded() const
        FileInfo finfo(getFileName());
        if (!finfo.isOK())
                return false;
-
-       return bufferlist.loadLyXFile(getFileName(), false) != 0;
+       return loadLyXFile(bufferlist.newBuffer(getFileName()),
+                          getFileName());
 }
 
 
index 08dc527a06e0c7044793240edccc7699a4a338d2..5348675679fefa664f161629588d7376afc34568 100644 (file)
@@ -13,6 +13,7 @@
 #include "lyx_cb.h"
 #include "lyx_main.h"
 #include "buffer.h"
+#include "buffer_funcs.h"
 #include "bufferlist.h"
 #include "bufferview_funcs.h"
 #include "debug.h"
@@ -326,7 +327,7 @@ Buffer * NewFile(string const & filename)
                            << "\nTemplate is " << tmpname << endl;
 
        // find a free buffer
-       Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
+       Buffer * tmpbuf = newFile(name, tmpname);
        if (tmpbuf)
                lastfiles->newFile(tmpbuf->fileName());
        return tmpbuf;
index f323a19069e7b52177e7380761f5a3267e131388..ad0165acc21ae120ce346a91c1b57d400185b112 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "bufferlist.h"
 #include "buffer.h"
+#include "buffer_funcs.h"
 #include "lyxserver.h"
 #include "kbmap.h"
 #include "lyxfunc.h"
@@ -142,14 +143,16 @@ LyX::LyX(int & argc, char * argv[])
                vector<string>::iterator it = files.begin();
                vector<string>::iterator end = files.end();
                for (; it != end; ++it) {
-                       last_loaded = bufferlist.loadLyXFile(*it);
+                       last_loaded = bufferlist.newBuffer(*it, false);
+                       loadLyXFile(last_loaded, *it);
                }
 
                files.clear();
 
                // no buffer loaded, create one
+               string const tmpfile = "tmpfile";
                if (!last_loaded)
-                       last_loaded = bufferlist.newFile("tmpfile", string());
+                       last_loaded = newFile(tmpfile, string());
 
                bool success = false;
 
index f155dd9ad96c9cf0d4c2777707fae20492a56ab4..576d918963acbdcd4b81dca3f74ed21ff9712c61 100644 (file)
@@ -16,6 +16,7 @@
 #include "lyxrow.h"
 #include "bufferlist.h"
 #include "buffer.h"
+#include "buffer_funcs.h"
 #include "BufferView.h"
 #include "lyxserver.h"
 #include "intl.h"
@@ -1195,7 +1196,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                }
                owner->message(bformat(_("Opening help file %1$s..."),
                        MakeDisplayPath(fname)));
-               view()->buffer(bufferlist.loadLyXFile(fname, false));
+               view()->loadLyXFile(fname, false);
                break;
        }
 
@@ -1307,7 +1308,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                if (bufferlist.exists(s)) {
                        view()->buffer(bufferlist.getBuffer(s));
                } else {
-                       view()->buffer(bufferlist.loadLyXFile(s));
+                       view()->loadLyXFile(s);
                }
 
                view()->setCursorFromRow(row);
@@ -1455,7 +1456,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                if (bufferlist.exists(filename))
                        view()->buffer(bufferlist.getBuffer(filename));
                else
-                       view()->buffer(bufferlist.loadLyXFile(filename));
+                       view()->loadLyXFile(filename);
        }
        break;
 
@@ -1714,7 +1715,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
                templname = fname;
        }
 
-       view()->buffer(bufferlist.newFile(filename, templname, !name.empty()));
+       view()->buffer(newFile(filename, templname, !name.empty()));
 }
 
 
@@ -1769,17 +1770,15 @@ void LyXFunc::open(string const & fname)
        FileInfo const f(filename, true);
        if (!f.exist()) {
                // the user specifically chose this name. Believe them.
-               Buffer * buffer =  bufferlist.newFile(filename, "", true);
+               Buffer * buffer =  newFile(filename, "", true);
                view()->buffer(buffer);
                return;
        }
 
        owner->message(bformat(_("Opening document %1$s..."), disp_fn));
 
-       Buffer * openbuf = bufferlist.loadLyXFile(filename);
        string str2;
-       if (openbuf) {
-               view()->buffer(openbuf);
+       if (view()->loadLyXFile(filename)) {
                str2 = bformat(_("Document %1$s opened."), disp_fn);
        } else {
                str2 = bformat(_("Could not open document %1$s"), disp_fn);