]> git.lyx.org Git - lyx.git/blobdiff - src/bufferlist.C
next step...
[lyx.git] / src / bufferlist.C
index 5dc320670da45f26abb4836f1af45ff6e559056b..c5af8316686d4dea579960ac7a608988cf70db86 100644 (file)
@@ -4,9 +4,9 @@
  *           LyX, The Document Word Processor
  *
  *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2000 The LyX Team. 
+ *           Copyright 1995-2001 The LyX Team. 
  *
- *           This file is Copyright 1996-2000
+ *           This file is Copyright 1996-2001
  *           Lars Gullik Bjønnes
  *
  * ====================================================== 
@@ -18,6 +18,7 @@
 
 #include <config.h>
 
+#include <assert.h>
 #include <algorithm>
 #include <functional>
 
@@ -27,6 +28,7 @@
 #include "support/filetools.h"
 #include "support/lyxmanip.h"
 #include "support/lyxfunctional.h"
+#include "support/LAssert.h"
 #include "lyx_gui_misc.h"
 #include "lastfiles.h"
 #include "debug.h"
@@ -34,6 +36,7 @@
 #include "lyxtext.h"
 #include "lyx_cb.h"
 #include "bufferview_funcs.h"
+#include "BufferView.h"
 #include "gettext.h"
 #include "LyXView.h"
 #include "vc-backend.h"
@@ -94,7 +97,7 @@ bool BufferList::empty() const
 }
 
 
-bool BufferList::QwriteAll()
+bool BufferList::qwriteAll()
 {
         bool askMoreConfirmation = false;
         string unsaved;
@@ -161,12 +164,6 @@ void BufferList::closeAll()
 }
 
 
-void BufferList::resize()
-{
-       for_each(bstore.begin(), bstore.end(), mem_fun(&Buffer::resize));
-}
-
-
 bool BufferList::close(Buffer * buf)
 {
        lyx::Assert(buf);
@@ -178,7 +175,7 @@ bool BufferList::close(Buffer * buf)
         if (buf->getUser()) buf->getUser()->insetUnlock();
        if (buf->paragraph && !buf->isLyxClean() && !quitting) {
                if (buf->getUser())
-                       ProhibitInput(buf->getUser());
+                       buf->getUser()->owner()->prohibitInput();
                string fname;
                if (buf->isUnnamed())
                        fname = OnlyFilename(buf->fileName());
@@ -197,7 +194,7 @@ bool BufferList::close(Buffer * buf)
                                        reask = false;
                                } else {
                                        if (buf->getUser())
-                                               AllowInput(buf->getUser());
+                                               buf->getUser()->owner()->allowInput();
                                        return false;
                                }
                                break;
@@ -209,12 +206,12 @@ bool BufferList::close(Buffer * buf)
                                break;
                        case 3: // Cancel
                                if (buf->getUser())
-                                       AllowInput(buf->getUser());
+                                       buf->getUser()->owner()->allowInput();
                                return false;
                        }
                }
                if (buf->getUser())
-                       AllowInput(buf->getUser());
+                       buf->getUser()->owner()->allowInput();
        }
 
        bstore.release(buf);
@@ -353,6 +350,12 @@ Buffer * BufferList::readFile(string const & s, bool ronly)
        // File information about normal file
        FileInfo fileInfo2(s);
 
+       if (!fileInfo2.exist()) {
+               WriteAlert(_("Error!"), _("Cannot open file"), 
+                       MakeDisplayPath(s));
+               return 0;
+       }
        // Check if emergency save file exists and is newer.
        e += OnlyFilename(s) + ".emergency";
        FileInfo fileInfoE(e);
@@ -448,11 +451,11 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
        if (tname.empty()) {
                tname = LibFileSearch("templates", "defaults.lyx");
        }
-       if (!tname.empty() && IsLyXFilename(tname)) {
+       if (!tname.empty()) {
                bool templateok = false;
                LyXLex lex(0, 0);
                lex.setFile(tname);
-               if (lex.IsOK()) {
+               if (lex.isOK()) {
                        if (b->readFile(lex)) {
                                templateok = true;
                        }
@@ -461,10 +464,10 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
                        WriteAlert(_("Error!"), _("Unable to open template"), 
                                   MakeDisplayPath(tname));
                        // no template, start with empty buffer
-                       b->paragraph = new LyXParagraph;
+                       b->paragraph = new Paragraph;
                }
        } else {  // start with empty buffer
-               b->paragraph = new LyXParagraph;
+               b->paragraph = new Paragraph;
        }
 
        if (!lyxrc.new_ask_filename && !isNamed) {
@@ -480,8 +483,12 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
 
 Buffer * BufferList::loadLyXFile(string const & filename, bool tolastfiles)
 {
-       // make sure our path is absolute
-       string const s = MakeAbsPath(filename);
+       // 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)) {