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

	* src/BufferView_pimpl.[Ch]
	(BufferView::Pimpl::newFile): remove, not used anymore

	* src/BufferView.C
	(BufferView::newFile): remove, not used anymore


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@14623 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2006-08-12 12:31:19 +00:00
parent 98151fde55
commit 2a64df96f9
10 changed files with 30 additions and 28 deletions

View File

@ -107,12 +107,6 @@ void BufferView::setBuffer(Buffer * b)
} }
void BufferView::newFile(string const & fn, string const & tn, bool named)
{
pimpl_->newFile(fn, tn, named);
}
bool BufferView::loadLyXFile(string const & fn, bool tl) bool BufferView::loadLyXFile(string const & fn, bool tl)
{ {
return pimpl_->loadLyXFile(fn, tl); return pimpl_->loadLyXFile(fn, tl);

View File

@ -92,9 +92,6 @@ public:
/// reload the contained buffer /// reload the contained buffer
void reload(); void reload();
/// create a new buffer based on template
void newFile(std::string const & fname, std::string const & tname,
bool named = true);
/// load a buffer into the view /// load a buffer into the view
bool loadLyXFile(std::string const & name, bool tolastfiles = true); bool loadLyXFile(std::string const & name, bool tolastfiles = true);

View File

@ -232,13 +232,6 @@ void BufferView::Pimpl::disconnectBuffer()
} }
void BufferView::Pimpl::newFile(string const & filename, string const & tname,
bool isNamed)
{
setBuffer(::newFile(filename, tname, isNamed));
}
bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
{ {
// Get absolute path of file and add ".lyx" // Get absolute path of file and add ".lyx"
@ -285,9 +278,11 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
int const ret = Alert::prompt(_("Create new document?"), int const ret = Alert::prompt(_("Create new document?"),
text, 0, 1, _("&Create"), _("Cancel")); text, 0, 1, _("&Create"), _("Cancel"));
if (ret == 0) if (ret == 0) {
b = ::newFile(s, string(), true); b = newFile(s, string(), true);
else if (!b)
return false;
} else
return false; return false;
} }

View File

@ -64,8 +64,6 @@ public:
/// ///
void update(Update::flags flags = Update::Force); void update(Update::flags flags = Update::Force);
/// ///
void newFile(std::string const &, std::string const &, bool);
///
bool loadLyXFile(std::string const &, bool); bool loadLyXFile(std::string const &, bool);
/// ///
void workAreaResize(); void workAreaResize();

View File

@ -189,7 +189,8 @@ Buffer * newFile(string const & filename, string const & templatename,
string const file = MakeDisplayPath(tname, 50); string const file = MakeDisplayPath(tname, 50);
string const text = bformat(_("The specified document template\n%1$s\ncould not be read."), file); string const text = bformat(_("The specified document template\n%1$s\ncould not be read."), file);
Alert::error(_("Could not read template"), text); Alert::error(_("Could not read template"), text);
// no template, start with empty buffer bufferlist.release(b);
return 0;
} }
} }

View File

@ -23,6 +23,7 @@
#include "frontends/Alert.h" #include "frontends/Alert.h"
#include "gettext.h" #include "gettext.h"
#include "BufferView.h" #include "BufferView.h"
#include "buffer_funcs.h"
using lyx::support::bformat; using lyx::support::bformat;
using lyx::support::ChangeExtension; using lyx::support::ChangeExtension;
@ -71,7 +72,11 @@ bool Importer::Import(LyXView * lv, string const & filename,
if (loader_format == "lyx") { if (loader_format == "lyx") {
lv->view()->loadLyXFile(lyxfile); lv->view()->loadLyXFile(lyxfile);
} else { } else {
lv->view()->newFile(lyxfile, string(), true); Buffer * const b = newFile(lyxfile, string(), true);
if (b)
lv->view()->setBuffer(b);
else
return false;
bool as_paragraphs = loader_format == "textparagraph"; bool as_paragraphs = loader_format == "textparagraph";
string filename2 = (loader_format == format) ? filename string filename2 = (loader_format == format) ? filename
: ChangeExtension(filename, : ChangeExtension(filename,

View File

@ -19,6 +19,7 @@
#include "buffer.h" #include "buffer.h"
#include "bufferlist.h" #include "bufferlist.h"
#include "BufferView.h" #include "BufferView.h"
#include "buffer_funcs.h"
#include "cursor.h" #include "cursor.h"
#include "debug.h" #include "debug.h"
#include "gettext.h" #include "gettext.h"
@ -351,7 +352,9 @@ void NewFile(BufferView * bv, string const & filename)
<< "\nName is " << name << "\nName is " << name
<< "\nTemplate is " << tmpname << endl; << "\nTemplate is " << tmpname << endl;
bv->newFile(name, tmpname); Buffer * const b = newFile(name, tmpname);
if (b)
bv->setBuffer(b);
} }

View File

@ -272,7 +272,9 @@ void LyX::exec2(int & argc, char * argv[])
// the filename if necessary // the filename if necessary
string s = FileSearch(string(), *it, "lyx"); string s = FileSearch(string(), *it, "lyx");
if (s.empty()) { if (s.empty()) {
last_loaded = newFile(*it, string(), true); Buffer * const b = newFile(*it, string(), true);
if (b)
last_loaded = b;
} else { } else {
Buffer * buf = bufferlist.newBuffer(s, false); Buffer * buf = bufferlist.newBuffer(s, false);
buf->error.connect(boost::bind(&LyX::printError, this, _1)); buf->error.connect(boost::bind(&LyX::printError, this, _1));

View File

@ -1724,7 +1724,9 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
templname = result.second; templname = result.second;
} }
view()->newFile(filename, templname, !name.empty()); Buffer * const b = newFile(filename, templname, !name.empty());
if (b)
view()->setBuffer(b);
} }
@ -1778,8 +1780,10 @@ void LyXFunc::open(string const & fname)
// if the file doesn't exist, let the user create one // if the file doesn't exist, let the user create one
if (!fs::exists(filename)) { if (!fs::exists(filename)) {
// the user specifically chose this name. Believe them. // the user specifically chose this name. Believe him.
view()->newFile(filename, "", true); Buffer * const b = newFile(filename, string(), true);
if (b)
view()->setBuffer(b);
return; return;
} }

View File

@ -62,6 +62,9 @@ What's new
- Fix the C-x C-b binding in emacs mode (bug 2747). - Fix the C-x C-b binding in emacs mode (bug 2747).
- Fix a crash when a non-template file is selected in the
"New from Template" dialog (bug 2404)
* Build/installation: * Build/installation:
- Fix 'check' make target for systems which do not have /bin/bash (bug 2524). - Fix 'check' make target for systems which do not have /bin/bash (bug 2524).