replace global variable bufferlist with Application class member access.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15161 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2006-09-27 10:24:13 +00:00
parent b3cacd0238
commit 1396c73262
15 changed files with 85 additions and 91 deletions

View File

@ -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,8 +101,6 @@ using std::mem_fun_ref;
using std::string;
using std::vector;
extern BufferList bufferlist;
namespace {
@ -186,7 +184,7 @@ void BufferView::setBuffer(Buffer * b)
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 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
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 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
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 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
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 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
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 @@ void BufferView::restorePosition(unsigned int i)
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);
}

View File

@ -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::set;
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 @@ using std::vector;
// - 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 @@ int LaTeX::run(TeXErrors & terr)
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.

View File

@ -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::string;
using std::vector;
extern BufferList bufferlist;
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
namespace {
@ -448,7 +447,7 @@ void expandLastfiles(Menu & tomenu, LyXView const * view)
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!"),

View File

@ -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::vector;
using std::string;
// all these externs should eventually be removed.
extern BufferList bufferlist;
namespace {
int const LYX_FORMAT = 249;
@ -1484,8 +1481,8 @@ void Buffer::setParentName(string const & name)
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();
}
@ -1497,8 +1494,8 @@ Buffer const * Buffer::getMasterBuffer() const
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();
}

View File

@ -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 @@ using std::string;
namespace fs = boost::filesystem;
extern BufferList bufferlist;
namespace {
bool readFile(Buffer * const b, string const & s)
@ -175,12 +173,12 @@ bool loadLyXFile(Buffer * b, string const & s)
return false;
}
// FIXME newFile() should probably be a member method of Application...
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 @@ Buffer * newFile(string const & filename, string const & templatename,
_("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;
}
}

View File

@ -70,6 +70,18 @@ LyXServerSocket const & Application::socket() const
}
BufferList & Application::bufferList()
{
return buffer_list_;
}
BufferList const & Application::bufferList() const
{
return buffer_list_;
}
void Application::setBufferView(BufferView * buffer_view)
{
buffer_view_ = buffer_view;

View File

@ -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 @@ public:
LyXServerSocket & socket();
LyXServerSocket const & socket() const;
///
BufferList & bufferList();
BufferList const & bufferList() const;
void setBufferView(BufferView * buffer_view);
protected:
@ -86,6 +90,8 @@ private:
boost::scoped_ptr<LyXServer> lyx_server_;
///
boost::scoped_ptr<LyXServerSocket> lyx_socket_;
///
BufferList buffer_list_;
}; // Application

View File

@ -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::string;
using std::vector;
extern BufferList bufferlist;
namespace lyx {
using support::FileFilterList;
@ -67,7 +66,7 @@ void ControlPrefs::dispatchParams()
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_;

View File

@ -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 @@ ControlRef::ControlRef(Dialog & d)
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 @@ void ControlRef::gotoBookmark()
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 @@ vector<string> const ControlRef::getBufferList() const
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 @@ int ControlRef::getBufferNum() const
string const ControlRef::getBufferName(int num) const
{
return bufferlist.getFileNames()[num];
return theApp->bufferList().getFileNames()[num];
}
} // namespace frontend

View File

@ -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"

View File

@ -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::string;
using std::vector;
extern BufferList bufferlist;
bool Importer::Import(LyXView * lv, string const & filename,
string const & format, ErrorList & errorList)
{

View File

@ -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,8 +82,6 @@ using std::ostringstream;
namespace fs = boost::filesystem;
extern BufferList bufferlist;
namespace {
@ -319,7 +317,7 @@ Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params
if (!isLyXFilename(included_file))
return 0;
return bufferlist.getBuffer(included_file);
return theApp->bufferList().getBuffer(included_file);
}
@ -333,12 +331,12 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
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 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
// 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 @@ int InsetInclude::docbook(Buffer const & buffer, ostream & os,
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 @@ void InsetInclude::validate(LaTeXFeatures & features) const
// 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 @@ void InsetInclude::getLabelList(Buffer const & buffer,
{
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 @@ void InsetInclude::fillWithBibKeys(Buffer const & buffer,
{
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));

View File

@ -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::ios;
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 @@ void quitLyX(bool noask)
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 @@ void quitLyX(bool noask)
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;

View File

@ -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 @@ using std::system;
#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 @@ int LyX::exec2(int & argc, char * argv[])
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 @@ int LyX::exec2(int & argc, char * argv[])
boost::bind(&LyX::printError, this, _1));
}
else
bufferlist.release(buf);
theApp->bufferList().release(buf);
}
}
@ -658,7 +654,7 @@ void LyX::emergencyCleanup() const
// contain documents etc. which might be helpful on
// a crash
bufferlist.emergencyWriteAll();
theApp->bufferList().emergencyWriteAll();
theApp->server().emergencyCleanup();
}

View File

@ -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 biblio = lyx::biblio;
namespace fs = boost::filesystem;
extern BufferList bufferlist;
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
// (alkis)
@ -1082,15 +1079,15 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// --- 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 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
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 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
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 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
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 @@ void LyXFunc::doImport(string const & argument)
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 @@ void LyXFunc::closeBuffer()
// 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());
}
}
}