"Bo Peng" <[EMAIL PROTECTED]> writes:

| 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());

We should perhaps change the name of the function.
|               return true;
|       }
|  
| @@ -196,7 +196,7 @@
|               if (!noask && !bufferlist.quitWriteAll())
|                       return;
|  
| -             LyX::cref().lastfiles().writeFile(lyxrc.lastfiles);
| +             LyX::cref().session().writeFile();
|       }

I really like the "one session object for session stuff" approach.

  
| 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));
| +             }
| +     }

Hmm da hmm... I think at the very least this block should be put into
its own function.

| Index: src/session.C
| ===================================================================
| --- src/session.C     (revision 0)
| +++ src/session.C     (revision 0)
| @@ -0,0 +1,184 @@
| +/**
| + * \file session.C
| + * This file is part of LyX, the document processor.
| + * Licence details can be found in the file COPYING.
| + *
| + * \author Bo Peng

Please move me over from the now defunct lastfiles file.

| + *
| + * 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>

fstream two times.

| +LyXSession::LyXSession(unsigned int num)

Please don't call this class "LyXSession", just call it session and
put in the LyX namespace.

| -string const LastFiles::operator[](unsigned int i) const
| -{
| -     if (i < files.size())
| -             return files[i];
| -     return string();
| -}

Was this unused?
(Yes I guess so)

| 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()

drop the comment please, it is kind of self evident.

| +#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());
| +                     }

Have you looked at putting this into QuitLyX instead?

|                       QuitLyX(argument == "force");
|                       break;
|  
| Index: src/frontends/qt4/QPrefs.C
| ===================================================================
| --- src/frontends/qt4/QPrefs.C        (revision 13486)
| +++ src/frontends/qt4/QPrefs.C        (working copy)
| @@ -18,7 +18,8 @@
|  #include "qt_helpers.h"
|  
|  #include "debug.h"
| -#include "lastfiles.h"
| +// is this file actually used?
| +#include "session.h"

If it is not, just delete it.

| Index: src/session.h
| ===================================================================
| --- src/session.h     (revision 0)
| +++ src/session.h     (revision 0)
| @@ -0,0 +1,149 @@
| +// -*- 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:
| +public:
| +     /// 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(); }

I'd rather just return the containers (const &) instead of having all
these iterator functions.

| +
| +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
| +     };

I don't really like using enums for this, but I missing a better
alternative.

| -     /** Local constants.
| -         It is more portable among different C++ compilers to use
| -         an enum instead of #int const XXX#
| -     */

C++ compilers have grown up a bit since then.

| @@ -246,6 +247,8 @@
|       ascii_linelen = 65;
|       num_lastfiles = maxlastfiles;
|       check_lastfiles = true;
| +     use_lastfilepos = true;
| +     load_session = true;

This seems wrongly named.
but I am afraid that a good alternative might be a bit too long
'load_files_from_last_session' -- not really nice

| Index: src/lyxrc.h
| ===================================================================
| --- src/lyxrc.h       (revision 13486)
| +++ src/lyxrc.h       (working copy)
| @@ -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

sp: 'opening'

-- 
        Lgb

Reply via email to