]> git.lyx.org Git - lyx.git/blob - src/LyXVC.cpp
remove unused code
[lyx.git] / src / LyXVC.cpp
1 /**
2  * \file LyXVC.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author Angus Leeming
9  * \author John Levon
10  * \author André Pönitz
11  * \author Allan Rae
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #include <config.h>
17
18 #include "LyXVC.h"
19 #include "VCBackend.h"
20 #include "Buffer.h"
21
22 #include "frontends/alert.h"
23
24 #include "support/debug.h"
25 #include "support/filetools.h"
26 #include "support/gettext.h"
27 #include "support/lstrings.h"
28
29 using namespace std;
30 using namespace lyx::support;
31
32 namespace lyx {
33
34 namespace Alert = frontend::Alert;
35
36
37 LyXVC::LyXVC()
38 {
39         owner_ = 0;
40 }
41
42
43 // for the sake of boost::scoped_ptr
44 LyXVC::~LyXVC()
45 {}
46
47
48 bool LyXVC::file_found_hook(FileName const & fn)
49 {
50         FileName found_file;
51         // Check if file is under RCS
52         if (!(found_file = RCS::findFile(fn)).empty()) {
53                 vcs.reset(new RCS(found_file));
54                 vcs->owner(owner_);
55                 return true;
56         }
57         // Check if file is under CVS
58         if (!(found_file = CVS::findFile(fn)).empty()) {
59                 vcs.reset(new CVS(found_file, fn));
60                 vcs->owner(owner_);
61                 return true;
62         }
63         // file is not under any VCS.
64         return false;
65 }
66
67
68 bool LyXVC::file_not_found_hook(FileName const & fn)
69 {
70         // Check if file is under RCS
71         if (!RCS::findFile(fn).empty())
72                 return true;
73         if (!CVS::findFile(fn).empty())
74                 return true;
75         return false;
76 }
77
78
79 void LyXVC::setBuffer(Buffer * buf)
80 {
81         owner_ = buf;
82 }
83
84
85 void LyXVC::registrer()
86 {
87         FileName const filename = owner_->fileName();
88
89         // there must be a file to save
90         if (!filename.isReadableFile()) {
91                 Alert::error(_("Document not saved"),
92                              _("You must save the document "
93                                             "before it can be registered."));
94                 return;
95         }
96
97         // it is very likely here that the vcs is not created yet...
98         if (!vcs) {
99                 FileName const cvs_entries(makeAbsPath("CVS/Entries"));
100
101                 if (cvs_entries.isReadableFile()) {
102                         LYXERR(Debug::LYXVC, "LyXVC: registering "
103                                 << to_utf8(filename.displayName()) << " with CVS");
104                         vcs.reset(new CVS(cvs_entries, filename));
105
106                 } else {
107                         LYXERR(Debug::LYXVC, "LyXVC: registering "
108                                 << to_utf8(filename.displayName()) << " with RCS");
109                         vcs.reset(new RCS(filename));
110                 }
111
112                 vcs->owner(owner_);
113         }
114
115         LYXERR(Debug::LYXVC, "LyXVC: registrer");
116         docstring response;
117         bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
118                         _("(no initial description)"));
119         if (!ok || response.empty()) {
120                 // should we insist on checking response.empty()?
121                 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
122                 return;
123         }
124
125         vcs->registrer(to_utf8(response));
126 }
127
128
129 void LyXVC::checkIn()
130 {
131         LYXERR(Debug::LYXVC, "LyXVC: checkIn");
132         docstring response;
133         bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
134         if (ok) {
135                 if (response.empty())
136                         response = _("(no log message)");
137                 vcs->checkIn(to_utf8(response));
138         } else {
139                 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
140         }
141 }
142
143
144 void LyXVC::checkOut()
145 {
146         LYXERR(Debug::LYXVC, "LyXVC: checkOut");
147         vcs->checkOut();
148 }
149
150
151 void LyXVC::revert()
152 {
153         LYXERR(Debug::LYXVC, "LyXVC: revert");
154
155         docstring const file = owner_->fileName().displayName(20);
156         docstring text = bformat(_("Reverting to the stored version of the "
157                 "document %1$s will lose all current changes.\n\n"
158                                              "Do you want to revert to the saved version?"), file);
159         int const ret = Alert::prompt(_("Revert to stored version of document?"),
160                 text, 0, 1, _("&Revert"), _("&Cancel"));
161
162         if (ret == 0)
163                 vcs->revert();
164 }
165
166
167 void LyXVC::undoLast()
168 {
169         vcs->undoLast();
170 }
171
172
173 void LyXVC::toggleReadOnly()
174 {
175         switch (vcs->status()) {
176         case VCS::UNLOCKED:
177                 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
178                 checkOut();
179                 break;
180         case VCS::LOCKED:
181                 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
182                 checkIn();
183                 break;
184         }
185 }
186
187
188 bool LyXVC::inUse()
189 {
190         if (vcs)
191                 return true;
192         return false;
193 }
194
195
196 //string const & LyXVC::version() const
197 //{
198 //      return vcs->version();
199 //}
200
201
202 string const LyXVC::versionString() const
203 {
204         return vcs->versionString();
205 }
206
207
208 string const & LyXVC::locker() const
209 {
210         return vcs->locker();
211 }
212
213
214 string const LyXVC::getLogFile() const
215 {
216         if (!vcs)
217                 return string();
218
219         FileName const tmpf = FileName::tempName("lyxvclog");
220         if (tmpf.empty()) {
221                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
222                 return string();
223         }
224         LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
225         vcs->getLog(tmpf);
226         return tmpf.absFilename();
227 }
228
229
230 } // namespace lyx