As the title says and as agreed yesterday. Will commit later today if there no comment.
Abdel.
Index: buffer.C =================================================================== --- buffer.C (revision 15153) +++ buffer.C (working copy) @@ -15,7 +15,6 @@ #include "author.h" #include "BranchList.h" #include "buffer_funcs.h" -#include "bufferlist.h" #include "bufferparams.h" #include "counters.h" #include "Bullet.h" @@ -60,6 +59,7 @@ #include "mathed/MathSupport.h" #include "frontends/Alert.h" +#include "frontends/Application.h" #include "graphics/Previews.h" @@ -141,9 +141,6 @@ using std::string; -// all these externs should eventually be removed. -extern BufferList bufferlist; - namespace { int const LYX_FORMAT = 249; @@ -1480,12 +1477,13 @@ params().parentname = name; } - +// FIXME getMasterBuffer() has no business here! +// should be transfered to BufferList. Buffer const * Buffer::getMasterBuffer() const { if (!params().parentname.empty() - && bufferlist.exists(params().parentname)) { - Buffer const * buf = bufferlist.getBuffer(params().parentname); + && theApp->bufferList().exists(params().parentname)) { + Buffer const * buf = theApp->bufferList().getBuffer(params().parentname); if (buf) return buf->getMasterBuffer(); } @@ -1494,11 +1492,13 @@ } +// FIXME getMasterBuffer() has no business here! +// should be transfered to BufferList. Buffer * Buffer::getMasterBuffer() { if (!params().parentname.empty() - && bufferlist.exists(params().parentname)) { - Buffer * buf = bufferlist.getBuffer(params().parentname); + && theApp->bufferList().exists(params().parentname)) { + Buffer * buf = theApp->bufferList().getBuffer(params().parentname); if (buf) return buf->getMasterBuffer(); } Index: buffer_funcs.C =================================================================== --- buffer_funcs.C (revision 15153) +++ buffer_funcs.C (working copy) @@ -14,7 +14,6 @@ #include "buffer_funcs.h" #include "buffer.h" -#include "bufferlist.h" #include "bufferparams.h" #include "dociterator.h" #include "counters.h" @@ -36,6 +35,7 @@ #include "toc.h" #include "frontends/Alert.h" +#include "frontends/Application.h" #include "insets/insetbibitem.h" @@ -64,8 +64,6 @@ namespace fs = boost::filesystem; -extern BufferList bufferlist; - namespace { bool readFile(Buffer * const b, string const & s) @@ -175,12 +173,12 @@ return false; } - +// FIXME newFile() should be a member method of Application or BufferList? Buffer * newFile(string const & filename, string const & templatename, bool const isNamed) { // get a free buffer - Buffer * b = bufferlist.newBuffer(filename); + Buffer * b = theApp->bufferList().newBuffer(filename); BOOST_ASSERT(b); string tname; @@ -197,7 +195,7 @@ _("The specified document template\n%1$s\ncould not be read."), file); Alert::error(_("Could not read template"), text); - bufferlist.release(b); + theApp->bufferList().release(b); return 0; } } Index: BufferView.C =================================================================== --- BufferView.C (revision 15153) +++ BufferView.C (working copy) @@ -18,7 +18,6 @@ #include "buffer.h" #include "buffer_funcs.h" -#include "bufferlist.h" #include "bufferparams.h" #include "coordcache.h" #include "CutAndPaste.h" @@ -60,6 +59,7 @@ #include "insets/insettext.h" #include "frontends/Alert.h" +#include "frontends/Application.h" #include "frontends/FileDialog.h" #include "frontends/font_metrics.h" @@ -101,9 +101,7 @@ using std::string; using std::vector; -extern BufferList bufferlist; - namespace { unsigned int const saved_positions_num = 20; @@ -186,7 +184,7 @@ lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION << " No Buffer!" << endl; // We are closing the buffer, use the first buffer as current - buffer_ = bufferlist.first(); + buffer_ = theApp->bufferList().first(); } else { // Set current buffer buffer_ = b; @@ -233,7 +231,7 @@ s = filename; // File already open? - if (bufferlist.exists(s)) { + if (theApp->bufferList().exists(s)) { docstring const file = makeDisplayPath(s, 20); docstring text = bformat(_("The document %1$s is already " "loaded.\n\nDo you want to revert " @@ -242,11 +240,11 @@ text, 0, 1, _("&Revert"), _("&Switch to document")); if (ret != 0) { - setBuffer(bufferlist.getBuffer(s)); + setBuffer(theApp->bufferList().getBuffer(s)); return true; } // FIXME: should be LFUN_REVERT - if (!bufferlist.close(bufferlist.getBuffer(s), false)) + if (!theApp->bufferList().close(theApp->bufferList().getBuffer(s), false)) return false; // Fall through to new load. (Asger) } @@ -254,9 +252,9 @@ Buffer * b = 0; if (found) { - b = bufferlist.newBuffer(s); + b = theApp->bufferList().newBuffer(s); if (!::loadLyXFile(b, s)) { - bufferlist.release(b); + theApp->bufferList().release(b); return false; } } else { @@ -310,7 +308,7 @@ void BufferView::reload() { string const fn = buffer_->fileName(); - if (bufferlist.close(buffer_, false)) + if (theApp->bufferList().close(buffer_, false)) loadLyXFile(fn); } @@ -535,10 +533,10 @@ if (fname != buffer_->fileName()) { Buffer * b = 0; - if (bufferlist.exists(fname)) - b = bufferlist.getBuffer(fname); + if (theApp->bufferList().exists(fname)) + b = theApp->bufferList().getBuffer(fname); else { - b = bufferlist.newBuffer(fname); + b = theApp->bufferList().newBuffer(fname); // Don't ask, just load it ::loadLyXFile(b, fname); } Index: frontends/Application.C =================================================================== --- frontends/Application.C (revision 15153) +++ frontends/Application.C (working copy) @@ -70,6 +70,18 @@ } +BufferList & Application::bufferList() +{ + return buffer_list_; +} + + +BufferList const & Application::bufferList() const +{ + return buffer_list_; +} + + void Application::setBufferView(BufferView * buffer_view) { buffer_view_ = buffer_view; Index: frontends/Application.h =================================================================== --- frontends/Application.h (revision 15153) +++ frontends/Application.h (working copy) @@ -11,6 +11,7 @@ #ifndef LYX_APPLICATION_H #define LYX_APPLICATION_H +#include "bufferlist.h" #include "lyxfunc.h" #include "lyxserver.h" #include "lyxsocket.h" @@ -69,6 +70,9 @@ LyXServerSocket & socket(); LyXServerSocket const & socket() const; /// + BufferList & bufferList(); + BufferList const & bufferList() const; + void setBufferView(BufferView * buffer_view); protected: @@ -86,6 +90,8 @@ boost::scoped_ptr<LyXServer> lyx_server_; /// boost::scoped_ptr<LyXServerSocket> lyx_socket_; + /// + BufferList buffer_list_; }; // Application Index: frontends/controllers/ControlPrefs.C =================================================================== --- frontends/controllers/ControlPrefs.C (revision 15153) +++ frontends/controllers/ControlPrefs.C (working copy) @@ -15,12 +15,13 @@ #include "helper_funcs.h" #include "Kernel.h" -#include "bufferlist.h" #include "gettext.h" #include "funcrequest.h" #include "paper.h" #include "LColor.h" +#include "frontends/Application.h" + #include "support/filefilterlist.h" #include <sstream> @@ -31,8 +32,6 @@ using std::vector; -extern BufferList bufferlist; - namespace lyx { using support::FileFilterList; @@ -67,7 +66,7 @@ kernel().dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str())); // FIXME: these need lfuns - bufferlist.setCurrentAuthor(rc_.user_name, rc_.user_email); + theApp->bufferList().setCurrentAuthor(rc_.user_name, rc_.user_email); ::formats = formats_; Index: frontends/controllers/ControlRef.C =================================================================== --- frontends/controllers/ControlRef.C (revision 15153) +++ frontends/controllers/ControlRef.C (working copy) @@ -13,17 +13,15 @@ #include "ControlRef.h" #include "buffer.h" -#include "bufferlist.h" #include "funcrequest.h" +#include "frontends/Application.h" + #include "support/filetools.h" // MakeAbsPath, MakeDisplayPath using std::vector; using std::string; - -extern BufferList bufferlist; - namespace lyx { using support::makeAbsPath; @@ -38,7 +36,7 @@ vector<string> const ControlRef::getLabelList(string const & name) const { - Buffer const & buf = *bufferlist.getBuffer(makeAbsPath(name)); + Buffer const & buf = *theApp->bufferList().getBuffer(makeAbsPath(name)); vector<string> list; buf.getLabelList(list); return list; @@ -60,7 +58,7 @@ vector<string> const ControlRef::getBufferList() const { - vector<string> buffers = bufferlist.getFileNames(); + vector<string> buffers = theApp->bufferList().getFileNames(); for (vector<string>::iterator it = buffers.begin(); it != buffers.end(); ++it) { *it = lyx::to_utf8(makeDisplayPath(*it)); @@ -72,7 +70,7 @@ int ControlRef::getBufferNum() const { - vector<string> buffers = bufferlist.getFileNames(); + vector<string> buffers = theApp->bufferList().getFileNames(); string const name = kernel().buffer().fileName(); vector<string>::const_iterator cit = find(buffers.begin(), buffers.end(), name); @@ -83,7 +81,7 @@ string const ControlRef::getBufferName(int num) const { - return bufferlist.getFileNames()[num]; + return theApp->bufferList().getFileNames()[num]; } } // namespace frontend Index: frontends/qt4/lyx_gui.C =================================================================== --- frontends/qt4/lyx_gui.C (revision 15159) +++ frontends/qt4/lyx_gui.C (working copy) @@ -15,7 +15,6 @@ #include "lyx_gui.h" // FIXME: move this stuff out again -#include "bufferlist.h" #include "Color.h" #include "funcrequest.h" #include "LColor.h" Index: importer.C =================================================================== --- importer.C (revision 15153) +++ importer.C (working copy) @@ -19,9 +19,10 @@ #include "funcrequest.h" #include "lyx_cb.h" -#include "bufferlist.h" #include "support/filetools.h" + #include "frontends/Alert.h" + #include "gettext.h" #include "BufferView.h" #include "buffer_funcs.h" @@ -36,9 +37,6 @@ using std::vector; -extern BufferList bufferlist; - - bool Importer::Import(LyXView * lv, string const & filename, string const & format, ErrorList & errorList) { Index: insets/insetinclude.C =================================================================== --- insets/insetinclude.C (revision 15153) +++ insets/insetinclude.C (working copy) @@ -14,7 +14,6 @@ #include "buffer.h" #include "buffer_funcs.h" -#include "bufferlist.h" #include "bufferparams.h" #include "BufferView.h" #include "cursor.h" @@ -32,6 +31,7 @@ #include "outputparams.h" #include "frontends/Alert.h" +#include "frontends/Application.h" #include "frontends/Painter.h" #include "graphics/PreviewImage.h" @@ -82,9 +82,7 @@ namespace fs = boost::filesystem; -extern BufferList bufferlist; - namespace { string const uniqueID() @@ -319,7 +317,7 @@ if (!isLyXFilename(included_file)) return 0; - return bufferlist.getBuffer(included_file); + return theApp->bufferList().getBuffer(included_file); } @@ -333,12 +331,12 @@ if (!isLyXFilename(included_file)) return false; - Buffer * buf = bufferlist.getBuffer(included_file); + Buffer * buf = theApp->bufferList().getBuffer(included_file); if (!buf) { // the readonly flag can/will be wrong, not anymore I think. if (!fs::exists(included_file)) return false; - buf = bufferlist.newBuffer(included_file); + buf = theApp->bufferList().newBuffer(included_file); if (!loadLyXFile(buf, included_file)) return false; } @@ -386,7 +384,7 @@ // Don't try to load or copy the file ; else if (loadIfNeeded(buffer, params_)) { - Buffer * tmp = bufferlist.getBuffer(included_file); + Buffer * tmp = theApp->bufferList().getBuffer(included_file); if (tmp->params().textclass != m_buffer->params().textclass) { // FIXME UNICODE @@ -499,7 +497,7 @@ string writefile = changeExtension(included_file, ".sgml"); if (loadIfNeeded(buffer, params_)) { - Buffer * tmp = bufferlist.getBuffer(included_file); + Buffer * tmp = theApp->bufferList().getBuffer(included_file); string const mangled = FileName(writefile).mangledFilename(); writefile = makeAbsPath(mangled, @@ -560,7 +558,7 @@ // to be loaded: if (loadIfNeeded(buffer, params_)) { // a file got loaded - Buffer * const tmp = bufferlist.getBuffer(included_file); + Buffer * const tmp = theApp->bufferList().getBuffer(included_file); if (tmp) { // We must temporarily change features.buffer, // otherwise it would always be the master buffer, @@ -578,7 +576,7 @@ { if (loadIfNeeded(buffer, params_)) { string const included_file = includedFilename(buffer, params_); - Buffer * tmp = bufferlist.getBuffer(included_file); + Buffer * tmp = theApp->bufferList().getBuffer(included_file); tmp->setParentName(""); tmp->getLabelList(list); tmp->setParentName(parentFilename(buffer)); @@ -591,7 +589,7 @@ { if (loadIfNeeded(buffer, params_)) { string const included_file = includedFilename(buffer, params_); - Buffer * tmp = bufferlist.getBuffer(included_file); + Buffer * tmp = theApp->bufferList().getBuffer(included_file); tmp->setParentName(""); tmp->fillWithBibKeys(keys); tmp->setParentName(parentFilename(buffer)); Index: LaTeX.C =================================================================== --- LaTeX.C (revision 15153) +++ LaTeX.C (working copy) @@ -15,11 +15,13 @@ #include <config.h> #include "LaTeX.h" -#include "bufferlist.h" #include "gettext.h" #include "lyxrc.h" #include "debug.h" #include "DepTable.h" + +#include "frontends/Application.h" + #include "support/filetools.h" #include "support/convert.h" #include "support/lstrings.h" @@ -70,7 +72,7 @@ using std::vector; // TODO: in no particular order -// - get rid of the extern BufferList and the call to +// - get rid of the call to // BufferList::updateIncludedTeXfiles, this should either // be done before calling LaTeX::funcs or in a completely // different way. @@ -80,8 +82,6 @@ // - somewhere support viewing of bibtex and makeindex log files. // - we should perhaps also scan the bibtex log file -extern BufferList bufferlist; - namespace { docstring runMessage(unsigned int count) @@ -179,7 +179,7 @@ bool rerun = false; // rerun requested // The class LaTeX does not know the temp path. - bufferlist.updateIncludedTeXfiles(getcwd(), runparams); + theApp->bufferList().updateIncludedTeXfiles(getcwd(), runparams); // Never write the depfile if an error was encountered. Index: lyx_cb.C =================================================================== --- lyx_cb.C (revision 15153) +++ lyx_cb.C (working copy) @@ -17,7 +17,6 @@ #include "lyx_cb.h" #include "buffer.h" -#include "bufferlist.h" #include "BufferView.h" #include "buffer_funcs.h" #include "cursor.h" @@ -32,6 +31,7 @@ #include "paragraph.h" #include "frontends/Alert.h" +#include "frontends/Application.h" #include "frontends/FileDialog.h" #include "frontends/lyx_gui.h" @@ -88,7 +88,6 @@ using std::istream_iterator; -extern BufferList bufferlist; // this should be static, but I need it in buffer.C bool quitting; // flag, that we are quitting the program @@ -192,7 +191,7 @@ lyxerr[Debug::INFO] << "Running QuitLyX." << endl; if (lyx_gui::use_gui) { - if (!noask && !bufferlist.quitWriteAll()) + if (!noask && !theApp->bufferList().quitWriteAll()) return; LyX::cref().session().writeFile(); @@ -203,7 +202,7 @@ quitting = true; // close buffers first - bufferlist.closeAll(); + theApp->bufferList().closeAll(); // do any other cleanup procedures now lyxerr[Debug::INFO] << "Deleting tmp dir " << package().temp_dir() << endl; Index: lyx_main.C =================================================================== --- lyx_main.C (revision 15153) +++ lyx_main.C (working copy) @@ -19,7 +19,6 @@ #include "buffer.h" #include "buffer_funcs.h" -#include "bufferlist.h" #include "converter.h" #include "debug.h" #include "encoding.h" @@ -89,9 +88,6 @@ #endif -// This is the global bufferlist object -BufferList bufferlist; - // convenient to have it here. boost::scoped_ptr<kb_keymap> toplevel_keymap; @@ -275,7 +271,7 @@ if (b) last_loaded = b; } else { - Buffer * buf = bufferlist.newBuffer(s, false); + Buffer * buf = theApp->bufferList().newBuffer(s, false); if (loadLyXFile(buf, s)) { last_loaded = buf; ErrorList const & el = buf->errorList("Parse"); @@ -284,7 +280,7 @@ boost::bind(&LyX::printError, this, _1)); } else - bufferlist.release(buf); + theApp->bufferList().release(buf); } } @@ -658,7 +654,7 @@ // contain documents etc. which might be helpful on // a crash - bufferlist.emergencyWriteAll(); + theApp->bufferList().emergencyWriteAll(); theApp->server().emergencyCleanup(); } Index: lyxfunc.C =================================================================== --- lyxfunc.C (revision 15153) +++ lyxfunc.C (working copy) @@ -24,7 +24,6 @@ #include "BranchList.h" #include "buffer.h" #include "buffer_funcs.h" -#include "bufferlist.h" #include "bufferparams.h" #include "BufferView.h" #include "cursor.h" @@ -138,8 +137,6 @@ namespace fs = boost::filesystem; -extern BufferList bufferlist; - extern boost::scoped_ptr<kb_keymap> toplevel_keymap; // (alkis) @@ -1082,15 +1079,15 @@ // --- buffers ---------------------------------------- case LFUN_BUFFER_SWITCH: - owner->setBuffer(bufferlist.getBuffer(argument)); + owner->setBuffer(theApp->bufferList().getBuffer(argument)); break; case LFUN_BUFFER_NEXT: - owner->setBuffer(bufferlist.next(view()->buffer())); + owner->setBuffer(theApp->bufferList().next(view()->buffer())); break; case LFUN_BUFFER_PREVIOUS: - owner->setBuffer(bufferlist.previous(view()->buffer())); + owner->setBuffer(theApp->bufferList().previous(view()->buffer())); break; case LFUN_FILE_NEW: @@ -1130,14 +1127,14 @@ if (prefixIs(file_name, package().temp_dir())) { // Needed by inverse dvi search. If it is a file // in tmpdir, call the apropriated function - owner->setBuffer(bufferlist.getBufferFromTmp(file_name)); + owner->setBuffer(theApp->bufferList().getBufferFromTmp(file_name)); } else { // Must replace extension of the file to be .lyx // and get full path string const s = changeExtension(file_name, ".lyx"); // Either change buffer or load the file - if (bufferlist.exists(s)) { - owner->setBuffer(bufferlist.getBuffer(s)); + if (theApp->bufferList().exists(s)) { + owner->setBuffer(theApp->bufferList().getBuffer(s)); } else { owner->loadLyXFile(s); } @@ -1287,8 +1284,8 @@ makeDisplayPath(filename) + lyx::from_ascii("...")); view()->savePosition(0); string const parentfilename = owner->buffer()->fileName(); - if (bufferlist.exists(filename)) - owner->setBuffer(bufferlist.getBuffer(filename)); + if (theApp->bufferList().exists(filename)) + owner->setBuffer(theApp->bufferList().getBuffer(filename)); else owner->loadLyXFile(filename); // Set the parent name of the child document. @@ -1703,7 +1700,7 @@ if (filename.empty()) { filename = addName(lyxrc.document_path, "newfile" + convert<string>(++newfile_number) + ".lyx"); - while (bufferlist.exists(filename) || fs::is_readable(filename)) { + while (theApp->bufferList().exists(filename) || fs::is_readable(filename)) { ++newfile_number; filename = addName(lyxrc.document_path, "newfile" + convert<string>(newfile_number) + @@ -1864,8 +1861,8 @@ string const lyxfile = changeExtension(filename, ".lyx"); // Check if the document already is open - if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) { - if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) { + if (lyx_gui::use_gui && theApp->bufferList().exists(lyxfile)) { + if (!theApp->bufferList().close(theApp->bufferList().getBuffer(lyxfile), true)) { owner->message(_("Canceled.")); return; } @@ -1898,14 +1895,14 @@ // save current cursor position LyX::ref().session().saveFilePosition(owner->buffer()->fileName(), boost::tie(view()->cursor().pit(), view()->cursor().pos()) ); - if (bufferlist.close(owner->buffer(), true) && !quitting) { - if (bufferlist.empty()) { + if (theApp->bufferList().close(owner->buffer(), true) && !quitting) { + if (theApp->bufferList().empty()) { // need this otherwise SEGV may occur while // trying to set variables that don't exist // since there's no current buffer owner->getDialogs().hideBufferDependent(); } else { - owner->setBuffer(bufferlist.first()); + owner->setBuffer(theApp->bufferList().first()); } } } Index: MenuBackend.C =================================================================== --- MenuBackend.C (revision 15153) +++ MenuBackend.C (working copy) @@ -19,7 +19,6 @@ #include "BranchList.h" #include "buffer.h" -#include "bufferlist.h" #include "bufferparams.h" #include "CutAndPaste.h" #include "debug.h" @@ -37,6 +36,7 @@ #include "lyxlex.h" #include "toc.h" +#include "frontends/Application.h" #include "frontends/LyXView.h" #include "support/filetools.h" @@ -67,7 +67,6 @@ using std::vector; -extern BufferList bufferlist; extern boost::scoped_ptr<kb_keymap> toplevel_keymap; namespace { @@ -448,7 +447,7 @@ void expandDocuments(Menu & tomenu, LyXView const * view) { typedef vector<string> Strings; - Strings const names = bufferlist.getFileNames(); + Strings const names = theApp->bufferList().getFileNames(); if (names.empty()) { tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"),