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
This commit is contained in:
Georg Baum 2006-07-17 15:13:49 +00:00
parent 20a9acdece
commit 04986c096a
6 changed files with 23 additions and 8 deletions

View 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;
}

View 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;
}
}

View 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,

View 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);
}

View 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))

View 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;
}