]> git.lyx.org Git - lyx.git/blob - src/lastfiles.h
fix compilation; remove cruft in configure script (I may have removed too much, but...
[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-2001 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
21 #include "LString.h"
22 #include <boost/utility.hpp>
23
24 /** The latest documents loaded.
25     This class takes care of the last .lyx files used by the LyX user. It
26     both reads and writes this information to a file. The number of files
27     kept are user defined, but defaults to four.
28     @author Lars Gullik Bjønnes
29 */
30 class LastFiles : boost::noncopyable {
31 public:
32         ///
33         typedef std::deque<string> Files;
34
35         ///
36         typedef Files::const_iterator const_iterator;
37
38         /** Read the lastfiles file.
39             @param file The file to read the lastfiles form.
40             @param dostat Whether to check for file existance.
41             @param num number of files to remember.
42         */
43         explicit
44         LastFiles(string const & file,
45                   bool dostat = true, unsigned int num = 4);
46
47         /** Insert #file# into the list.
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             @param file the file to insert in the list.
53         */
54         void newFile(string const & file);
55         /** Writes the lastfiles table to disk.
56             Writes one file on each line, this way we can at least have
57             some special chars (e.g. space), but newline in filenames
58             are thus not allowed.
59             @param file the file we write the lastfiles list to.
60         */
61         void writeFile(string const & file) const;
62         /** Return file #n# in the lastfiles list.
63             @param n number in the list to get
64         */
65         string const operator[](unsigned int n) const;
66         /// Iterator to the beginning of the list.
67         Files::const_iterator begin() const { return files.begin(); }
68         /// Iterator to the end of the list.
69         Files::const_iterator end() const { return files.end(); }
70 private:
71         /** Local constants.
72             It is more portable among different C++ compilers to use
73             an enum instead of #int const XXX#
74         */
75         enum local_constants {
76                 /// Default number of lastfiles.
77                 DEFAULTFILES = 4,
78                 /** Max number of lastfiles.
79                     There is no point in keeping more than this number
80                     of files at the same time. However perhaps someday
81                     someone finds use for more files and wants to
82                     change it. Please do. But don't show the files in
83                     a menu...
84                 */
85                 ABSOLUTEMAXLASTFILES = 20
86         };
87
88         /// a list of lastfiles
89         Files files;
90         /// number of files in the lastfiles list.
91         unsigned int num_files;
92         /// check for file existance or not.
93         bool dostat;
94
95         /** Read the lastfiles file.
96             Reads the #.lyx_lastfiles# at the beginning of the LyX session.
97             This will read the lastfiles file (usually #.lyx_lastfiles#). It
98             will normally discard files that don't exist anymore, unless
99             LastFiles has been initialized with #dostat = false#.
100             @param file the file containing the lastfiles.
101         */
102         void readFile(string const & file);
103         /** Used by the constructor to set the number of stored last files.
104             @param num the number of lastfiles to set.
105         */
106         void setNumberOfFiles(unsigned int num);
107 };
108 #endif