From: Georg Baum Date: Mon, 17 Jul 2006 15:13:49 +0000 (+0000) Subject: Fix bug 2404 X-Git-Tag: 1.6.10~12933 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=04986c096a9bd58fe4e3e1fbb51d166aa60500ed;p=features.git Fix bug 2404 * 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 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 2c4e1e7d42..f5ada35390 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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; } diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index 0d1cb5cddf..a306de412e 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -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; } } diff --git a/src/importer.C b/src/importer.C index b2d6f12156..b4e135cc8b 100644 --- a/src/importer.C +++ b/src/importer.C @@ -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, diff --git a/src/lyx_cb.C b/src/lyx_cb.C index c47d517869..028cd74f4b 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -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); } diff --git a/src/lyx_main.C b/src/lyx_main.C index e5a31af35c..02c9758989 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -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)) diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 6cadfff147..1cff4e2847 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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; }