]> git.lyx.org Git - lyx.git/blob - src/LyXVC.h
* Get rid of LFUN_TOC_INSERT: we use LFUN_INSET_INSERT "toc".
[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 verison 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         /** Not a good name perhaps. This function should be called whenever
47           LyX loads a file. This function then checks for a master VC file (for
48           RCS this is *,v or RCS/ *,v ; for CVS this is CVS/Entries and .svn/entries
49           for SVN) if this file or entry is found, the loaded file is assumed to be
50           under controll by VC, and the appropiate actions is taken.
51           Returns true if the file is under control by a VCS.
52           */
53         bool file_found_hook(support::FileName const & fn);
54
55         /** This function should be run when a file is requested for loading,
56           but it does not exist. This function will then check for a VC master
57           file with the same name (see above function). If this exists the
58           user should be asked if he/her wants to checkout a version for
59           viewing/editing. Returns true if the file is under control by a VCS
60           and the user wants to view/edit it.
61           */
62         static bool file_not_found_hook(support::FileName const & fn);
63
64         ///
65         void setBuffer(Buffer *);
66
67         /// Register the document as an VC file.
68         bool registrer();
69
70
71         // std::string used as a return value in functions below are
72         // workaround to defer messages to be displayed in UI. If message()
73         // is used directly, message string is immediately overwritten
74         // by the next multiple messages on the top of the processed dispatch
75         // machinery.
76
77         /// Unlock and commit changes. Returns log.
78         std::string checkIn();
79         /// Does the current VC supports this operation?
80         bool checkInEnabled() const;
81
82         /// Lock/update and prepare to edit document. Returns log.
83         std::string checkOut();
84         /// Does the current VC supports this operation?
85         bool checkOutEnabled() const;
86
87         /// Synchronize the whole archive with repository
88         std::string repoUpdate();
89         /// Does the current VC supports this operation?
90         bool repoUpdateEnabled() const;
91
92         /**
93          * Toggle locking property of the edited file,
94          * i.e. whether the file uses locking mechanism.
95          */
96         std::string lockingToggle();
97         /// Does the current VC support this operation?
98         bool lockingToggleEnabled() const;
99
100         /// Revert to last version
101         void revert();
102
103         /// Undo last check-in.
104         void undoLast();
105         /// Does the current VC supports this operation?
106         bool undoLastEnabled() const;
107         /**
108          * Prepare revision rev of the file into newly created temporary file
109          * and save the filename into parameter f.
110          * Parameter rev can be either revision number or negative number
111          * which is interpreted as how many revision back from the current
112          * one do we want. rev=0 is reserved for the last (committed) revision.
113          * We need rev to be string, since in various VCS revision is not integer.
114          * If RCS addressed by a single number, it is automatically used
115          * as the last number in the whole revision specification (it applies
116          * for retrieving normal revisions (rev>0) or backtracking (rev<0).
117          */
118         bool prepareFileRevision(std::string const & rev, std::string & f);
119         /// Does the current VC supports this operation?
120         bool prepareFileRevisionEnabled();
121
122         /**
123          * Generate a log file and return the filename.
124          * It is the caller's responsibility to remove the
125          * file after use.
126          */
127         const std::string getLogFile() const;
128
129         /**
130          * We do not support this generally. In RCS/SVN file read-only flag
131          * is often connected with locking state and one has to be careful to
132          * keep things in synchro once we would allow user to toggle
133          * read-only flags.
134          */
135         void toggleReadOnly();
136
137         /// Is the document under administration by VCS?
138         bool inUse() const;
139
140         /// Returns the RCS + version number for messages
141         std::string const versionString() const;
142
143         /**
144          * Returns whether we use locking for the given file.
145          */
146         bool locking() const;
147
148         // type of the revision information
149         enum RevisionInfo {
150                 Unknown = 0,
151                 File = 1,
152                 Tree = 2,
153                 Author = 3,
154                 Date = 4,
155                 Time = 5
156         };
157
158         /**
159          * Return revision info specified by the argument.
160          * Its safe to call it regardless VCS is in usage or this
161          * info is (un)available. Returns empty string in such a case.
162          */
163         std::string revisionInfo(RevisionInfo const info) const;
164
165 private:
166         ///
167         Buffer * owner_;
168
169         ///
170         boost::scoped_ptr<VCS> vcs;
171 };
172
173
174 } // namespace lyx
175
176 #endif