string const sec_lastopened = "[last opened files]";
string const sec_bookmarks = "[bookmarks]";
string const sec_session = "[session info]";
+string const sec_toolbars = "[toolbars]";
} // anon namespace
break;
getline(is, tmp);
// read bookmarks
- // bookmarkid, id, pos, file\n
- unsigned int num;
+ // id, pos, file\n
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));
+ if (bookmarks.size() < max_bookmarks && fs::exists(fname))
+ bookmarks.push_back(Bookmark(fname, id, pos));
} while (is.good());
}
void BookmarksSection::write(ostream & os) const
{
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';
+ for (size_t i = 0; i < bookmarks.size(); ++i) {
+ os << bookmarks[i].par_id << ", "
+ << bookmarks[i].par_pos << ", "
+ << bookmarks[i].filename << '\n';
}
}
-void BookmarksSection::save(Bookmark const & bookmark)
+void BookmarksSection::save(std::string const & fname, int par_id, pos_type par_pos, bool persistent)
{
- bookmarks.push_back(bookmark);
+ if (persistent) {
+ bookmarks.push_front(Bookmark(fname, par_id, par_pos));
+ if (bookmarks.size() > max_bookmarks)
+ bookmarks.pop_back();
+ }
+ else
+ temp_bookmark = Bookmark(fname, par_id, par_pos);
+}
+
+
+bool BookmarksSection::isValid(unsigned int i) const
+{
+ // i == 0, or in the queue
+ return i <= bookmarks.size();
+}
+
+
+BookmarksSection::Bookmark const & BookmarksSection::bookmark(unsigned int i) const
+{
+ if (i == 0)
+ return temp_bookmark;
+ else
+ return bookmarks[i-1];
+}
+
+
+void ToolbarSection::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);
+ int state;
+ int location;
+ istringstream value(tmp.substr(pos + 3));
+ value >> state;
+ value.ignore(1); // ignore " "
+ value >> location;
+ toolbars[key] = ToolbarInfo(state, location);
+ }
+ } while (is.good());
+}
+
+
+void ToolbarSection::write(ostream & os) const
+{
+ os << '\n' << sec_toolbars << '\n';
+ for (ToolbarMap::const_iterator tb = toolbars.begin();
+ tb != toolbars.end(); ++tb) {
+ os << tb->first << " = "
+ << static_cast<int>(tb->second.state) << " "
+ << static_cast<int>(tb->second.location) << '\n';
+ }
+}
+
+
+ToolbarSection::ToolbarInfo & ToolbarSection::load(string const & name)
+{
+ return toolbars[name];
}
}
-
Session::Session(unsigned int num) :
last_files(num)
{
// Determine section id
if (tmp == sec_lastfiles)
- LastFiles().read(is);
+ lastFiles().read(is);
else if (tmp == sec_lastopened)
- LastOpened().read(is);
+ lastOpened().read(is);
else if (tmp == sec_lastfilepos)
- LastFilePos().read(is);
+ lastFilePos().read(is);
else if (tmp == sec_bookmarks)
- Bookmarks().read(is);
+ bookmarks().read(is);
+ else if (tmp == sec_toolbars)
+ toolbars().read(is);
else if (tmp == sec_session)
- SessionInfo().read(is);
+ sessionInfo().read(is);
else
lyxerr << "LyX: Warning: unknown Session section: " << tmp << endl;
}
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);
+ lastFiles().write(os);
+ lastOpened().write(os);
+ lastFilePos().write(os);
+ bookmarks().write(os);
+ toolbars().write(os);
+ sessionInfo().write(os);
} else
lyxerr << "LyX: Warning: unable to save Session: "
<< session_file << endl;