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