* 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
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;
}
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;
}
}
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,
<< "\nName is " << name
<< "\nTemplate is " << tmpname << endl;
- bv->setBuffer(newFile(name, tmpname));
+ Buffer * const b = newFile(name, tmpname);
+ if (b)
+ bv->setBuffer(b);
}
// 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))
templname = result.second;
}
- owner->setBuffer(newFile(filename, templname, !name.empty()));
+ Buffer * const b = newFile(filename, templname, !name.empty());
+ if (b)
+ owner->setBuffer(b);
}
// 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;
}