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