]> git.lyx.org Git - features.git/commitdiff
Fix bug 2404
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 17 Jul 2006 15:13:49 +0000 (15:13 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 17 Jul 2006 15:13:49 +0000 (15:13 +0000)
* src/lyx_cb.C
(newFile): Only set the new buffer if it is valid

* src/BufferView_pimpl.C
(BufferView::Pimpl::loadLyXFile): Test whether newFile succeeded

* src/lyxfunc.C
(LyXFunc::menuNew): Only set the new buffer if it is valid
(LyXFunc::open): ditto

* src/importer.C
(Importer::Import): ditto

* src/lyx_main.C
(LyX::exec2): Only use the new buffer if newFile succeeded

* src/buffer_funcs.C
(newFile): discard the buffer and return 0 if the template is invalid

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14474 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView_pimpl.C
src/buffer_funcs.C
src/importer.C
src/lyx_cb.C
src/lyx_main.C
src/lyxfunc.C

index 2c4e1e7d4256cfd0e2f653ec23eb04b03abcef26..f5ada3539066d987c308125fed61e059c3bb708a 100644 (file)
@@ -189,9 +189,11 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
                int const ret = Alert::prompt(_("Create new document?"),
                         text, 0, 1, _("&Create"), _("Cancel"));
 
-               if (ret == 0)
+               if (ret == 0) {
                        b = newFile(s, string(), true);
-               else
+                       if (!b)
+                               return false;
+               } else
                        return false;
        }
 
index 0d1cb5cddfef03dedd6964469d426bfb67c964db..a306de412efbce0716e08b1f3e0d13519da27e2d 100644 (file)
@@ -194,7 +194,8 @@ Buffer * newFile(string const & filename, string const & templatename,
                        string const file = makeDisplayPath(tname, 50);
                        string const text  = bformat(_("The specified document template\n%1$s\ncould not be read."), file);
                        Alert::error(_("Could not read template"), text);
-                       // no template, start with empty buffer
+                       bufferlist.release(b);
+                       return 0;
                }
        }
 
index b2d6f12156d10f693f6fb8762781344ea196b7f1..b4e135cc8b60c94f991e799bbd52beedfd50c5ea 100644 (file)
@@ -72,7 +72,11 @@ bool Importer::Import(LyXView * lv, string const & filename,
        if (loader_format == "lyx") {
                lv->loadLyXFile(lyxfile);
        } else {
-               lv->setBuffer(newFile(lyxfile, string(), true));
+               Buffer * const b = newFile(lyxfile, string(), true);
+               if (b)
+                       lv->setBuffer(b);
+               else
+                       return false;
                bool as_paragraphs = loader_format == "textparagraph";
                string filename2 = (loader_format == format) ? filename
                        : changeExtension(filename,
index c47d517869b5abcc7a7e67b23ab6c1df2a3fbce3..028cd74f4b8aeb3ef692be403e68e004bf782ff3 100644 (file)
@@ -343,7 +343,9 @@ void newFile(BufferView * bv, string const & filename)
                            << "\nName is " << name
                            << "\nTemplate is " << tmpname << endl;
 
-       bv->setBuffer(newFile(name, tmpname));
+       Buffer * const b = newFile(name, tmpname);
+       if (b)
+               bv->setBuffer(b);
 }
 
 
index e5a31af35c8b9d56d59244cf26ff141063ac6fe9..02c9758989484d5c3478e83d17a734aa25360544 100644 (file)
@@ -283,7 +283,9 @@ int LyX::exec2(int & argc, char * argv[])
                        // the filename if necessary
                        string s = fileSearch(string(), *it, "lyx");
                        if (s.empty()) {
-                               last_loaded = newFile(*it, string(), true);
+                               Buffer * const b = newFile(*it, string(), true);
+                               if (b)
+                                       last_loaded = b;
                        } else {
                                Buffer * buf = bufferlist.newBuffer(s, false);
                                if (loadLyXFile(buf, s))
index 6cadfff1473460025a1e3b2727509b0e0ce1a9d3..1cff4e2847999abaccce85d0a86b3283d9e7240a 100644 (file)
@@ -1735,7 +1735,9 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
                templname = result.second;
        }
 
-       owner->setBuffer(newFile(filename, templname, !name.empty()));
+       Buffer * const b = newFile(filename, templname, !name.empty());
+       if (b)
+               owner->setBuffer(b);
 }
 
 
@@ -1790,7 +1792,9 @@ void LyXFunc::open(string const & fname)
        // if the file doesn't exist, let the user create one
        if (!fs::exists(filename)) {
                // the user specifically chose this name. Believe him.
-               owner->setBuffer(newFile(filename, "", true));
+               Buffer * const b = newFile(filename, string(), true);
+               if (b)
+                       owner->setBuffer(b);
                return;
        }