]> git.lyx.org Git - lyx.git/blobdiff - src/bufferlist.C
ws changes and some cruft removal, slight cleanup
[lyx.git] / src / bufferlist.C
index 41327e41ecfecbfb67b30241cd611235e121ba6d..f0b289eb92f8ac88aaefa1c427beddcec8c75f33 100644 (file)
  * ====================================================== 
  */
 
+#include <config.h>
+
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
-#include <config.h>
-
-#include <assert.h>
-#include <algorithm>
-#include <functional>
-
-#include "frontends/Alert.h"
 #include "bufferlist.h"
 #include "lyx_main.h"
-#include "support/FileInfo.h"
-#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"
 #include "lyxrc.h"
 #include "LyXView.h"
 #include "vc-backend.h"
 #include "TextCache.h"
+#include "lyxtextclasslist.h"
+
+#include "frontends/Alert.h"
+
+#include "support/FileInfo.h"
+#include "support/filetools.h"
+#include "support/lyxmanip.h"
+#include "support/lyxfunctional.h"
+#include "support/LAssert.h"
+
+#include <cassert>
+#include <algorithm>
+#include <functional>
+
 
 using std::vector;
 using std::find;
@@ -98,7 +101,8 @@ bool BufferList::empty() const
 }
 
 
-bool BufferList::qwriteOne(Buffer * buf, string const & fname, string & unsaved_list)
+bool BufferList::qwriteOne(Buffer * buf, string const & fname,
+                          string & unsaved_list)
 {
        bool reask = true;
        while (reask) {
@@ -134,9 +138,9 @@ bool BufferList::qwriteOne(Buffer * buf, string const & fname, string & unsaved_
 bool BufferList::qwriteAll()
 {
        string unsaved;
-       for (BufferStorage::iterator it = bstore.begin();
-            it != bstore.end(); ++it)
-       {
+       BufferStorage::iterator it = bstore.begin();
+       BufferStorage::iterator end = bstore.end();
+       for (; it != end; ++it) {
                if (!(*it)->isLyxClean()) {
                        string fname;
                        if ((*it)->isUnnamed())
@@ -179,7 +183,9 @@ bool BufferList::close(Buffer * buf)
        // Trace back why we need to use buf->getUser here.
        // Perhaps slight rewrite is in order? (Lgb)
        
-        if (buf->getUser()) buf->getUser()->insetUnlock();
+        if (buf->getUser())
+               buf->getUser()->insetUnlock();
+       
        if (buf->paragraph && !buf->isLyxClean() && !quitting) {
                if (buf->getUser())
                        buf->getUser()->owner()->prohibitInput();
@@ -192,7 +198,7 @@ bool BufferList::close(Buffer * buf)
                while (reask) {
                        switch (Alert::askConfirmation(_("Changes in document:"),
                                               fname,
-                                              _("Save document?"))){
+                                              _("Save document?"))) {
                        case 1: // Yes
                                if (buf->isUnnamed())
                                        reask = !WriteAs(current_view, buf);
@@ -237,14 +243,16 @@ vector<string> const BufferList::getFileNames() const
 
 Buffer * BufferList::first()
 {
-       if (bstore.empty()) return 0;
+       if (bstore.empty())
+               return 0;
        return bstore.front();
 }
 
 
 Buffer * BufferList::getBuffer(unsigned int choice)
 {
-       if (choice >= bstore.size()) return 0;
+       if (choice >= bstore.size())
+               return 0;
        return bstore[choice];
 }
 
@@ -253,9 +261,9 @@ int BufferList::unlockInset(UpdatableInset * inset)
 {
        lyx::Assert(inset);
        
-       //if (!inset) return 1;
-       for (BufferStorage::iterator it = bstore.begin();
-            it != bstore.end(); ++it) {
+       BufferStorage::iterator it = bstore.begin();
+       BufferStorage::iterator end = bstore.end();
+       for (; it != end; ++it) {
                if ((*it)->getUser()
                    && (*it)->getUser()->theLockingInset() == inset) {
                        (*it)->getUser()->insetUnlock();
@@ -268,8 +276,9 @@ int BufferList::unlockInset(UpdatableInset * inset)
 
 void BufferList::updateIncludedTeXfiles(string const & mastertmpdir)
 {
-       for (BufferStorage::iterator it = bstore.begin();
-            it != bstore.end(); ++it) {
+       BufferStorage::iterator it = bstore.begin();
+       BufferStorage::iterator end = bstore.end();
+       for (; it != end; ++it) {
                if (!(*it)->isDepClean(mastertmpdir)) {
                        string writefile = mastertmpdir;
                        writefile += '/';
@@ -297,7 +306,8 @@ void BufferList::emergencyWrite(Buffer * buf)
 
        
        // No need to save if the buffer has not changed.
-       if (buf->isLyxClean()) return;
+       if (buf->isLyxClean())
+               return;
        
        lyxerr << fmt(_("lyx: Attempting to save document %s as..."),
                      buf->isUnnamed() ? OnlyFilename(buf->fileName()).c_str()
@@ -349,9 +359,7 @@ void BufferList::emergencyWrite(Buffer * buf)
 
 Buffer * BufferList::readFile(string const & s, bool ronly)
 {
-       Buffer * b = bstore.newBuffer(s, ronly);
-
-       string ts = s;
+       string ts(s);
        string e = OnlyPath(s);
        string a = e;
        // File information about normal file
@@ -363,6 +371,8 @@ Buffer * BufferList::readFile(string const & s, bool ronly)
                return 0;
        }
  
+       Buffer * b = bstore.newBuffer(s, ronly);
+
        // Check if emergency save file exists and is newer.
        e += OnlyFilename(s) + ".emergency";
        FileInfo fileInfoE(e);
@@ -468,13 +478,15 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
                        }
                }
                if (!templateok) {
-                       Alert::alert(_("Error!"), _("Unable to open template"), 
+                       Alert::alert(_("Error!"), _("Unable to open template"),
                                   MakeDisplayPath(tname));
                        // no template, start with empty buffer
                        b->paragraph = new Paragraph;
+                       b->paragraph->layout(textclasslist[b->params.textclass].defaultLayoutName());
                }
        } else {  // start with empty buffer
                b->paragraph = new Paragraph;
+                       b->paragraph->layout(textclasslist[b->params.textclass].defaultLayoutName());
        }
 
        if (!lyxrc.new_ask_filename && !isNamed) {
@@ -534,7 +546,7 @@ Buffer * BufferList::loadLyXFile(string const & filename, bool tolastfiles)
                                // 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::retrive(s);
+                               RCS::retrieve(s);
                                return loadLyXFile(filename, tolastfiles);
                        }
                }