3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
8 * \author Angus Leeming
10 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
19 #include "vc-backend.h"
24 #include "frontends/Alert.h"
26 #include "support/filetools.h"
27 #include "support/lyxlib.h"
30 using namespace lyx::support;
49 bool LyXVC::file_found_hook(string const & fn)
52 // Check if file is under RCS
53 if (!(found_file = RCS::find_file(fn)).empty()) {
54 vcs = new RCS(found_file);
58 // Check if file is under CVS
59 if (!(found_file = CVS::find_file(fn)).empty()) {
60 vcs = new CVS(found_file, fn);
64 // file is not under any VCS.
69 bool LyXVC::file_not_found_hook(string const & fn)
71 // Check if file is under RCS
72 if (!RCS::find_file(fn).empty())
74 if (!CVS::find_file(fn).empty())
80 void LyXVC::buffer(Buffer * buf)
86 void LyXVC::registrer()
88 string const filename = owner_->fileName();
90 // there must be a file to save
91 if (!IsFileReadable(filename)) {
92 Alert::error(_("Document not saved"),
93 _("You must save the document "
94 "before it can be registered."));
98 // it is very likely here that the vcs is not created yet...
100 string const cvs_entries = "CVS/Entries";
102 if (IsFileReadable(cvs_entries)) {
104 << "LyXVC: registering "
105 << MakeDisplayPath(filename)
106 << " with CVS" << endl;
107 vcs = new CVS(cvs_entries, filename);
111 << "LyXVC: registering "
112 << MakeDisplayPath(filename)
113 << " with RCS" << endl;
114 vcs = new RCS(filename);
120 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
121 pair<bool, string> tmp =
122 Alert::askForText(_("LyX VC: Initial description"),
123 _("(no initial description)"));
124 if (!tmp.first || tmp.second.empty()) {
125 // should we insist on checking tmp.second.empty()?
126 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
130 vcs->registrer(tmp.second);
134 void LyXVC::checkIn()
137 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
138 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
140 if (tmp.second.empty()) {
141 tmp.second = _("(no log message)");
143 vcs->checkIn(tmp.second);
145 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
150 void LyXVC::checkOut()
152 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
160 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
162 string const file = MakeDisplayPath(owner_->fileName(), 20);
163 string text = bformat(_("Reverting to the stored version of the "
164 "document %1$s will lose all current changes.\n\n"
165 "Do you want to revert to the saved version?"), file);
166 int const ret = Alert::prompt(_("Revert to stored version of document?"),
167 text, 0, 1, _("&Revert"), _("&Cancel"));
174 void LyXVC::undoLast()
180 void LyXVC::toggleReadOnly()
182 switch (vcs->status()) {
184 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
188 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
197 if (vcs) return true;
202 //string const & LyXVC::version() const
204 // return vcs->version();
207 string const LyXVC::versionString() const
209 return vcs->versionString();
213 string const & LyXVC::locker() const
215 return vcs->locker();
219 string const LyXVC::getLogFile() const
224 string tmpf = tempName(string(), "lyxvclog");
225 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;