X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsession.C;h=4372d610e89401a6ca975bfd045235df8442e222;hb=3bc4d28449143f6c90cf8209f29693c975801b28;hp=02edebd0a84f68975ded70ca9f85b7601a0583a6;hpb=b9c604e968bffcd4aacceee87989782f28492f2f;p=lyx.git diff --git a/src/session.C b/src/session.C index 02edebd0a8..4372d610e8 100644 --- a/src/session.C +++ b/src/session.C @@ -48,6 +48,7 @@ string const sec_lastfilepos = "[cursor positions]"; 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 @@ -211,22 +212,19 @@ void BookmarksSection::read(istream & is) 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()); } @@ -234,20 +232,84 @@ void BookmarksSection::read(istream & is) 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(tb->second.state) << " " + << static_cast(tb->second.location) << '\n'; + } +} + + +ToolbarSection::ToolbarInfo & ToolbarSection::load(string const & name) +{ + return toolbars[name]; } @@ -301,7 +363,6 @@ string const SessionInfoSection::load(string const & key, bool release) } - Session::Session(unsigned int num) : last_files(num) { @@ -334,6 +395,8 @@ void Session::readFile() lastFilePos().read(is); else if (tmp == sec_bookmarks) bookmarks().read(is); + else if (tmp == sec_toolbars) + toolbars().read(is); else if (tmp == sec_session) sessionInfo().read(is); else @@ -353,6 +416,7 @@ void Session::writeFile() const lastOpened().write(os); lastFilePos().write(os); bookmarks().write(os); + toolbars().write(os); sessionInfo().write(os); } else lyxerr << "LyX: Warning: unable to save Session: "