Am Sonntag, 16. Juli 2006 16:49 schrieb Lars Gullik Bjønnes:
> Georg Baum <[EMAIL PROTECTED]> writes:
>
> | Another short fix that goes in tomorrow if nobody objects. See
> | http://bugzilla.lyx.org/show_bug.cgi?id=2404 for details.
>
> Why is this the correct fix?
>
> I would have thought a message that "this is not a template" and doing
> nothing (not loading a buffer at all) would be a more proper solution.
Good question. A message "this is not a LyX file" appears already, followed
by "The specified document template %s could not be read".
The only reason for loading the buffer nevertheless was apparently the fact
that newFile was expected to always return a valid buffer.
What about the attached patch? It does not open a new buffer if the
temnplate could not be read, and checks the return value of newFile and
acts accordingly at all places where it is called.
Georg
Index: src/lyx_cb.C
===================================================================
--- src/lyx_cb.C (Revision 14468)
+++ src/lyx_cb.C (Arbeitskopie)
@@ -343,7 +343,9 @@ void newFile(BufferView * bv, string con
<< "\nName is " << name
<< "\nTemplate is " << tmpname << endl;
- bv->setBuffer(newFile(name, tmpname));
+ Buffer * const b = newFile(name, tmpname);
+ if (b)
+ bv->setBuffer(b);
}
Index: src/BufferView_pimpl.C
===================================================================
--- src/BufferView_pimpl.C (Revision 14468)
+++ src/BufferView_pimpl.C (Arbeitskopie)
@@ -189,9 +189,11 @@ bool BufferView::Pimpl::loadLyXFile(stri
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: src/lyxfunc.C
===================================================================
--- src/lyxfunc.C (Revision 14468)
+++ src/lyxfunc.C (Arbeitskopie)
@@ -1735,7 +1735,9 @@ void LyXFunc::menuNew(string const & nam
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;
}
Index: src/importer.C
===================================================================
--- src/importer.C (Revision 14468)
+++ src/importer.C (Arbeitskopie)
@@ -72,7 +72,11 @@ bool Importer::Import(LyXView * lv, stri
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: src/lyx_main.C
===================================================================
--- src/lyx_main.C (Revision 14468)
+++ src/lyx_main.C (Arbeitskopie)
@@ -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: src/buffer_funcs.C
===================================================================
--- src/buffer_funcs.C (Revision 14468)
+++ src/buffer_funcs.C (Arbeitskopie)
@@ -194,7 +194,8 @@ Buffer * newFile(string const & filename
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;
}
}