]> git.lyx.org Git - lyx.git/blob - src/lastfiles.h
9faf6b88a56feac8b1a75121e17e38bcfe963993
[lyx.git] / src / lastfiles.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-1999 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef LASTFILES_H
13 #define LASTFILES_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include <deque>
20 using std::deque;
21
22 #include "LString.h"
23
24
25 /** The latest documents loaded
26     This class takes care of the last .lyx files used by the LyX user. It
27     both reads and writes this information to a file. The number of files
28     kept are user defined, but defaults to four.
29 */
30 class LastFiles 
31 {
32 public:
33         ///
34         typedef deque<string> Files;
35
36         /**@name Constructors and Deconstructors */
37         //@{
38         /**
39            Parameters are: name of file to read. Whether LastFiles should
40            check for file existance, and the number of files to remember.
41         */
42         LastFiles(string const &, bool dostat = true, unsigned int num = 4);
43         //@}
44         
45         /**@name Methods */
46         //@{
47         /**
48            This funtion inserts #file# into the last files list. If the file
49            already exist it is moved to the top of the list, else exist it
50            is placed on the top of the list. If the list is full the last
51            file in the list is popped from the end.
52         */
53         void newFile(string const &);
54         /**  Writes the lastfiles table to disk. One file on each line, this
55              way we can at least have some special chars (e.g. space), but
56              newline in filenames are thus not allowed.
57         */
58         void writeFile(string const &) const;
59         ///
60         string operator[](unsigned int) const;
61         ///
62         Files::const_iterator begin() const { return files.begin(); }
63         ///
64         Files::const_iterator end() const { return files.end(); }
65         //@}
66 private:
67         /**@name const variables */
68         //@{
69         enum {
70                 ///
71                 DEFAULTFILES = 4,
72                 /** There is no point in keeping more than this number
73                     of files at the same time. However perhaps someday
74                     someone finds use for more files and wants to
75                     change it. Please do. But don't show the files in
76                     a menu...
77                 */
78                 ABSOLUTEMAXLASTFILES = 20
79         };
80         //@}
81         
82         /**@name Variables */
83         //@{
84         /// a list of lastfiles
85         Files files;
86         /// number of files in the lastfiles list.
87         unsigned int num_files;
88         /// check for file existance or not.
89         bool dostat;
90         //@}
91         
92         /**@name Methods */
93         //@{
94         /** reads the .lyx_lastfiles at the beginning of the LyX session.
95             This will read the lastfiles file (usually .lyx_lastfiles). It
96             will normally discard files that don't exist anymore, unless
97             LastFiles has been initialized with dostat = false. 
98         */
99         void readFile(string const &);
100         /// used by the constructor to set the number of stored last files.
101         void setNumberOfFiles(unsigned int num);
102         //@}
103 };
104 #endif