class session reorganization

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15581 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2006-10-27 14:18:03 +00:00
parent d916db37b0
commit 0fc684e6e6
9 changed files with 482 additions and 263 deletions

View File

@ -132,8 +132,8 @@ BufferView::BufferView()
saved_positions.resize(saved_positions_num);
// load saved bookmarks
Session::BookmarkList & bmList = LyX::ref().session().loadBookmarks();
for (Session::BookmarkList::iterator bm = bmList.begin();
BookmarksSection::BookmarkList & bmList = LyX::ref().session().Bookmarks().load();
for (BookmarksSection::BookmarkList::iterator bm = bmList.begin();
bm != bmList.end(); ++bm)
if (bm->get<0>() < saved_positions_num)
saved_positions[bm->get<0>()] = Position( bm->get<1>(), bm->get<2>(), bm->get<3>() );
@ -167,7 +167,7 @@ void BufferView::setBuffer(Buffer * b)
buffer_->saveCursor(cursor_.selectionBegin(),
cursor_.selectionEnd());
// current buffer is going to be switched-off, save cursor pos
LyX::ref().session().saveFilePosition(buffer_->fileName(),
LyX::ref().session().LastFilePos().save(buffer_->fileName(),
boost::tie(cursor_.pit(), cursor_.pos()) );
}
@ -280,7 +280,7 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
if (lyxrc.use_lastfilepos) {
pit_type pit;
pos_type pos;
boost::tie(pit, pos) = LyX::ref().session().loadFilePosition(s);
boost::tie(pit, pos) = LyX::ref().session().LastFilePos().load(s);
// I am not sure how to separate the following part to a function
// so I will leave this to Lars.
//
@ -299,7 +299,7 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
}
if (tolastfiles)
LyX::ref().session().addLastFile(b->fileName());
LyX::ref().session().LastFiles().add(b->fileName());
return true;
}
@ -574,7 +574,7 @@ void BufferView::saveSavedPositions()
// par_id and pit.
for (unsigned int i=1; i < saved_positions_num; ++i) {
if ( isSavedPosition(i) )
LyX::ref().session().saveBookmark( boost::tie(
LyX::ref().session().Bookmarks().save( boost::tie(
i,
saved_positions[i].filename,
saved_positions[i].par_id,

View File

@ -427,8 +427,8 @@ docstring const limit_string_length(docstring const & str)
void expandLastfiles(Menu & tomenu)
{
lyx::Session::LastFiles const & lf = LyX::cref().session().lastFiles();
lyx::Session::LastFiles::const_iterator lfit = lf.begin();
lyx::LastFilesSection::LastFiles const & lf = LyX::cref().session().LastFiles().lastFiles();
lyx::LastFilesSection::LastFiles::const_iterator lfit = lf.begin();
int ii = 1;

View File

@ -135,7 +135,7 @@ bool BufferList::quitWriteAll()
// if master/slave are both open, do not save slave since it
// will be automatically loaded when the master is loaded
if ((*it)->getMasterBuffer() == (*it))
LyX::ref().session().addLastOpenedFile((*it)->fileName());
LyX::ref().session().LastOpened().add((*it)->fileName());
}
return true;

View File

@ -138,12 +138,12 @@ void GuiView::saveGeometry()
// save windows size and position
Session & session = LyX::ref().session();
session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
session.SessionInfo().save("WindowWidth", convert<string>(geometry.width()));
session.SessionInfo().save("WindowHeight", convert<string>(geometry.height()));
session.SessionInfo().save("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
if (lyxrc.geometry_xysaved) {
session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
session.SessionInfo().save("WindowPosX", convert<string>(geometry.x()));
session.SessionInfo().save("WindowPosY", convert<string>(geometry.y()));
}
}

View File

@ -101,7 +101,7 @@ bool quitting; // flag, that we are quitting the program
bool menuWrite(Buffer * buffer)
{
if (buffer->save()) {
LyX::ref().session().addLastFile(buffer->fileName());
LyX::ref().session().LastFiles().add(buffer->fileName());
return true;
}

View File

@ -493,7 +493,7 @@ void LyX::restoreGuiSession(vector<string> const & files)
// if a file is specified, I assume that user wants to edit *that* file
if (files.empty() && lyxrc.load_session) {
vector<string> const & lastopened = pimpl_->session_->lastOpenedFiles();
vector<string> const & lastopened = pimpl_->session_->LastOpened().getfiles();
// do not add to the lastfile list since these files are restored from
// last seesion, and should be already there (regular files), or should
// not be added at all (help files).
@ -501,7 +501,7 @@ void LyX::restoreGuiSession(vector<string> const & files)
bind(&LyXView::loadLyXFile, view, _1, false));
}
// clear this list to save a few bytes of RAM
pimpl_->session_->clearLastOpenedFiles();
pimpl_->session_->LastOpened().clear();
}
@ -522,13 +522,13 @@ LyXView * LyX::newLyXView()
}
// if lyxrc returns (0,0), then use session info
else {
string val = session().loadSessionInfo("WindowWidth");
string val = session().SessionInfo().load("WindowWidth");
if (!val.empty())
width = convert<unsigned int>(val);
val = session().loadSessionInfo("WindowHeight");
val = session().SessionInfo().load("WindowHeight");
if (!val.empty())
height = convert<unsigned int>(val);
if (session().loadSessionInfo("WindowIsMaximized") == "yes")
if (session().SessionInfo().load("WindowIsMaximized") == "yes")
maximize = true;
}
@ -536,10 +536,10 @@ LyXView * LyX::newLyXView()
int posx = -1;
int posy = -1;
if (lyxrc.geometry_xysaved) {
string val = session().loadSessionInfo("WindowPosX");
string val = session().SessionInfo().load("WindowPosX");
if (!val.empty())
posx = convert<int>(val);
val = session().loadSessionInfo("WindowPosY");
val = session().SessionInfo().load("WindowPosY");
if (!val.empty())
posy = convert<int>(val);
}

View File

@ -1033,7 +1033,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// might be visible in more than one LyXView.
if (lyx_view_ && lyx_view_->view()->buffer()) {
// save cursor Position for opened files to .lyx/session
LyX::ref().session().saveFilePosition(lyx_view_->buffer()->fileName(),
LyX::ref().session().LastFilePos().save(lyx_view_->buffer()->fileName(),
boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
// save bookmarks to .lyx/session
view()->saveSavedPositions();
@ -1968,7 +1968,7 @@ void LyXFunc::doImport(string const & argument)
void LyXFunc::closeBuffer()
{
// save current cursor position
LyX::ref().session().saveFilePosition(lyx_view_->buffer()->fileName(),
LyX::ref().session().LastFilePos().save(lyx_view_->buffer()->fileName(),
boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
if (theBufferList().close(lyx_view_->buffer(), true) && !quitting) {
if (theBufferList().empty()) {

View File

@ -33,6 +33,8 @@ using std::getline;
using std::string;
using std::ifstream;
using std::ofstream;
using std::istream;
using std::ostream;
using std::endl;
using std::istringstream;
using std::copy;
@ -46,32 +48,57 @@ string const sec_lastfilepos = "[cursor positions]";
string const sec_lastopened = "[last opened files]";
string const sec_bookmarks = "[bookmarks]";
string const sec_session = "[session info]";
int const id_lastfiles = 0;
int const id_lastfilepos = 1;
int const id_lastopened = 2;
int const id_bookmarks = 3;
int const id_session = 4;
} // anon namespace
namespace lyx {
Session::Session(unsigned int num) :
LastFilesSection::LastFilesSection(unsigned int num) :
default_num_last_files(4),
absolute_max_last_files(100),
num_lastfilepos(100)
absolute_max_last_files(100)
{
setNumberOfLastFiles(num);
// locate the session file
// note that the session file name 'session' is hard-coded
session_file = addName(package().user_support(), "session");
//
readFile();
}
void Session::setNumberOfLastFiles(unsigned int no)
void LastFilesSection::read(istream & is)
{
string tmp;
do {
char c = is.peek();
if (c == '[')
break;
getline(is, tmp);
// read lastfiles
if (!fs::exists(tmp) || lastfiles.size() >= num_lastfiles)
continue;
lastfiles.push_back(tmp);
} while (is.good());
}
void LastFilesSection::write(ostream & os) const
{
os << '\n' << sec_lastfiles << '\n';
copy(lastfiles.begin(), lastfiles.end(),
ostream_iterator<string>(os, "\n"));
}
void LastFilesSection::add(string const & file)
{
// If file already exist, delete it and reinsert at front.
LastFiles::iterator it = find(lastfiles.begin(), lastfiles.end(), file);
if (it != lastfiles.end())
lastfiles.erase(it);
lastfiles.push_front(file);
if (lastfiles.size() > num_lastfiles)
lastfiles.pop_back();
}
void LastFilesSection::setNumberOfLastFiles(unsigned int no)
{
if (0 < no && no <= absolute_max_last_files)
num_lastfiles = no;
@ -84,152 +111,86 @@ void Session::setNumberOfLastFiles(unsigned int no)
}
void Session::readFile()
void LastOpenedSection::read(istream & is)
{
// we will not complain if we can't find session_file nor will
// we issue a warning. (Lgb)
ifstream ifs(session_file.c_str());
string tmp;
int section = -1;
// the following is currently not implemented very
// robustly. (Manually editing of the session file may crash lyx)
//
while (getline(ifs, tmp)) {
// Ignore comments, empty line or line stats with ' '
if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ')
do {
char c = is.peek();
if (c == '[')
break;
getline(is, tmp);
if (!fs::exists(tmp))
continue;
lastopened.push_back(tmp);
} while (is.good());
}
// Determine section id
if (tmp == sec_lastfiles) {
section = id_lastfiles;
} else if (tmp == sec_lastfilepos) {
section = id_lastfilepos;
} else if (tmp == sec_lastopened) {
section = id_lastopened;
} else if (tmp == sec_bookmarks) {
section = id_bookmarks;
} else if (tmp == sec_session) {
section = id_session;
} else if (section == id_lastfiles) {
// read lastfiles
if (!fs::exists(tmp) || lastfiles.size() >= num_lastfiles)
continue;
lastfiles.push_back(tmp);
} else if (section == id_lastfilepos) {
// read lastfilepos
// pos, file\n
pit_type pit;
pos_type pos;
string fname;
istringstream itmp(tmp);
itmp >> pit;
itmp.ignore(2); // ignore ", "
itmp >> pos;
itmp.ignore(2); // ignore ", "
itmp >> fname;
if (!fs::exists(fname) || lastfilepos.size() >= num_lastfilepos)
continue;
lastfilepos[fname] = boost::tie(pit, pos);
} else if (section == id_lastopened) {
// read lastopened
// files
if (!fs::exists(tmp))
continue;
lastopened.push_back(tmp);
} else if (section == id_bookmarks) {
// read bookmarks
// bookmarkid, id, pos, file\n
unsigned int num;
unsigned int id;
pos_type pos;
string fname;
istringstream itmp(tmp);
itmp >> num;
itmp.ignore(2); // ignore ", "
itmp >> id;
itmp.ignore(2); // ignore ", "
itmp >> pos;
itmp.ignore(2); // ignore ", "
itmp >> fname;
// only load valid bookmarks
if (fs::exists(fname))
bookmarks.push_back(boost::tie(num, fname, id, pos));
} else if (section == id_session) {
// Read session info, saved as key/value pairs
// would better yell if pos returns npos
string::size_type pos = tmp.find_first_of(" = ");
string key = tmp.substr(0, pos);
string value = tmp.substr(pos + 3);
sessioninfo[key] = value;
}
void LastOpenedSection::write(ostream & os) const
{
os << '\n' << sec_lastopened << '\n';
copy(lastopened.begin(), lastopened.end(),
ostream_iterator<string>(os, "\n"));
}
void LastOpenedSection::add(string const & file)
{
lastopened.push_back(file);
}
void LastOpenedSection::clear()
{
lastopened.clear();
}
void LastFilePosSection::read(istream & is)
{
string tmp;
do {
char c = is.peek();
if (c == '[')
break;
getline(is, tmp);
// read lastfilepos
// pos, file\n
pit_type pit;
pos_type pos;
string fname;
istringstream itmp(tmp);
itmp >> pit;
itmp.ignore(2); // ignore ", "
itmp >> pos;
itmp.ignore(2); // ignore ", "
itmp >> fname;
if (!fs::exists(fname) || lastfilepos.size() >= num_lastfilepos)
continue;
lastfilepos[fname] = boost::tie(pit, pos);
} while (is.good());
}
void LastFilePosSection::write(ostream & os) const
{
os << '\n' << sec_lastfilepos << '\n';
for (FilePosMap::const_iterator file = lastfilepos.begin();
file != lastfilepos.end(); ++file) {
os << file->second.get<0>() << ", "
<< file->second.get<1>() << ", "
<< file->first << '\n';
}
}
void Session::writeFile() const
{
ofstream ofs(session_file.c_str());
if (ofs) {
ofs << "## Automatically generated lyx session file \n"
<< "## Editing this file manually may cause lyx to crash.\n";
// first section
ofs << '\n' << sec_lastfiles << '\n';
copy(lastfiles.begin(), lastfiles.end(),
ostream_iterator<string>(ofs, "\n"));
// second section
ofs << '\n' << sec_lastfilepos << '\n';
for (FilePosMap::const_iterator file = lastfilepos.begin();
file != lastfilepos.end(); ++file) {
ofs << file->second.get<0>() << ", "
<< file->second.get<1>() << ", "
<< file->first << '\n';
}
// third section
ofs << '\n' << sec_lastopened << '\n';
copy(lastopened.begin(), lastopened.end(),
ostream_iterator<string>(ofs, "\n"));
// fourth section
ofs << '\n' << sec_bookmarks << '\n';
for (BookmarkList::const_iterator bm = bookmarks.begin();
bm != bookmarks.end(); ++bm) {
// save bookmark number, id, pos, fname
ofs << bm->get<0>() << ", "
<< bm->get<2>() << ", "
<< bm->get<3>() << ", "
<< bm->get<1>() << '\n';
}
// fifth section
ofs << '\n' << sec_session << '\n';
for (MiscInfo::const_iterator val = sessioninfo.begin();
val != sessioninfo.end(); ++val) {
ofs << val->first << " = " << val->second << '\n';
}
} else
lyxerr << "LyX: Warning: unable to save Session: "
<< session_file << endl;
}
void Session::addLastFile(string const & file)
{
// If file already exist, delete it and reinsert at front.
LastFiles::iterator it = find(lastfiles.begin(), lastfiles.end(), file);
if (it != lastfiles.end())
lastfiles.erase(it);
lastfiles.push_front(file);
if (lastfiles.size() > num_lastfiles)
lastfiles.pop_back();
}
void Session::saveFilePosition(string const & fname, FilePos pos)
void LastFilePosSection::save(string const & fname, FilePos pos)
{
lastfilepos[fname] = pos;
}
Session::FilePos Session::loadFilePosition(string const & fname) const
LastFilePosSection::FilePos LastFilePosSection::load(string const & fname) const
{
FilePosMap::const_iterator entry = lastfilepos.find(fname);
// Has position information, return it.
@ -241,31 +202,94 @@ Session::FilePos Session::loadFilePosition(string const & fname) const
}
void Session::clearLastOpenedFiles()
void BookmarksSection::read(istream & is)
{
lastopened.clear();
string tmp;
do {
char c = is.peek();
if (c == '[')
break;
getline(is, tmp);
// read bookmarks
// bookmarkid, id, pos, file\n
unsigned int num;
unsigned int id;
pos_type pos;
string fname;
istringstream itmp(tmp);
itmp >> num;
itmp.ignore(2); // ignore ", "
itmp >> id;
itmp.ignore(2); // ignore ", "
itmp >> pos;
itmp.ignore(2); // ignore ", "
itmp >> fname;
// only load valid bookmarks
if (fs::exists(fname))
bookmarks.push_back(boost::tie(num, fname, id, pos));
} while (is.good());
}
void Session::addLastOpenedFile(string const & file)
void BookmarksSection::write(ostream & os) const
{
lastopened.push_back(file);
os << '\n' << sec_bookmarks << '\n';
for (BookmarkList::const_iterator bm = bookmarks.begin();
bm != bookmarks.end(); ++bm) {
// save bookmark number, id, pos, fname
os << bm->get<0>() << ", "
<< bm->get<2>() << ", "
<< bm->get<3>() << ", "
<< bm->get<1>() << '\n';
}
}
void Session::saveBookmark(Bookmark const & bookmark)
void BookmarksSection::save(Bookmark const & bookmark)
{
bookmarks.push_back(bookmark);
}
void Session::saveSessionInfo(string const & key, string const & value)
void SessionInfoSection::read(istream & is)
{
string tmp;
do {
char c = is.peek();
if (c == '[')
break;
getline(is, tmp);
// Read session info, saved as key/value pairs
// would better yell if pos returns npos
string::size_type pos = tmp.find_first_of(" = ");
// silently ignore lines without " = "
if (pos != string::npos) {
string key = tmp.substr(0, pos);
string value = tmp.substr(pos + 3);
sessioninfo[key] = value;
}
} while (is.good());
}
void SessionInfoSection::write(ostream & os) const
{
os << '\n' << sec_session << '\n';
for (MiscInfo::const_iterator val = sessioninfo.begin();
val != sessioninfo.end(); ++val) {
os << val->first << " = " << val->second << '\n';
}
}
void SessionInfoSection::save(string const & key, string const & value)
{
sessioninfo[key] = value;
}
string const Session::loadSessionInfo(string const & key, bool release)
string const SessionInfoSection::load(string const & key, bool release)
{
MiscInfo::const_iterator pos = sessioninfo.find(key);
string value;
@ -276,4 +300,63 @@ string const Session::loadSessionInfo(string const & key, bool release)
return value;
}
Session::Session(unsigned int num) :
last_files(num)
{
// locate the session file
// note that the session file name 'session' is hard-coded
session_file = addName(package().user_support(), "session");
//
readFile();
}
void Session::readFile()
{
// we will not complain if we can't find session_file nor will
// we issue a warning. (Lgb)
ifstream is(session_file.c_str());
string tmp;
while (getline(is, tmp)) {
// Ignore comments, empty line or line stats with ' '
if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ')
continue;
// Determine section id
if (tmp == sec_lastfiles)
LastFiles().read(is);
else if (tmp == sec_lastopened)
LastOpened().read(is);
else if (tmp == sec_lastfilepos)
LastFilePos().read(is);
else if (tmp == sec_bookmarks)
Bookmarks().read(is);
else if (tmp == sec_session)
SessionInfo().read(is);
else
lyxerr << "LyX: Warning: unknown Session section: " << tmp << endl;
}
}
void Session::writeFile() const
{
ofstream os(session_file.c_str());
if (os) {
os << "## Automatically generated lyx session file \n"
<< "## Editing this file manually may cause lyx to crash.\n";
LastFiles().write(os);
LastOpened().write(os);
LastFilePos().write(os);
Bookmarks().write(os);
SessionInfo().write(os);
} else
lyxerr << "LyX: Warning: unable to save Session: "
<< session_file << endl;
}
}

View File

@ -35,24 +35,204 @@ const long maxlastfiles = 20;
*/
namespace lyx {
class Session : boost::noncopyable {
/** base class for all sections in the session file
*/
class SessionSection : boost::noncopyable {
public:
/// read section from std::istream
virtual void read(std::istream & is) = 0;
/// write to std::ostream
virtual void write(std::ostream & os) const = 0;
};
class LastFilesSection : SessionSection
{
public:
///
typedef std::deque<std::string> LastFiles;
public:
///
typedef boost::tuple<pit_type, pos_type> FilePos;
explicit LastFilesSection(unsigned int num = 4);
///
typedef std::map<std::string, FilePos> FilePosMap;
void read(std::istream & is);
///
typedef std::deque<std::string> LastFiles;
void write(std::ostream & os) const;
/// Return lastfiles container (deque)
LastFiles const lastFiles() const { return lastfiles; }
/** Insert #file# into the lastfile dequeue.
This funtion inserts #file# into the last files list. If the file
already exists it is moved to the top of the list, else exist it
is placed on the top of the list. If the list is full the last
file in the list is popped from the end.
@param file the file to insert in the lastfile list.
*/
void add(std::string const & file);
private:
/// Default number of lastfiles.
unsigned int const default_num_last_files;
/// Max number of lastfiles.
unsigned int const absolute_max_last_files;
/// a list of lastfiles
LastFiles lastfiles;
/// number of files in the lastfiles list.
unsigned int num_lastfiles;
/** Used by the constructor to set the number of stored last files.
@param num the number of lastfiles to set.
*/
void setNumberOfLastFiles(unsigned int num);
};
class LastOpenedSection : SessionSection
{
public:
///
typedef std::vector<std::string> LastOpened;
public:
///
void read(std::istream & is);
///
void write(std::ostream & os) const;
/// Return lastopened container (vector)
LastOpened const getfiles() const { return lastopened; }
/** add file to lastopened file list
@param file filename to add
*/
void add(std::string const & file);
/** clear lastopened file list
*/
void clear();
private:
/// a list of lastopened files
LastOpened lastopened;
};
class LastFilePosSection : SessionSection
{
public:
///
typedef boost::tuple<pit_type, pos_type> FilePos;
///
typedef std::map<std::string, FilePos> FilePosMap;
public:
///
LastFilePosSection() : num_lastfilepos(100) {}
///
void read(std::istream & is);
///
void write(std::ostream & os) const;
/** add cursor position to the fname entry in the filepos map
@param fname file entry for which to save position information
@param pos position of the cursor when the file is closed.
*/
void save(std::string const & fname, FilePos pos);
/** load saved cursor position from the fname entry in the filepos map
@param fname file entry for which to load position information
*/
FilePos load(std::string const & fname) const;
private:
/// default number of lastfilepos to save */
unsigned int const num_lastfilepos;
/// a map of file positions
FilePosMap lastfilepos;
};
class BookmarksSection : SessionSection
{
public:
///
typedef boost::tuple<unsigned int, std::string, unsigned int, pos_type> Bookmark;
///
typedef std::vector<Bookmark> BookmarkList;
public:
///
void read(std::istream & is);
///
void write(std::ostream & os) const;
/** save a bookmark
@bookmark bookmark to be saved
*/
void save(Bookmark const & bookmark);
/** return bookmark list. Non-const container is used since
bookmarks will be cleaned after use.
*/
BookmarkList & load() { return bookmarks; }
private:
/// a list of bookmarks
BookmarkList bookmarks;
};
class SessionInfoSection : SessionSection
{
public:
///
typedef std::map<std::string, std::string> MiscInfo;
public:
///
void read(std::istream & is);
///
void write(std::ostream & os) const;
/** set session info
@param key key of the value to store
@param value value, a string without newline ('\n')
*/
void save(std::string const & key, std::string const & value);
/** load session info
@param key a key to extract value from the session file
@param release whether or not clear the value. Default to true
since most of such values are supposed to be used only once.
*/
std::string const load(std::string const & key, bool release = true);
private:
/// a map to save session info
MiscInfo sessioninfo;
};
class Session : boost::noncopyable {
public:
/** Read the session file.
@param num length of lastfiles
@ -63,94 +243,40 @@ public:
*/
void writeFile() const;
/** Insert #file# into the lastfile dequeue.
This funtion inserts #file# into the last files list. If the file
already exists it is moved to the top of the list, else exist it
is placed on the top of the list. If the list is full the last
file in the list is popped from the end.
@param file the file to insert in the lastfile list.
*/
void addLastFile(std::string const & file);
///
LastFilesSection & LastFiles() { return last_files; }
///
LastFilesSection const & LastFiles() const { return last_files; }
/** add cursor position to the fname entry in the filepos map
@param fname file entry for which to save position information
@param pos position of the cursor when the file is closed.
*/
void saveFilePosition(std::string const & fname, FilePos pos);
///
LastOpenedSection & LastOpened() { return last_opened; }
/** clear lastopened file list
*/
void clearLastOpenedFiles();
///
LastOpenedSection const & LastOpened() const { return last_opened; }
///
LastFilePosSection & LastFilePos() { return last_file_pos; }
///
LastFilePosSection const & LastFilePos() const { return last_file_pos; }
/** add file to lastopened file list
@param file filename to add
*/
void addLastOpenedFile(std::string const & file);
///
BookmarksSection & Bookmarks() { return bookmarks; }
/** load saved cursor position from the fname entry in the filepos map
@param fname file entry for which to load position information
*/
FilePos loadFilePosition(std::string const & fname) const;
///
BookmarksSection const & Bookmarks() const { return bookmarks; }
/// Return lastfiles container (deque)
LastFiles const lastFiles() const { return lastfiles; }
///
SessionInfoSection & SessionInfo() { return session_info; }
/// Return lastopened container (vector)
LastOpened const lastOpenedFiles() const { return lastopened; }
///
SessionInfoSection const & SessionInfo() const { return session_info; }
/** save a bookmark
@bookmark bookmark to be saved
*/
void saveBookmark(Bookmark const & bookmark);
/** return bookmark list. Non-const container is used since
bookmarks will be cleaned after use.
*/
BookmarkList & loadBookmarks() { return bookmarks; }
/** set session info
@param key key of the value to store
@param value value, a string without newline ('\n')
*/
void saveSessionInfo(std::string const & key, std::string const & value);
/** load session info
@param key a key to extract value from the session file
@param release whether or not clear the value. Default to true
since most of such values are supposed to be used only once.
*/
std::string const loadSessionInfo(std::string const & key, bool release = true);
private:
/// Default number of lastfiles.
unsigned int const default_num_last_files;
/// Max number of lastfiles.
unsigned int const absolute_max_last_files;
/// default number of lastfilepos to save */
unsigned int const num_lastfilepos;
/// file to save session, determined in the constructor.
std::string session_file;
/// a list of lastfiles
LastFiles lastfiles;
/// a list of bookmarks
BookmarkList bookmarks;
/// a map to save session info
MiscInfo sessioninfo;
/// number of files in the lastfiles list.
unsigned int num_lastfiles;
/// a map of file positions
FilePosMap lastfilepos;
/// a list of lastopened files
LastOpened lastopened;
/** Read the session file.
Reads the #.lyx/session# at the beginning of the LyX session.
This will read the session file (usually #.lyx/session#).
@ -158,10 +284,20 @@ private:
*/
void readFile();
/** Used by the constructor to set the number of stored last files.
@param num the number of lastfiles to set.
*/
void setNumberOfLastFiles(unsigned int num);
///
LastFilesSection last_files;
///
LastOpenedSection last_opened;
///
LastFilePosSection last_file_pos;
///
BookmarksSection bookmarks;
///
SessionInfoSection session_info;
};
}