]> git.lyx.org Git - lyx.git/blob - src/lastfiles.h
removed a warning from screen and added CFLAGS in lyx.spec.in.
[lyx.git] / src / lastfiles.h
1 // -*- C++ -*-
2 /* This file is part of
3 * ======================================================
4
5 *           LyX, The Document Processor
6 *        
7 *           Copyright (C) 1995 1996 Matthias Ettrich
8 *           and 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 "LString.h"
20
21
22 /** The latest documents loaded
23   This class takes care of the last .lyx files used by the LyX user. It
24   both reads and writes this information to a file. The number of files
25   kept are user defined, but defaults to four.
26 */
27 class LastFiles 
28 {
29 public:
30         /**@name Constructors and Deconstructors */
31         //@{
32         /**
33           Parameters are: name of file to read. Whether you want LastFiles 
34           to check for file existance, and the number of files to remember.
35           */
36         LastFiles(string const &, bool dostat = true, char num = 4);
37         ///
38         ~LastFiles();
39         //@}
40
41         /**@name Methods */
42         //@{
43         /**
44           This funtion inserts #file# into the last files list. If the file
45           already exist it is moved to the top of the list. If it don't
46           exist it is placed on the top of the list. If the list already is
47           full the last visited file in the list is puched out and deleted.
48          */
49         void newFile(string const &);
50         /**  Writes the lastfiles table to disk. A " is placed around the
51           filenames to preserve special chars. (not all are preserved
52           anyway, but at least space is.)
53           */
54         void writeFile(string const &) const;
55         //@}
56 private:
57         /**@name const variables */
58         //@{
59         /// 
60         enum {
61                 ///
62                 DEFAULTFILES = 4
63         };
64         /** There is no point in keeping more than this number of files
65           at the same time. However perhaps someday someone finds use for
66           more files and wants to change it. Please do. But don't show
67           the files in a menu...
68           */
69         enum {
70                 ///
71                 ABSOLUTEMAXLASTFILES = 20
72         };
73         //@}
74
75         /**@name Variables */
76         //@{
77         /// an array of lastfiles
78         string *files;
79         /// number of files in the lastfiles list.
80         char num_files;
81         /// check for file existance or not.
82         bool dostat;
83         //@}
84         
85         /**@name Methods */
86         //@{
87         /** reads the .lyx_lastfiles at the beginning of the LyX session.
88           This will read the lastfiles file (usually .lyx_lastfiles). It
89           will normally discard files that don't exist anymore, unless
90           LastFiles has been initialized with dostat = false. 
91          */
92         void readFile(string const &);
93         /// used by the constructor to set the number of stored last files.
94         void setNumberOfFiles(char num);
95         //@}
96
97         /**@name Friends */
98         //@{
99         ///
100         friend class LastFiles_Iter;
101         //@}
102 };
103
104
105 /// An Iterator class for LastFiles
106 class LastFiles_Iter {
107 public:
108         ///
109         LastFiles_Iter(const LastFiles& la)
110         {cs = &la; index = 0;}
111         ///
112         string operator() ()
113         {
114                 return (index < cs->num_files)? cs->files[index++] 
115                                                 : string();
116         }
117         ///
118         string operator[] (int a)
119         { return cs->files[a];}
120 private:
121         ///
122         const LastFiles *cs;
123         ///
124         char index;
125 };
126
127 #endif