From: Alfredo Braunstein Date: Tue, 29 Jul 2003 16:40:26 +0000 (+0000) Subject: Fix to Bug 1287 and Bug 1297 X-Git-Tag: 1.6.10~16388 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=5fb7795b10d163bbc669404dd1743e0ad32ee41b;p=features.git Fix to Bug 1287 and Bug 1297 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7443 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 2efe77dc3d..c15bf9b7d2 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -188,9 +188,11 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) // get absolute path of file and add ".lyx" to the filename if // necessary string s = FileSearch(string(), filename, "lyx"); - if (s.empty()) { + + bool const found = !s.empty(); + + if (!found) s = filename; - } // file already open? if (bufferlist.exists(s)) { @@ -211,29 +213,35 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) // Fall through to new load. (Asger) } } - Buffer * b = bufferlist.newBuffer(s); - connectBuffer(*b); + Buffer * b; - if (! ::loadLyXFile(b, s)) { - bufferlist.release(b); + if (found) { + b = bufferlist.newBuffer(s); + connectBuffer(*b); + if (!::loadLyXFile(b, s)) { + bufferlist.release(b); + return false; + } + } else { string text = bformat(_("The document %1$s does not yet " "exist.\n\nDo you want to create " "a new document?"), s); 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 return false; } buffer(b); + bv_->showErrorList(_("Parse")); if (tolastfiles) lastfiles->newFile(b->fileName()); - bv_->showErrorList(_("Parse")); - return true; } @@ -281,18 +289,16 @@ void BufferView::Pimpl::buffer(Buffer * b) return; // if we are closing the buffer, use the first buffer as current - if (!buffer_) { + if (!buffer_) buffer_ = bufferlist.first(); - } if (buffer_) { lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl; connectBuffer(*buffer_); // If we don't have a text object for this, we make one - if (bv_->text == 0) { + if (bv_->text == 0) resizeCurrentBuffer(); - } // FIXME: needed when ? bv_->text->top_y(screen().topCursorVisible(bv_->text)); diff --git a/src/ChangeLog b/src/ChangeLog index 571694f494..7088cf6a46 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-07-29 Alfredo Braunstein + + * lyx_main.C (LyX): + * BufferView_pimpl.C (loadLyXFile): fix to bugs 1287 and 1297 + ws + + 2003-07-29 Martin Vermeer * LaTeXFeatures.C: diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index 59b1cfc9e4..018a0bf4bd 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -163,8 +163,7 @@ Buffer * newFile(string const & filename, string const & templatename, if (!tname.empty()) { if (!b->readFile(tname)) { string const file = MakeDisplayPath(tname, 50); - string const text = bformat(_("The specified document template\n%1$s\n" - "could 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); // no template, start with empty buffer b->paragraphs.push_back(Paragraph()); diff --git a/src/frontends/xforms/lyx_gui.C b/src/frontends/xforms/lyx_gui.C index c97b591b3d..c86b834d46 100644 --- a/src/frontends/xforms/lyx_gui.C +++ b/src/frontends/xforms/lyx_gui.C @@ -290,9 +290,8 @@ void start(string const & batch, vector const & files) view.view()->loadLyXFile(*cit, true); // handle the batch commands the user asked for - if (!batch.empty()) { + if (!batch.empty()) view.getLyXFunc().dispatch(batch); - } // enter the event loop while (!finished) { diff --git a/src/lyx_main.C b/src/lyx_main.C index f12367b635..666362d229 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -59,7 +59,6 @@ using std::signal; using std::system; #endif -extern void LoadLyXFile(string const &); extern void QuitLyX(); extern LyXServer * lyxserver; @@ -97,9 +96,8 @@ LyX::LyX(int & argc, char * argv[]) // #include "graphics/GraphicsTypes.h" at the top -- Rob Lahaye. lyx::graphics::setDisplayTranslator(); - if (want_gui) { + if (want_gui) lyx_gui::parse_init(argc, argv); - } // check for any spurious extra arguments // other than documents @@ -116,15 +114,13 @@ LyX::LyX(int & argc, char * argv[]) init(want_gui); lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl; - if (want_gui) { + if (want_gui) lyx_gui::parse_lyxrc(); - } vector files; - for (int argi = argc - 1; argi >= 1; --argi) { + for (int argi = argc - 1; argi >= 1; --argi) files.push_back(argv[argi]); - } if (first_start) files.push_back(i18nLibFileSearch("examples", "splash.lyx")); @@ -145,14 +141,14 @@ LyX::LyX(int & argc, char * argv[]) // the filename if necessary string s = FileSearch(string(), *it, "lyx"); if (s.empty()) { - last_loaded = newFile(*it, ""); + last_loaded = newFile(*it, string(), true); } else { - last_loaded = bufferlist.newBuffer(s, false); - last_loaded->error.connect(boost::bind(&LyX::printError, this, _1)); - if (!loadLyXFile(last_loaded, s)) { - bufferlist.release(last_loaded); - last_loaded = newFile(*it, string()); - } + Buffer * buf = bufferlist.newBuffer(s, false); + buf->error.connect(boost::bind(&LyX::printError, this, _1)); + if (loadLyXFile(buf, s)) + last_loaded = buf; + else + bufferlist.release(buf); } }