]> git.lyx.org Git - lyx.git/blob - src/LyXVC.h
Update my email and status.
[lyx.git] / src / LyXVC.h
1 // -*- C++ -*-
2 /**
3  * \file LyXVC.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef LYX_VC_H
13 #define LYX_VC_H
14
15 #include <boost/scoped_ptr.hpp>
16
17 #include <string>
18
19
20 namespace lyx {
21
22 namespace support { class FileName; }
23
24 class VCS;
25 class Buffer;
26
27 /** Version Control for LyX.
28     This is the class giving the version control features to LyX. It is
29     intended to support different kinds of version control.
30     The support in LyX is based loosely upon the version control in GNU Emacs,
31     but is not as extensive as that one. See Extended Manual for a simple
32     tutorial and manual for the use of the version control system in LyX.
33
34     LyXVC use this algorithm when it searches for VC files:
35     for RCS it searches for <filename>,v and RCS/<filename>,v similarly
36     CVS/Entries for cvs and .svn/entries. By doing this there doesn't need to be any
37     special support for VC in the lyx format, and this is especially good
38     when the lyx format will be a subset of LaTeX.
39 */
40 class LyXVC {
41 public:
42         ///
43         LyXVC();
44         ///
45         ~LyXVC();
46         /// Is \p fn under version control?
47         static bool fileInVC(support::FileName const & fn);
48         /** Not a good name perhaps. This function should be called whenever
49           LyX loads a file. This function then checks for a master VC file (for
50           RCS this is *,v or RCS/ *,v ; for CVS this is CVS/Entries and .svn/entries
51           for SVN) if this file or entry is found, the loaded file is assumed to be
52           under control by VC, and the appropiate actions is taken.
53           Returns true if the file is under control by a VCS.
54           */
55         bool file_found_hook(support::FileName const & fn);
56
57         /** Is \p fn under version control?
58           This function should be run when a file is requested for loading,
59           but it does not exist. This function will then check for a VC master
60           file with the same name (see above function). If this exists the
61           user should be asked if he/her wants to checkout a version for
62           viewing/editing. Returns true if the file is under control by a VCS
63           and the user wants to view/edit it.
64           */
65         static bool file_not_found_hook(support::FileName const & fn);
66
67         ///
68         void setBuffer(Buffer *);
69
70         /// Register the document as a VC file.
71         bool registrer();
72
73
74         // std::string used as a return value in functions below are
75         // workaround to defer messages to be displayed in UI. If message()
76         // is used directly, message string is immediately overwritten
77         // by the next multiple messages on the top of the processed dispatch
78         // machinery.
79
80         /// Unlock and commit changes. Returns log.
81         std::string checkIn();
82         /// Does the current VC supports this operation?
83         bool checkInEnabled() const;
84
85         /// Lock/update and prepare to edit document. Returns log.
86         std::string checkOut();
87         /// Does the current VC supports this operation?
88         bool checkOutEnabled() const;
89
90         /// Synchronize the whole archive with repository
91         std::string repoUpdate();
92         /// Does the current VC supports this operation?
93         bool repoUpdateEnabled() const;
94
95         /**
96          * Toggle locking property of the edited file,
97          * i.e. whether the file uses locking mechanism.
98          */
99         std::string lockingToggle();
100         /// Does the current VC support this operation?
101         bool lockingToggleEnabled() const;
102
103         /// Revert to last version
104         bool revert();
105
106         /// Undo last check-in.
107         void undoLast();
108         /// Does the current VC supports this operation?
109         bool undoLastEnabled() const;
110         /**
111          * Prepare revision rev of the file into newly created temporary file
112          * and save the filename into parameter f.
113          * Parameter rev can be either revision number or negative number
114          * which is interpreted as how many revision back from the current
115          * one do we want. rev=0 is reserved for the last (committed) revision.
116          * We need rev to be string, since in various VCS revision is not integer.
117          * If RCS addressed by a single number, it is automatically used
118          * as the last number in the whole revision specification (it applies
119          * for retrieving normal revisions (rev>0) or backtracking (rev<0).
120          */
121         bool prepareFileRevision(std::string const & rev, std::string & f);
122         /// Does the current VC supports this operation?
123         bool prepareFileRevisionEnabled();
124
125         /**
126          * Generate a log file and return the filename.
127          * It is the caller's responsibility to remove the
128          * file after use.
129          */
130         const std::string getLogFile() const;
131
132         /**
133          * We do not support this generally. In RCS/SVN file read-only flag
134          * is often connected with locking state and one has to be careful to
135          * keep things in synchro once we would allow user to toggle
136          * read-only flags.
137          */
138         void toggleReadOnly();
139
140         /// Is the document under administration by VCS?
141         bool inUse() const;
142
143         /// Returns the RCS + version number for messages
144         std::string const versionString() const;
145
146         /**
147          * Returns whether we use locking for the given file.
148          */
149         bool locking() const;
150
151         // type of the revision information
152         enum RevisionInfo {
153                 Unknown = 0,
154                 File = 1,
155                 Tree = 2,
156                 Author = 3,
157                 Date = 4,
158                 Time = 5
159         };
160
161         /**
162          * Return revision info specified by the argument.
163          * Its safe to call it regardless VCS is in usage or this
164          * info is (un)available. Returns empty string in such a case.
165          */
166         std::string revisionInfo(RevisionInfo const info) const;
167
168 private:
169         ///
170         Buffer * owner_;
171
172         ///
173         boost::scoped_ptr<VCS> vcs;
174 };
175
176
177 } // namespace lyx
178
179 #endif