diff --git a/src/BufferView.C b/src/BufferView.C index 2dc1129034..6509e3a52f 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -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) { return pimpl_->loadLyXFile(fn, tl); diff --git a/src/BufferView.h b/src/BufferView.h index 2940d77586..f572b7d84a 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -92,9 +92,6 @@ public: /// reload the contained buffer 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 bool loadLyXFile(std::string const & name, bool tolastfiles = true); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 52ac54533b..75fa06d495 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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) { // 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?"), text, 0, 1, _("&Create"), _("Cancel")); - if (ret == 0) - b = ::newFile(s, string(), true); - else + if (ret == 0) { + b = newFile(s, string(), true); + if (!b) + return false; + } else return false; } diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index c6ac78f6f7..d69ddc3d73 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -64,8 +64,6 @@ public: /// void update(Update::flags flags = Update::Force); /// - void newFile(std::string const &, std::string const &, bool); - /// bool loadLyXFile(std::string const &, bool); /// void workAreaResize(); diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index 8886920d89..0bc94fc9ff 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -189,7 +189,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 672edcdc6e..a1869f81b7 100644 --- a/src/importer.C +++ b/src/importer.C @@ -23,6 +23,7 @@ #include "frontends/Alert.h" #include "gettext.h" #include "BufferView.h" +#include "buffer_funcs.h" using lyx::support::bformat; using lyx::support::ChangeExtension; @@ -71,7 +72,11 @@ bool Importer::Import(LyXView * lv, string const & filename, if (loader_format == "lyx") { lv->view()->loadLyXFile(lyxfile); } 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"; string filename2 = (loader_format == format) ? filename : ChangeExtension(filename, diff --git a/src/lyx_cb.C b/src/lyx_cb.C index a2c95a1711..3d00b76568 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -19,6 +19,7 @@ #include "buffer.h" #include "bufferlist.h" #include "BufferView.h" +#include "buffer_funcs.h" #include "cursor.h" #include "debug.h" #include "gettext.h" @@ -351,7 +352,9 @@ void NewFile(BufferView * bv, string const & filename) << "\nName is " << name << "\nTemplate is " << tmpname << endl; - bv->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 c6c45fb7e8..c0cf62ad6d 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -272,7 +272,9 @@ void 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); buf->error.connect(boost::bind(&LyX::printError, this, _1)); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index f74e23d286..23818afe73 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1724,7 +1724,9 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate) 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 (!fs::exists(filename)) { - // the user specifically chose this name. Believe them. - view()->newFile(filename, "", true); + // the user specifically chose this name. Believe him. + Buffer * const b = newFile(filename, string(), true); + if (b) + view()->setBuffer(b); return; } diff --git a/status.14x b/status.14x index 819900cea4..0326b5e54e 100644 --- a/status.14x +++ b/status.14x @@ -62,6 +62,9 @@ What's new - 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: - Fix 'check' make target for systems which do not have /bin/bash (bug 2524).