4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS.
16 #include <support/types.h>
18 #include <boost/utility.hpp>
19 #include <boost/tuple/tuple.hpp>
26 // used by at least frontends/qt2/QPref.C
27 const long maxlastfiles = 20;
29 /** This session file maintains
30 1. the latest documents loaded (lastfiles)
31 2. cursor positions of files closed (lastfilepos)
32 3. opened files when a lyx session is closed (lastopened)
34 5. general purpose session info in the form of key/value pairs
38 class Session : boost::noncopyable {
42 typedef boost::tuple<lyx::pit_type, lyx::pos_type> FilePos;
44 typedef std::map<std::string, FilePos> FilePosMap;
46 typedef std::deque<std::string> LastFiles;
48 typedef std::vector<std::string> LastOpened;
50 typedef boost::tuple<unsigned int, std::string, unsigned int, lyx::pos_type> Bookmark;
52 typedef std::vector<Bookmark> BookmarkList;
54 typedef std::map<std::string, std::string> MiscInfo;
57 /** Read the session file.
58 @param num length of lastfiles
60 explicit Session(unsigned int num = 4);
62 /** Write the session file.
64 void writeFile() const;
66 /** Insert #file# into the lastfile dequeue.
67 This funtion inserts #file# into the last files list. If the file
68 already exists it is moved to the top of the list, else exist it
69 is placed on the top of the list. If the list is full the last
70 file in the list is popped from the end.
71 @param file the file to insert in the lastfile list.
73 void addLastFile(std::string const & file);
75 /** add cursor position to the fname entry in the filepos map
76 @param fname file entry for which to save position information
77 @param pos position of the cursor when the file is closed.
79 void saveFilePosition(std::string const & fname, FilePos pos);
81 /** clear lastopened file list
83 void clearLastOpenedFiles();
85 /** add file to lastopened file list
86 @param file filename to add
88 void addLastOpenedFile(std::string const & file);
90 /** load saved cursor position from the fname entry in the filepos map
91 @param fname file entry for which to load position information
93 FilePos loadFilePosition(std::string const & fname) const;
95 /// Return lastfiles container (deque)
96 LastFiles const lastFiles() const { return lastfiles; }
98 /// Return lastopened container (vector)
99 LastOpened const lastOpenedFiles() const { return lastopened; }
102 @bookmark bookmark to be saved
104 void saveBookmark(Bookmark const & bookmark);
106 /** return bookmark list. Non-const container is used since
107 bookmarks will be cleaned after use.
109 BookmarkList & loadBookmarks() { return bookmarks; }
112 @param key key of the value to store
113 @param value value, a string without newline ('\n')
115 void saveSessionInfo(std::string const & key, std::string const & value);
117 /** load session info
118 @param key a key to extract value from the session file
119 @param release whether or not clear the value. Default to true
120 since most of such values are supposed to be used only once.
122 std::string const loadSessionInfo(std::string const & key, bool release = true);
124 /// Default number of lastfiles.
125 unsigned int const default_num_last_files;
127 /// Max number of lastfiles.
128 unsigned int const absolute_max_last_files;
130 /// default number of lastfilepos to save */
131 unsigned int const num_lastfilepos;
133 /// file to save session, determined in the constructor.
134 std::string session_file;
136 /// a list of lastfiles
139 /// a list of bookmarks
140 BookmarkList bookmarks;
142 /// a map to save session info
143 MiscInfo sessioninfo;
145 /// number of files in the lastfiles list.
146 unsigned int num_lastfiles;
148 /// a map of file positions
149 FilePosMap lastfilepos;
151 /// a list of lastopened files
152 LastOpened lastopened;
154 /** Read the session file.
155 Reads the #.lyx/session# at the beginning of the LyX session.
156 This will read the session file (usually #.lyx/session#).
157 @param file the file containing the session.
161 /** Used by the constructor to set the number of stored last files.
162 @param num the number of lastfiles to set.
164 void setNumberOfLastFiles(unsigned int num);