From: Alfredo Braunstein Date: Fri, 20 Jun 2003 12:46:28 +0000 (+0000) Subject: take several functions out of BufferList, and split functionality X-Git-Tag: 1.6.10~16608 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2d8eb4b9d466e8293534ef7410737aa9448361c6;p=features.git take several functions out of BufferList, and split functionality git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7195 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView.C b/src/BufferView.C index 7b8a4cfa33..6e3d8ba3c9 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -104,11 +104,17 @@ void BufferView::buffer(Buffer * b) } +bool BufferView::loadLyXFile(string const & fn, bool tl) +{ + return pimpl_->loadLyXFile(fn, tl); +} + + void BufferView::reload() { string const fn = buffer()->fileName(); if (bufferlist.close(buffer(), false)) - buffer(bufferlist.loadLyXFile(fn)); + loadLyXFile(fn); } diff --git a/src/BufferView.h b/src/BufferView.h index 419f807b77..a2fbaed170 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -81,6 +81,8 @@ public: /// reload the contained buffer void reload(); + /// load a buffer into the view + bool loadLyXFile(string const & name, bool tolastfiles = true); /// fit the user cursor within the visible view bool fitCursor(); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 6f32514272..f2c3be9d81 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -11,6 +11,7 @@ #include "BufferView_pimpl.h" #include "bufferlist.h" #include "buffer.h" +#include "buffer_funcs.h" #include "bufferview_funcs.h" #include "lfuns.h" #include "debug.h" @@ -28,6 +29,7 @@ #include "lyxtext.h" #include "lyxrc.h" #include "lyxrow.h" +#include "lastfiles.h" #include "paragraph.h" #include "ParagraphParameters.h" #include "TextCache.h" @@ -128,6 +130,62 @@ BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner, } + +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()) { + s = filename; + } + + // file already open? + if (bufferlist.exists(s)) { + string const file = MakeDisplayPath(s, 20); + string text = bformat(_("The document %1$s is already " + "loaded.\n\nDo you want to revert " + "to the saved version?"), file); + int const ret = Alert::prompt(_("Revert to saved document?"), + text, 0, 1, _("&Revert"), _("&Switch to document")); + + if (ret != 0) { + buffer(bufferlist.getBuffer(s)); + return true; + } else { + // FIXME: should be LFUN_REVERT + if (!bufferlist.close(bufferlist.getBuffer(s), false)) + return false; + // Fall through to new load. (Asger) + } + } + Buffer * b = bufferlist.newBuffer(s); + + //this is the point to attach to the error signal in the buffer + + if (!::loadLyXFile(b, s)) { + bufferlist.release(b); + string text = bformat(_("The document %1$s does " + "not yet exist.\n\n" + "Do you want to create " + "a new document?"), s); + int const ret = Alert::prompt(_("Create new document?"), + text, 0, 1, _("&Create"), _("Cancel")); + + if (ret == 0) { + bufferlist.close(buffer_, false); + buffer(newFile(s, string(), true)); + } + } + + buffer(b); + + if (tolastfiles) + lastfiles->newFile(b->fileName()); + + return true; +} + WorkArea & BufferView::Pimpl::workarea() const { return *workarea_.get(); @@ -286,8 +344,8 @@ int BufferView::Pimpl::resizeCurrentBuffer() mark_set = bv_->text->selection.mark(); the_locking_inset = bv_->theLockingInset(); buffer_->resizeInsets(bv_); - // I don't think the delete and new are necessary here we just could - // call only init! (Jug 20020419) + // I don't think the delete and new are necessary here we + // just could call only init! (Jug 20020419) delete bv_->text; bv_->text = new LyXText(bv_); bv_->text->init(bv_); @@ -641,10 +699,15 @@ void BufferView::Pimpl::restorePosition(unsigned int i) beforeChange(bv_->text); if (fname != buffer_->fileName()) { - Buffer * b = bufferlist.exists(fname) ? - bufferlist.getBuffer(fname) : - bufferlist.loadLyXFile(fname); // don't ask, just load it - if (b != 0) buffer(b); + Buffer * b; + if (bufferlist.exists(fname)) + b = bufferlist.getBuffer(fname); + else { + b = bufferlist.newBuffer(fname); + ::loadLyXFile(b, fname); // don't ask, just load it + } + if (b != 0) + buffer(b); } ParIterator par = buffer_->getParFromID(saved_positions[i].par_id); diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 5f4baf4f63..7dea067f93 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -54,6 +54,9 @@ struct BufferView::Pimpl : public boost::signals::trackable { * Repaint pixmap. Used for when we've made a visible * change but don't need the full update() logic */ + /// + bool loadLyXFile(string const &, bool); + /// void repaint(); /// void workAreaResize(); diff --git a/src/ChangeLog b/src/ChangeLog index f1215d608e..5abfb2681c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ + +2003-06-19 Alfredo Braunstein + + * bufferlist.[Ch] (loadLyXFile, readFile, newFile): removed the + ability to create a buffer and to return an existing one from + the list. Moved these functions to... + * buffer_funcs.[Ch]: added + * BufferView.[Ch] (loadLyXFile): added + * BufferView_pimpl.[Ch] (loadLyXFile): Added. Does the guessing + job removed from bufferlist::loadLyXFile. + * buffer.C (setReadOnly): make it work without view + (i.e added an if (users)) + 2003-06-19 Angus Leeming * lfuns.h: diff --git a/src/Makefile.am b/src/Makefile.am index 5d775d0342..cdafd15d4c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -105,6 +105,8 @@ lyx_SOURCES = \ broken_headers.h \ buffer.C \ buffer.h \ + buffer_funcs.C \ + buffer_funcs.h \ bufferlist.C \ bufferlist.h \ bufferparams.C \ diff --git a/src/buffer.C b/src/buffer.C index 04e7e1ef14..808f3149b2 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -206,7 +206,8 @@ void Buffer::setReadonly(bool flag) if (read_only != flag) { read_only = flag; updateTitles(); - users->owner()->getDialogs().updateBufferDependent(false); + if (users) + users->owner()->getDialogs().updateBufferDependent(false); } } diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C new file mode 100644 index 0000000000..3590c774fb --- /dev/null +++ b/src/buffer_funcs.C @@ -0,0 +1,196 @@ +/** + * \file buffer_funcs.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Lars Gullik Bjønnes + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS + * + */ + +#include + +#include "buffer_funcs.h" +#include "bufferlist.h" +#include "buffer.h" +#include "gettext.h" +#include "vc-backend.h" +#include "lyxlex.h" +#include "ParagraphList.h" +#include "paragraph.h" + +#include "frontends/Alert.h" + +#include "support/filetools.h" +#include "support/FileInfo.h" +#include "support/lyxlib.h" + + +extern BufferList bufferlist; + + +namespace { + +bool readFile(Buffer * b, string const & s) +{ + string ts(s); + string e = OnlyPath(s); + string a = e; + // File information about normal file + FileInfo fileInfo(s); + + if (!fileInfo.exist()) { + string const file = MakeDisplayPath(s, 50); + string text = bformat(_("The specified document\n%1$s" + "\ncould not be read."), file); + Alert::error(_("Could not read document"), text); + return false; + } + + // Check if emergency save file exists and is newer. + e += OnlyFilename(s) + ".emergency"; + FileInfo fileInfoE(e); + + bool use_emergency = false; + + if (fileInfoE.exist() && fileInfo.exist()) { + if (fileInfoE.getModificationTime() + > fileInfo.getModificationTime()) { + string const file = MakeDisplayPath(s, 20); + string text = bformat(_("An emergency save of the document %1$s exists.\n" + "\nRecover emergency save?"), file); + int const ret = Alert::prompt(_("Load emergency save?"), + text, 0, 1, _("&Recover"), _("&Load Original")); + + if (ret == 0) { + ts = e; + // the file is not saved if we load the + // emergency file. + b->markDirty(); + use_emergency = true; + } + } + } + + if (!use_emergency) { + // Now check if autosave file is newer. + a += '#'; + a += OnlyFilename(s); + a += '#'; + FileInfo fileInfoA(a); + if (fileInfoA.exist() && fileInfo.exist()) { + if (fileInfoA.getModificationTime() + > fileInfo.getModificationTime()) { + string const file = MakeDisplayPath(s, 20); + string text = bformat(_("The backup of the document %1$s is newer.\n\n" + "Load the backup instead?"), file); + int const ret = Alert::prompt(_("Load backup?"), + text, 0, 1, _("&Load backup"), _("Load &original")); + + if (ret == 0) { + ts = a; + // the file is not saved if we load the + // autosave file. + b->markDirty(); + } else { + // Here, we should delete the autosave + lyx::unlink(a); + } + } + } + } + // not sure if this is the correct place to begin LyXLex + LyXLex lex(0, 0); + lex.setFile(ts); + + return b->readFile(lex, ts); +} + + +} // namespace anon + + + +bool loadLyXFile(Buffer * b, string const & s) +{ + switch (IsFileWriteable(s)) { + case 0: + b->setReadonly(true); + // Fall through + case 1: + if (readFile(b, s)) { + b->lyxvc.file_found_hook(s); + return true; + } + break; + case -1: + string const file = MakeDisplayPath(s, 20); + // Here we probably should run + if (LyXVC::file_not_found_hook(s)) { + string text = bformat(_("Do you want to retrieve the document" + " %1$s from version control?"), file); + int const ret = Alert::prompt(_("Retrieve from version control?"), + text, 0, 1, _("&Retrieve"), _("&Cancel")); + + if (ret == 0) { + // How can we know _how_ to do the checkout? + // With the current VC support it has to be, + // a RCS file since CVS do not have special ,v files. + RCS::retrieve(s); + return loadLyXFile(b, s); + } + } + break; + } + return false; +} + + +Buffer * newFile(string const & filename, string const & templatename, + bool isNamed) +{ + // get a free buffer + Buffer * b = bufferlist.newBuffer(filename); + + string tname; + // use defaults.lyx as a default template if it exists. + if (templatename.empty()) + tname = LibFileSearch("templates", "defaults.lyx"); + else + tname = templatename; + + if (!tname.empty()) { + bool templateok = false; + LyXLex lex(0, 0); + lex.setFile(tname); + if (lex.isOK()) { + if (b->readFile(lex, tname)) { + templateok = true; + } + } + if (!templateok) { + string const file = MakeDisplayPath(tname, 50); + string text = bformat(_("The specified document template\n%1$s\n" + "could not be read."), file); + Alert::error(_("Could not read template"), text); + // no template, start with empty buffer + b->paragraphs.push_back(Paragraph()); + b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout()); + } + } else { // start with empty buffer + b->paragraphs.push_back(Paragraph()); + b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout()); + } + + if (!isNamed) { + b->setUnnamed(); + b->setFileName(filename); + } + + b->setReadonly(false); + b->updateDocLang(b->params.language); + + return b; +} diff --git a/src/buffer_funcs.h b/src/buffer_funcs.h new file mode 100644 index 0000000000..dc6a440b76 --- /dev/null +++ b/src/buffer_funcs.h @@ -0,0 +1,26 @@ +// -*- C++ -*- +/* \file buffer_funcs.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Lars Gullik Bjønnes + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS + */ + +#include "LString.h" + +class Buffer; + +/** + * Loads a LyX file \c filename into \c Buffer + * and \return success status. + */ +bool loadLyXFile(Buffer *, string const & filename); + +/* Make a new file (buffer) with name \c filename based on a template + * named \c templatename + */ +Buffer * newFile(string const & filename, string const & templatename, + bool isNamed = false); diff --git a/src/bufferlist.C b/src/bufferlist.C index a0c6cf31a2..7d7b327b4e 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -306,89 +306,6 @@ void BufferList::emergencyWrite(Buffer * buf) } - -Buffer * BufferList::readFile(string const & s, bool ronly) -{ - string ts(s); - string e = OnlyPath(s); - string a = e; - // File information about normal file - FileInfo fileInfo2(s); - - if (!fileInfo2.exist()) { - string const file = MakeDisplayPath(s, 50); - string text = bformat(_("The specified document\n%1$s" - "\ncould not be read."), file); - Alert::error(_("Could not read document"), text); - return 0; - } - - Buffer * b = newBuffer(s, ronly); - - // Check if emergency save file exists and is newer. - e += OnlyFilename(s) + ".emergency"; - FileInfo fileInfoE(e); - - bool use_emergency = false; - - if (fileInfoE.exist() && fileInfo2.exist()) { - if (fileInfoE.getModificationTime() - > fileInfo2.getModificationTime()) { - string const file = MakeDisplayPath(s, 20); - string text = bformat(_("An emergency save of the document %1$s exists.\n" - "\nRecover emergency save?"), file); - int const ret = Alert::prompt(_("Load emergency save?"), - text, 0, 1, _("&Recover"), _("&Load Original")); - - if (ret == 0) { - ts = e; - // the file is not saved if we load the - // emergency file. - b->markDirty(); - use_emergency = true; - } - } - } - - if (!use_emergency) { - // Now check if autosave file is newer. - a += '#'; - a += OnlyFilename(s); - a += '#'; - FileInfo fileInfoA(a); - if (fileInfoA.exist() && fileInfo2.exist()) { - if (fileInfoA.getModificationTime() - > fileInfo2.getModificationTime()) { - string const file = MakeDisplayPath(s, 20); - string text = bformat(_("The backup of the document %1$s is newer.\n\n" - "Load the backup instead?"), file); - int const ret = Alert::prompt(_("Load backup?"), - text, 0, 1, _("&Load backup"), _("Load &original")); - - if (ret == 0) { - ts = a; - // the file is not saved if we load the - // autosave file. - b->markDirty(); - } else { - // Here, we should delete the autosave - lyx::unlink(a); - } - } - } - } - // not sure if this is the correct place to begin LyXLex - LyXLex lex(0, 0); - lex.setFile(ts); - if (b->readFile(lex, ts)) - return b; - else { - release(b); - return 0; - } -} - - bool BufferList::exists(string const & s) const { return find_if(bstore.begin(), bstore.end(), @@ -416,129 +333,6 @@ Buffer * BufferList::getBuffer(string const & s) } -Buffer * BufferList::newFile(string const & name, string tname, bool isNamed) -{ - // get a free buffer - Buffer * b = newBuffer(name); - - // use defaults.lyx as a default template if it exists. - if (tname.empty()) { - tname = LibFileSearch("templates", "defaults.lyx"); - } - if (!tname.empty()) { - bool templateok = false; - LyXLex lex(0, 0); - lex.setFile(tname); - if (lex.isOK()) { - if (b->readFile(lex, tname)) { - templateok = true; - } - } - if (!templateok) { - string const file = MakeDisplayPath(tname, 50); - string text = bformat(_("The specified document template\n%1$s\n" - "could not be read."), file); - Alert::error(_("Could not read template"), text); - // no template, start with empty buffer - b->paragraphs.push_back(Paragraph()); - b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout()); - } - } else { // start with empty buffer - b->paragraphs.push_back(Paragraph()); - b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout()); - } - - if (!isNamed) { - b->setUnnamed(); - b->setFileName(name); - } - - b->setReadonly(false); - b->updateDocLang(b->params.language); - - return b; -} - - -Buffer * BufferList::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()) { - s = filename; - } - - // file already open? - if (exists(s)) { - string const file = MakeDisplayPath(s, 20); - string text = bformat(_("The document %1$s is already loaded.\n\n" - "Do you want to revert to the saved version?"), file); - int const ret = Alert::prompt(_("Revert to saved document?"), - text, 0, 1, _("&Revert"), _("&Switch to document")); - - if (ret == 0) { - // FIXME: should be LFUN_REVERT - if (!close(getBuffer(s), false)) { - return 0; - } - // Fall through to new load. (Asger) - } else { - // Here, we pretend that we just loaded the - // open document - return getBuffer(s); - } - } - - Buffer * b = 0; - bool ro = false; - switch (IsFileWriteable(s)) { - case 0: - ro = true; - // Fall through - case 1: - b = readFile(s, ro); - if (b) { - b->lyxvc.file_found_hook(s); - } - break; //fine- it's r/w - case -1: { - string const file = MakeDisplayPath(s, 20); - // Here we probably should run - if (LyXVC::file_not_found_hook(s)) { - string text = bformat(_("Do you want to retrieve the document" - " %1$s from version control?"), file); - int const ret = Alert::prompt(_("Retrieve from version control?"), - text, 0, 1, _("&Retrieve"), _("&Cancel")); - - if (ret == 0) { - // How can we know _how_ to do the checkout? - // With the current VC support it has to be, - // a RCS file since CVS do not have special ,v files. - RCS::retrieve(s); - return loadLyXFile(filename, tolastfiles); - } - } - - string text = bformat(_("The document %1$s does not yet exist.\n\n" - "Do you want to create a new document?"), file); - int const ret = Alert::prompt(_("Create new document?"), - text, 0, 1, _("&Create"), _("Cancel")); - - if (ret == 0) - b = newFile(s, string(), true); - - break; - } - } - - if (b && tolastfiles) - lastfiles->newFile(b->fileName()); - - return b; -} - - void BufferList::setCurrentAuthor(string const & name, string const & email) { BufferStorage::iterator it = bstore.begin(); diff --git a/src/bufferlist.h b/src/bufferlist.h index 5ba7e6ffc5..a9f8768c1d 100644 --- a/src/bufferlist.h +++ b/src/bufferlist.h @@ -29,17 +29,6 @@ class BufferList : boost::noncopyable { public: BufferList(); - /** - Loads a LyX file or... - - \param filename The filename to read from. - \param tolastfiles Wether the file should be put in the - last opened files list or not. - \return The newly loaded LyX file. - */ - Buffer * loadLyXFile(string const & filename, - bool tolastfiles = true); - /// write all buffers, asking the user, returns false if cancelled bool quitWriteAll(); @@ -52,11 +41,6 @@ public: /// Close all open buffers. void closeAll(); - /// read the given file - Buffer * readFile(string const &, bool ro); - - /// Make a new file (buffer) using a template - Buffer * newFile(string const &, string, bool isNamed = false); /// returns a vector with all the buffers filenames std::vector const getFileNames() const; diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 0efc0c12f9..9b047d62b7 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,9 @@ + +2003-06-19 Alfredo Braunstein + + * lyx_gui.C (start): call ::loadLyXFile instead + of BufferList::loadLyXFile + 2003-06-19 Angus Leeming * Dialogs.C: diff --git a/src/frontends/qt2/lyx_gui.C b/src/frontends/qt2/lyx_gui.C index 38657a00b2..08413432c0 100644 --- a/src/frontends/qt2/lyx_gui.C +++ b/src/frontends/qt2/lyx_gui.C @@ -28,6 +28,7 @@ // FIXME: move this stuff out again #include "bufferlist.h" +#include "buffer_funcs.h" #include "lyxfunc.h" #include "lyxserver.h" #include "BufferView.h" @@ -153,10 +154,9 @@ void start(string const & batch, vector const & files) vector::const_iterator cit = files.begin(); vector::const_iterator end = files.end(); for (; cit != end; ++cit) { - Buffer * b = bufferlist.loadLyXFile(*cit); - if (b) { + Buffer * b = bufferlist.newBuffer(*cit); + if (loadLyXFile(b, *cit)) last = b; - } } // switch to the last buffer successfully loaded diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 01d1e4cbb0..5744d42a83 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2003-06-19 Alfredo Braunstein + + * lyx_gui.C (start): call ::loadLyXFile instead + of BufferList::loadLyXFile + 2003-06-19 Angus Leeming * Dialogs.C: diff --git a/src/frontends/xforms/lyx_gui.C b/src/frontends/xforms/lyx_gui.C index cb3849f539..ccf772656d 100644 --- a/src/frontends/xforms/lyx_gui.C +++ b/src/frontends/xforms/lyx_gui.C @@ -27,6 +27,7 @@ // FIXME: move this stuff out again #include "bufferlist.h" +#include "buffer_funcs.h" #include "lyxfunc.h" #include "lyxserver.h" #include "BufferView.h" @@ -285,10 +286,9 @@ void start(string const & batch, vector const & files) vector::const_iterator cit = files.begin(); vector::const_iterator end = files.end(); for (; cit != end; ++cit) { - Buffer * b = bufferlist.loadLyXFile(*cit); - if (b) { + Buffer * b = bufferlist.newBuffer(*cit); + if (loadLyXFile(b, *cit)) last = b; - } } // switch to the last buffer successfully loaded diff --git a/src/importer.C b/src/importer.C index d79ed4be5f..d5b6a60f02 100644 --- a/src/importer.C +++ b/src/importer.C @@ -18,6 +18,7 @@ #include "funcrequest.h" #include "bufferlist.h" +#include "buffer_funcs.h" #include "support/filetools.h" #include "frontends/Alert.h" #include "gettext.h" @@ -65,11 +66,9 @@ bool Importer::Import(LyXView * lv, string const & filename, if (loader_format == "lyx") { - Buffer * buffer = bufferlist.loadLyXFile(lyxfile); - if (buffer) - lv->view()->buffer(buffer); + lv->view()->loadLyXFile(lyxfile); } else { - lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true)); + lv->view()->buffer(newFile(lyxfile, string(), true)); bool as_paragraphs = loader_format == "textparagraph"; string filename2 = (loader_format == format) ? filename : ChangeExtension(filename, diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index d9333fd0dc..ce91287b07 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2003-06-19 Alfredo Braunstein + + * insetinclude.C (loadIfNeeded): call ::loadLyXFile instead + of BufferList::loadLyXFile + 2003-06-18 Lars Gullik Bjønnes * insettext.C (update): simplify diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 4a1a773ade..774f333439 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -12,6 +12,7 @@ #include "insetinclude.h" #include "buffer.h" +#include "buffer_funcs.h" #include "bufferlist.h" #include "BufferView.h" #include "debug.h" @@ -293,8 +294,8 @@ bool InsetInclude::loadIfNeeded() const FileInfo finfo(getFileName()); if (!finfo.isOK()) return false; - - return bufferlist.loadLyXFile(getFileName(), false) != 0; + return loadLyXFile(bufferlist.newBuffer(getFileName()), + getFileName()); } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 08dc527a06..5348675679 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -13,6 +13,7 @@ #include "lyx_cb.h" #include "lyx_main.h" #include "buffer.h" +#include "buffer_funcs.h" #include "bufferlist.h" #include "bufferview_funcs.h" #include "debug.h" @@ -326,7 +327,7 @@ Buffer * NewFile(string const & filename) << "\nTemplate is " << tmpname << endl; // find a free buffer - Buffer * tmpbuf = bufferlist.newFile(name, tmpname); + Buffer * tmpbuf = newFile(name, tmpname); if (tmpbuf) lastfiles->newFile(tmpbuf->fileName()); return tmpbuf; diff --git a/src/lyx_main.C b/src/lyx_main.C index f323a19069..ad0165acc2 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -24,6 +24,7 @@ #include "bufferlist.h" #include "buffer.h" +#include "buffer_funcs.h" #include "lyxserver.h" #include "kbmap.h" #include "lyxfunc.h" @@ -142,14 +143,16 @@ LyX::LyX(int & argc, char * argv[]) vector::iterator it = files.begin(); vector::iterator end = files.end(); for (; it != end; ++it) { - last_loaded = bufferlist.loadLyXFile(*it); + last_loaded = bufferlist.newBuffer(*it, false); + loadLyXFile(last_loaded, *it); } files.clear(); // no buffer loaded, create one + string const tmpfile = "tmpfile"; if (!last_loaded) - last_loaded = bufferlist.newFile("tmpfile", string()); + last_loaded = newFile(tmpfile, string()); bool success = false; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index f155dd9ad9..576d918963 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -16,6 +16,7 @@ #include "lyxrow.h" #include "bufferlist.h" #include "buffer.h" +#include "buffer_funcs.h" #include "BufferView.h" #include "lyxserver.h" #include "intl.h" @@ -1195,7 +1196,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) } owner->message(bformat(_("Opening help file %1$s..."), MakeDisplayPath(fname))); - view()->buffer(bufferlist.loadLyXFile(fname, false)); + view()->loadLyXFile(fname, false); break; } @@ -1307,7 +1308,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) if (bufferlist.exists(s)) { view()->buffer(bufferlist.getBuffer(s)); } else { - view()->buffer(bufferlist.loadLyXFile(s)); + view()->loadLyXFile(s); } view()->setCursorFromRow(row); @@ -1455,7 +1456,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) if (bufferlist.exists(filename)) view()->buffer(bufferlist.getBuffer(filename)); else - view()->buffer(bufferlist.loadLyXFile(filename)); + view()->loadLyXFile(filename); } break; @@ -1714,7 +1715,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate) templname = fname; } - view()->buffer(bufferlist.newFile(filename, templname, !name.empty())); + view()->buffer(newFile(filename, templname, !name.empty())); } @@ -1769,17 +1770,15 @@ void LyXFunc::open(string const & fname) FileInfo const f(filename, true); if (!f.exist()) { // the user specifically chose this name. Believe them. - Buffer * buffer = bufferlist.newFile(filename, "", true); + Buffer * buffer = newFile(filename, "", true); view()->buffer(buffer); return; } owner->message(bformat(_("Opening document %1$s..."), disp_fn)); - Buffer * openbuf = bufferlist.loadLyXFile(filename); string str2; - if (openbuf) { - view()->buffer(openbuf); + if (view()->loadLyXFile(filename)) { str2 = bformat(_("Document %1$s opened."), disp_fn); } else { str2 = bformat(_("Could not open document %1$s"), disp_fn);