Dear list, The new patch combines lastfiles and filepositions, and add lastopened (and will add bookmarks) to a single session management interface. Please let me know if you like it.
What it does: 1. remove lastfile and its rc entries 2. add use_lastfilepos and load_session rc entries 3. remove .lyx/lastfile and add .lyx/session, with format like ## Automatically generated lyx session file ## Editing this file manually may cause lyx to crash. [lastfiles] /home/user/tmp/glib/doc/UserGuide.lyx /home/user/tmp/glib/doc/Tutorial.lyx /home/user/tmp/glib/doc/Intro.lyx /home/user/.lyx/doc/LaTeXConfig.lyx [lastfilepos] 11, /home/user/.lyx/doc/LaTeXConfig.lyx 3, /home/user/tmp/glib/doc/Customization.lyx 11, /home/user/tmp/glib/doc/UserGuide.lyx [lastopened] /home/user/.lyx/doc/LaTeXConfig.lyx /home/user/tmp/glib/doc/Intro.lyx /home/user/tmp/glib/doc/Tutorial.lyx /home/user/tmp/glib/doc/UserGuide.lyx 4. load files in lastopened automatically (if load_session is true) 5. go to saved paragraph automatically if use_lastfilepos is true, subject to the new-file-scroll-back problem. 6. saved_positions[0] is no longer used. The bookmark feature is easy to add but I will wait till this one is approved. Bo
Index: src/lyx_cb.C =================================================================== --- src/lyx_cb.C (revision 13486) +++ src/lyx_cb.C (working copy) @@ -22,7 +22,7 @@ #include "cursor.h" #include "debug.h" #include "gettext.h" -#include "lastfiles.h" +#include "session.h" #include "LaTeXFeatures.h" #include "lyx_main.h" #include "lyxlayout.h" @@ -101,7 +101,7 @@ bool MenuWrite(Buffer * buffer) { if (buffer->save()) { - LyX::ref().lastfiles().newFile(buffer->fileName()); + LyX::ref().session().newLastFile(buffer->fileName()); return true; } @@ -196,7 +196,7 @@ if (!noask && !bufferlist.quitWriteAll()) return; - LyX::cref().lastfiles().writeFile(lyxrc.lastfiles); + LyX::cref().session().writeFile(); } // Set a flag that we do quitting from the program, Index: src/bufferlist.C =================================================================== --- src/bufferlist.C (revision 13486) +++ src/bufferlist.C (working copy) @@ -17,7 +17,7 @@ #include "bufferparams.h" #include "debug.h" #include "gettext.h" -#include "lastfiles.h" +#include "session.h" #include "lyx_cb.h" #include "lyx_main.h" #include "output_latex.h" @@ -187,7 +187,7 @@ if (!WriteAs(buf)) return false; } else if (buf->save()) { - LyX::ref().lastfiles().newFile(buf->fileName()); + LyX::ref().session().newLastFile(buf->fileName()); } else { return false; } Index: src/BufferView_pimpl.C =================================================================== --- src/BufferView_pimpl.C (revision 13486) +++ src/BufferView_pimpl.C (working copy) @@ -42,7 +42,7 @@ #include "lyxfunc.h" #include "lyxtext.h" #include "lyxrc.h" -#include "lastfiles.h" +#include "session.h" #include "metricsinfo.h" #include "paragraph.h" #include "paragraph_funcs.h" @@ -293,9 +293,27 @@ setBuffer(b); bv_->showErrorList(_("Parse")); + + // scroll to the position when the file was last closed + if (lyxrc.use_lastfilepos) { + lyx::pit_type pit = LyX::ref().session().loadFilePosition(s); + // move to the beginning of that paragraph + // be careful since the file may have been externally changed ... + if ( static_cast<size_t>(pit) < b->paragraphs().size() ) { + // paragraphs is now RandomAccessList + // so simple paragraphs[pit] is not allowed. + ParIterator it = b->par_iterator_begin(); + ParIterator const end = b->par_iterator_end(); + for (; it != end; ++it) + if (it.pit() == pit) + break; + if (it != end) + bv_->setCursor(makeDocIterator(it, 0)); + } + } if (tolastfiles) - LyX::ref().lastfiles().newFile(b->fileName()); + LyX::ref().session().newLastFile(b->fileName()); return true; } Index: src/session.C =================================================================== --- src/session.C (revision 0) +++ src/session.C (revision 0) @@ -0,0 +1,179 @@ +/** + * \file session.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Bo Peng + * + * Full author contact details are available in file CREDITS. + */ + +#include <config.h> + +#include "session.h" +#include "debug.h" +#include "support/package.h" +#include "support/filetools.h" + +#include <boost/filesystem/operations.hpp> + +#include <fstream> +#include <sstream> +#include <algorithm> +#include <fstream> +#include <iterator> + +using std::vector; +using std::getline; +using std::string; +using std::ifstream; +using std::ofstream; +using std::endl; +using std::istringstream; +using std::copy; +using std::find; +using std::ostream_iterator; + +namespace fs = boost::filesystem; +using lyx::support::AddName; +using lyx::support::package; + +LyXSession::LyXSession(unsigned int num) +{ + 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 LyXSession::setNumberOfLastFiles(unsigned int no) +{ + if (0 < no && no <= ABSOLUTEMAXLASTFILES) + num_lastfiles = no; + else { + lyxerr << "LyX: lastfiles: too many files\n" + "\tdefault (=" << int(DEFAULTLASTFILES) + << ") used." << endl; + num_lastfiles = DEFAULTLASTFILES; + } +} + +void LyXSession::readFile() +{ + // 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[0] == '#' || tmp[0] == '\n' || tmp[0] == ' ') + continue; + // lastfiles section + if (tmp == "[lastfiles]") { + section = 0; + continue; + } + else if (tmp == "[lastfilepos]") { + section = 1; + continue; + } + else if (tmp == "[lastopened]") { + section = 2; + continue; + } + // read lastfiles + else if (section == 0) { + if (!fs::exists(tmp) || lastfiles.size() >= num_lastfiles) + continue; + lastfiles.push_back(tmp); + } + // read lastfilepos + else if (section == 1) { + // pos, file\n + FilePos pos; + string fname; + istringstream itmp(tmp); + itmp >> pos; + itmp.ignore(2); // ignore ", " + itmp >> fname; + if (!fs::exists(fname) || lastfilepos.size() >= DEFAULTNUMLASTFILEPOS) + continue; + lastfilepos[fname] = pos; + } + // read lastopened + else if (section == 2) { + // files + if (!fs::exists(tmp)) + continue; + lastopened.push_back(tmp); + } + } + ifs.close(); +} + +void LyXSession::writeFile() const +{ + ofstream ofs(session_file.c_str()); + if (ofs) { + // + ofs << "## Automatically generated lyx session file " << endl; + ofs << "## Editing this file manually may cause lyx to crash. " << endl; + // first section + ofs << endl << "[lastfiles]" << endl; + copy(lastfiles.begin(), lastfiles.end(), + ostream_iterator<string>(ofs, "\n")); + // second section + ofs << endl << "[lastfilepos]" << endl; + for (FilePosMap::const_iterator file = lastfilepos.begin(); + file != lastfilepos.end(); ++file) { + ofs << file->second << ", " << file->first << endl; + } + // third section + ofs << endl << "[lastopened]" << endl; + copy(lastopened.begin(), lastopened.end(), + ostream_iterator<string>(ofs, "\n")); + ofs.close(); + } else + lyxerr << "LyX: Warning: unable to save LyXSession: " + << session_file << endl; +} + +void LyXSession::newLastFile(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 LyXSession::saveFilePosition(string const & fname, FilePos pos ) +{ + lastfilepos[fname] = pos; +} + +LyXSession::FilePos LyXSession::loadFilePosition(string const & fname ) const +{ + FilePosMap::const_iterator entry = lastfilepos.find(fname); + // has position information, return it. + if( entry != lastfilepos.end() ) + return entry->second; + // not found, return the first paragraph + else + return 0; +} + +void LyXSession::setLastOpenedFiles(vector<string> const & files) +{ + lastopened = files; +} + Index: src/lastfiles.C =================================================================== --- src/lastfiles.C (revision 13486) +++ src/lastfiles.C (working copy) @@ -1,99 +0,0 @@ -/** - * \file lastfiles.C - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * - * Full author contact details are available in file CREDITS. - */ - -#include <config.h> - -#include "lastfiles.h" -#include "debug.h" - -#include <boost/filesystem/operations.hpp> - -#include <algorithm> -#include <fstream> -#include <iterator> - -namespace fs = boost::filesystem; - -using std::copy; -using std::endl; -using std::find; -using std::getline; -using std::string; -using std::ifstream; -using std::ofstream; -using std::ostream_iterator; - - -LastFiles::LastFiles(string const & filename, bool st, unsigned int num) - : dostat(st) -{ - setNumberOfFiles(num); - readFile(filename); -} - - -void LastFiles::setNumberOfFiles(unsigned int no) -{ - if (0 < no && no <= ABSOLUTEMAXLASTFILES) - num_files = no; - else { - lyxerr << "LyX: lastfiles: too many files\n" - "\tdefault (=" << int(DEFAULTFILES) - << ") used." << endl; - num_files = DEFAULTFILES; - } -} - - -void LastFiles::readFile(string const & filename) -{ - // we will not complain if we can't find filename nor will - // we issue a warning. (Lgb) - ifstream ifs(filename.c_str()); - string tmp; - - while (getline(ifs, tmp) && files.size() < num_files) { - if (dostat && !fs::exists(tmp)) - continue; - files.push_back(tmp); - } -} - - -void LastFiles::writeFile(string const & filename) const -{ - ofstream ofs(filename.c_str()); - if (ofs) { - copy(files.begin(), files.end(), - ostream_iterator<string>(ofs, "\n")); - } else - lyxerr << "LyX: Warning: unable to save LastFiles: " - << filename << endl; -} - - -void LastFiles::newFile(string const & file) -{ - // If file already exist, delete it and reinsert at front. - Files::iterator it = find(files.begin(), files.end(), file); - if (it != files.end()) - files.erase(it); - files.push_front(file); - if (files.size() > num_files) - files.pop_back(); -} - - -string const LastFiles::operator[](unsigned int i) const -{ - if (i < files.size()) - return files[i]; - return string(); -} Index: src/lyxfunc.C =================================================================== --- src/lyxfunc.C (revision 13486) +++ src/lyxfunc.C (working copy) @@ -43,6 +43,9 @@ #include "kbmap.h" #include "language.h" #include "LColor.h" +// for LyX::ref().session() +#include "session.h" +#include "lyx_main.h" #include "lyx_cb.h" #include "LyXAction.h" #include "lyxfind.h" @@ -996,6 +999,15 @@ break; case LFUN_QUIT: + // with this, File->exit will save Position, + // however, Alt-F4 and close-button do not go + // through here ... + if (view()->available()) { + LyX::ref().session().saveFilePosition(owner->buffer()->fileName(), + view()->cursor().pit() ); + // save opened file name to lastopened list + LyX::ref().session().setLastOpenedFiles( bufferlist.getFileNames()); + } QuitLyX(argument == "force"); break; @@ -1880,6 +1892,9 @@ void LyXFunc::closeBuffer() { + // save current position to lastfile + LyX::ref().session().saveFilePosition(owner->buffer()->fileName(), + view()->cursor().pit() ); if (bufferlist.close(owner->buffer(), true) && !quitting) { if (bufferlist.empty()) { // need this otherwise SEGV may occur while @@ -1966,6 +1981,8 @@ case LyXRC::RC_BIBTEX_COMMAND: case LyXRC::RC_BINDFILE: case LyXRC::RC_CHECKLASTFILES: + case LyXRC::RC_USELASTFILEPOS: + case LyXRC::RC_LOADSESSION: case LyXRC::RC_CHKTEX_COMMAND: case LyXRC::RC_CONVERTER: case LyXRC::RC_COPIER: @@ -2007,7 +2024,6 @@ case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS: case LyXRC::RC_LANGUAGE_PACKAGE: case LyXRC::RC_LANGUAGE_USE_BABEL: - case LyXRC::RC_LASTFILES: case LyXRC::RC_MAKE_BACKUP: case LyXRC::RC_MARK_FOREIGN_LANGUAGE: case LyXRC::RC_NUMLASTFILES: Index: src/frontends/qt2/QPrefs.C =================================================================== --- src/frontends/qt2/QPrefs.C (revision 13486) +++ src/frontends/qt2/QPrefs.C (working copy) @@ -35,7 +35,7 @@ #include "ui/QPrefIdentityModule.h" #include "debug.h" -#include "lastfiles.h" +#include "session.h" #include "LColor.h" #include "lyxfont.h" Index: src/session.h =================================================================== --- src/session.h (revision 0) +++ src/session.h (revision 0) @@ -0,0 +1,145 @@ +// -*- C++ -*- +/** + * \file session.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Bo Peng + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef SESSION_H +#define SESSION_H + +// for pit_type +#include <support/types.h> +#include <boost/utility.hpp> + +#include <string> +#include <deque> +#include <vector> +#include <map> + +// used by at least frontends/qt2/QPref.C +const long maxlastfiles = 20; + +/** This session file maintains + 1. the latest documents loaded (lastfiles) + 2. cursor positions of files closed (lastfilepos) + 3. opened files when a lyx session is closed (lastopened) + 4. bookmarks (will be added soon) + + In the future, things like windows size, + can be added. + */ +class LyXSession : boost::noncopyable { + +public: + /// + typedef lyx::pit_type FilePos; + /// + typedef std::map<std::string, FilePos> FilePosMap; + /// + typedef FilePosMap::iterator FilePosIterator; + /// + typedef std::deque<std::string> LastFiles; + /// + typedef LastFiles::const_iterator LastFilesIterator; + /// + typedef std::vector<std::string> LastOpened; + /// + typedef LastOpened::const_iterator LastOpenedIterator; + +public: + /** Read the session file. + @param num length of lastfiles + */ + explicit LyXSession(unsigned int num = 4); + + /** Write the session file. + */ + 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 newLastFile(std::string const & file); + + /** 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); + + /** set lastopened file list + @param files filenames of a list of opened files + */ + void setLastOpenedFiles(std::vector<std::string> const & files); + + /** 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; + + /// Iterator to the beginning of the list. + LastFilesIterator lastfiles_begin() const { return lastfiles.begin(); } + + /// Iterator to the end of the list. + LastFilesIterator lastfiles_end() const { return lastfiles.end(); } + + /// Iterator to the beginning of the list. + LastOpenedIterator lastopened_begin() const { return lastopened.begin(); } + + /// Iterator to the end of the list. + LastOpenedIterator lastopened_end() const { return lastopened.end(); } + +private: + enum local_constants { + /// Default number of lastfiles. + DEFAULTLASTFILES = 4, + /** Max number of lastfiles. + There is no point in keeping more than this number + of files at the same time. However perhaps someday + someone finds use for more files and wants to + change it. Please do. But don't show the files in + a menu... + */ + ABSOLUTEMAXLASTFILES = 20, + /** default number of lastfilepos to save */ + DEFAULTNUMLASTFILEPOS = 100 + }; + + /// file to save session, determined in the constructor. + std::string session_file; + + /// a list of lastfiles + LastFiles lastfiles; + + /// 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#). + @param file the file containing the session. + */ + 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); +}; + +#endif Index: src/Makefile.am =================================================================== --- src/Makefile.am (revision 13486) +++ src/Makefile.am (working copy) @@ -189,8 +189,8 @@ kbsequence.h \ language.C \ language.h \ - lastfiles.C \ - lastfiles.h \ + session.C \ + session.h \ layout.h \ lengthcommon.C \ lengthcommon.h \ Index: src/lastfiles.h =================================================================== --- src/lastfiles.h (revision 13486) +++ src/lastfiles.h (working copy) @@ -1,105 +0,0 @@ -// -*- C++ -*- -/** - * \file lastfiles.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef LASTFILES_H -#define LASTFILES_H - -#include <boost/utility.hpp> - -#include <deque> -#include <string> - -const long maxlastfiles = 20; - -/** The latest documents loaded. - * This class takes care of the last .lyx files used by the LyX user. It - * both reads and writes this information to a file. The number of files - * kept are user defined, but defaults to four. - */ -class LastFiles : boost::noncopyable { -public: - /// - typedef std::deque<std::string> Files; - - /// - typedef Files::const_iterator const_iterator; - - /** Read the lastfiles file. - @param file The file to read the lastfiles form. - @param dostat Whether to check for file existance. - @param num number of files to remember. - */ - explicit - LastFiles(std::string const & file, - bool dostat = true, unsigned int num = 4); - - /** Insert #file# into the list. - This funtion inserts #file# into the last files list. If the file - already exist 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 list. - */ - void newFile(std::string const & file); - /** Writes the lastfiles table to disk. - Writes one file on each line, this way we can at least have - some special chars (e.g. space), but newline in filenames - are thus not allowed. - @param file the file we write the lastfiles list to. - */ - void writeFile(std::string const & file) const; - /** Return file #n# in the lastfiles list. - @param n number in the list to get - */ - std::string const operator[](unsigned int n) const; - /// Iterator to the beginning of the list. - Files::const_iterator begin() const { return files.begin(); } - /// Iterator to the end of the list. - Files::const_iterator end() const { return files.end(); } -private: - /** Local constants. - It is more portable among different C++ compilers to use - an enum instead of #int const XXX# - */ - enum local_constants { - /// Default number of lastfiles. - DEFAULTFILES = 4, - /** Max number of lastfiles. - There is no point in keeping more than this number - of files at the same time. However perhaps someday - someone finds use for more files and wants to - change it. Please do. But don't show the files in - a menu... - */ - ABSOLUTEMAXLASTFILES = 20 - }; - - /// a list of lastfiles - Files files; - /// number of files in the lastfiles list. - unsigned int num_files; - /// check for file existance or not. - bool dostat; - - /** Read the lastfiles file. - Reads the #.lyx_lastfiles# at the beginning of the LyX session. - This will read the lastfiles file (usually #.lyx_lastfiles#). It - will normally discard files that don't exist anymore, unless - LastFiles has been initialized with #dostat = false#. - @param file the file containing the lastfiles. - */ - void readFile(std::string const & file); - /** Used by the constructor to set the number of stored last files. - @param num the number of lastfiles to set. - */ - void setNumberOfFiles(unsigned int num); -}; -#endif Index: src/lyxrc.C =================================================================== --- src/lyxrc.C (revision 13486) +++ src/lyxrc.C (working copy) @@ -25,7 +25,7 @@ #include "converter.h" #include "format.h" #include "gettext.h" -#include "lastfiles.h" +#include "session.h" #include "LColor.h" #include "lyxlex.h" #include "lyxfont.h" @@ -104,7 +104,8 @@ { "\\language_global_options", LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS }, { "\\language_package", LyXRC::RC_LANGUAGE_PACKAGE }, { "\\language_use_babel", LyXRC::RC_LANGUAGE_USE_BABEL }, - { "\\lastfiles", LyXRC::RC_LASTFILES }, + { "\\use_lastfilepos", LyXRC::RC_USELASTFILEPOS }, + { "\\load_session", LyXRC::RC_LOADSESSION }, { "\\make_backup", LyXRC::RC_MAKE_BACKUP }, { "\\mark_foreign_language", LyXRC::RC_MARK_FOREIGN_LANGUAGE }, { "\\num_lastfiles", LyXRC::RC_NUMLASTFILES }, @@ -246,6 +247,8 @@ ascii_linelen = 65; num_lastfiles = maxlastfiles; check_lastfiles = true; + use_lastfilepos = true; + load_session = true; make_backup = true; backupdir_path.erase(); display_graphics = lyx::graphics::ColorDisplay; @@ -717,12 +720,18 @@ } break; - case RC_LASTFILES: + case RC_USELASTFILEPOS: if (lexrc.next()) { - lastfiles = ExpandPath(os::internal_path(lexrc.getString())); + use_lastfilepos = lexrc.getBool(); } break; + case RC_LOADSESSION: + if (lexrc.next()) { + load_session = lexrc.getBool(); + } + break; + case RC_NUMLASTFILES: if (lexrc.next()) { num_lastfiles = lexrc.getInteger(); @@ -1741,12 +1750,18 @@ string const path = os::external_path(document_path); os << "\\document_path \"" << path << "\"\n"; } - case RC_LASTFILES: + case RC_USELASTFILEPOS: if (ignore_system_lyxrc || - lastfiles != system_lyxrc.lastfiles) { - string const path = os::external_path(lastfiles); - os << "\\lastfiles \"" << path << "\"\n"; + use_lastfilepos != system_lyxrc.use_lastfilepos) { + os << "\\use_session " << convert<string>(use_lastfilepos) + << '\n'; } + case RC_LOADSESSION: + if (ignore_system_lyxrc || + load_session != system_lyxrc.load_session) { + os << "\\load_session " << convert<string>(load_session) + << "\n"; + } case RC_NUMLASTFILES: if (ignore_system_lyxrc || num_lastfiles != system_lyxrc.num_lastfiles) { @@ -2225,10 +2240,14 @@ str = _("De-select if you don't want babel to be used when the language of the document is the default language."); break; - case RC_LASTFILES: - str = _("The file where the last-files information should be stored."); + case RC_USELASTFILEPOS: + str = _("De-select if you do not want LyX to scroll to saved position."); break; + case RC_LOADSESSION: + str = _("De-select to prevent loading files opened from the last lyx session."); + break; + case RC_MAKE_BACKUP: str = _("De-select if you don't want LyX to create backup files."); break; Index: src/lyxrc.h =================================================================== --- src/lyxrc.h (revision 13486) +++ src/lyxrc.h (working copy) @@ -75,7 +75,8 @@ RC_LANGUAGE_GLOBAL_OPTIONS, RC_LANGUAGE_PACKAGE, RC_LANGUAGE_USE_BABEL, - RC_LASTFILES, + RC_USELASTFILEPOS, + RC_LOADSESSION, RC_MAKE_BACKUP, RC_MARK_FOREIGN_LANGUAGE, RC_NUMLASTFILES, @@ -227,10 +228,12 @@ bool auto_reset_options; /// bool check_lastfiles; - /// filename for lastfiles file - std::string lastfiles; /// maximal number of lastfiles unsigned int num_lastfiles; + /// whether or not go to saved position when open a file + bool use_lastfilepos; + /// load files from last session automatically + bool load_session; /// shall a backup file be created bool make_backup; /// A directory for storing backup files Index: src/MenuBackend.C =================================================================== --- src/MenuBackend.C (revision 13486) +++ src/MenuBackend.C (working copy) @@ -30,7 +30,7 @@ #include "gettext.h" #include "importer.h" #include "kbmap.h" -#include "lastfiles.h" +#include "session.h" #include "LyXAction.h" #include "lyx_main.h" // for lastfiles #include "lyxfunc.h" @@ -428,11 +428,11 @@ void expandLastfiles(Menu & tomenu, LyXView const * view) { - LastFiles const & lastfiles = LyX::cref().lastfiles(); + LyXSession const & session = LyX::cref().session(); int ii = 1; - LastFiles::const_iterator lfit = lastfiles.begin(); - LastFiles::const_iterator end = lastfiles.end(); + LyXSession::LastFilesIterator lfit = session.lastfiles_begin(); + LyXSession::LastFilesIterator end = session.lastfiles_end(); for (; lfit != end && ii < 10; ++lfit, ++ii) { string const label = convert<string>(ii) + ". " Index: src/lyx_main.C =================================================================== --- src/lyx_main.C (revision 13486) +++ src/lyx_main.C (working copy) @@ -28,7 +28,7 @@ #include "gettext.h" #include "kbmap.h" #include "language.h" -#include "lastfiles.h" +#include "session.h" #include "LColor.h" #include "lyxfunc.h" #include "lyxlex.h" @@ -163,17 +163,17 @@ {} -LastFiles & LyX::lastfiles() +LyXSession & LyX::session() { - BOOST_ASSERT(lastfiles_.get()); - return *lastfiles_.get(); + BOOST_ASSERT(session_.get()); + return *session_.get(); } -LastFiles const & LyX::lastfiles() const +LyXSession const & LyX::session() const { - BOOST_ASSERT(lastfiles_.get()); - return *lastfiles_.get(); + BOOST_ASSERT(session_.get()); + return *session_.get(); } @@ -238,6 +238,13 @@ if (first_start) files.push_back(i18nLibFileSearch("examples", "splash.lyx")); + // if files is empty (no file is passed) and load_session, ... + if (lyxrc.load_session) { + for (LyXSession::LastOpenedIterator it = session_->lastopened_begin(); + it != session_->lastopened_end(); ++it) + files.push_back( *it ); + } + // Execute batch commands if available if (!batch_command.empty()) { @@ -425,10 +432,6 @@ "templates"); } - if (lyxrc.lastfiles.empty()) { - lyxrc.lastfiles = AddName(package().user_support(), "lastfiles"); - } - if (lyxrc.roman_font_name.empty()) lyxrc.roman_font_name = lyx_gui::roman_font_name(); if (lyxrc.sans_font_name.empty()) @@ -513,11 +516,8 @@ lyxerr << "LyX tmp dir: `" << package().temp_dir() << '\'' << endl; } - lyxerr[Debug::INIT] << "Reading lastfiles `" - << lyxrc.lastfiles << "'..." << endl; - lastfiles_.reset(new LastFiles(lyxrc.lastfiles, - lyxrc.check_lastfiles, - lyxrc.num_lastfiles)); + lyxerr[Debug::INIT] << "Reading session information '.lyx/session'..." << endl; + session_.reset(new LyXSession(lyxrc.num_lastfiles)); } Index: src/lyx_main.h =================================================================== --- src/lyx_main.h (revision 13486) +++ src/lyx_main.h (working copy) @@ -24,7 +24,7 @@ class Buffer; class ErrorItem; class InsetBase; -class LastFiles; +class LyXSession; class LyXView; class kb_keymap; @@ -39,8 +39,8 @@ /// in the case of failure void emergencyCleanup() const; - LastFiles & lastfiles(); - LastFiles const & lastfiles() const; + LyXSession & session(); + LyXSession const & session() const; void addLyXView(boost::shared_ptr<LyXView> const & lyxview); @@ -86,8 +86,8 @@ /// the parsed command line batch command if any std::string batch_command; - /// last files loaded - boost::scoped_ptr<LastFiles> lastfiles_; + /// lyx session, containing lastfiles, lastfilepos, and lastopened + boost::scoped_ptr<LyXSession> session_; /// typedef std::list<boost::shared_ptr<LyXView> > ViewList; ViewList views_;