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"
29 using lyx::support::bformat;
30 using lyx::support::IsFileReadable;
31 using lyx::support::MakeDisplayPath;
32 using lyx::support::tempName;
52 bool LyXVC::file_found_hook(string const & fn)
55 // Check if file is under RCS
56 if (!(found_file = RCS::find_file(fn)).empty()) {
57 vcs = new RCS(found_file);
61 // Check if file is under CVS
62 if (!(found_file = CVS::find_file(fn)).empty()) {
63 vcs = new CVS(found_file, fn);
67 // file is not under any VCS.
72 bool LyXVC::file_not_found_hook(string const & fn)
74 // Check if file is under RCS
75 if (!RCS::find_file(fn).empty())
77 if (!CVS::find_file(fn).empty())
83 void LyXVC::buffer(Buffer * buf)
89 void LyXVC::registrer()
91 string const filename = owner_->fileName();
93 // there must be a file to save
94 if (!IsFileReadable(filename)) {
95 Alert::error(_("Document not saved"),
96 _("You must save the document "
97 "before it can be registered."));
101 // it is very likely here that the vcs is not created yet...
103 string const cvs_entries = "CVS/Entries";
105 if (IsFileReadable(cvs_entries)) {
107 << "LyXVC: registering "
108 << MakeDisplayPath(filename)
109 << " with CVS" << endl;
110 vcs = new CVS(cvs_entries, filename);
114 << "LyXVC: registering "
115 << MakeDisplayPath(filename)
116 << " with RCS" << endl;
117 vcs = new RCS(filename);
123 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
124 pair<bool, string> tmp =
125 Alert::askForText(_("LyX VC: Initial description"),
126 _("(no initial description)"));
127 if (!tmp.first || tmp.second.empty()) {
128 // should we insist on checking tmp.second.empty()?
129 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
133 vcs->registrer(tmp.second);
137 void LyXVC::checkIn()
140 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
141 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
143 if (tmp.second.empty()) {
144 tmp.second = _("(no log message)");
146 vcs->checkIn(tmp.second);
148 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
153 void LyXVC::checkOut()
155 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
163 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
165 string const file = MakeDisplayPath(owner_->fileName(), 20);
166 string text = bformat(_("Reverting to the stored version of the "
167 "document %1$s will lose all current changes.\n\n"
168 "Do you want to revert to the saved version?"), file);
169 int const ret = Alert::prompt(_("Revert to stored version of document?"),
170 text, 0, 1, _("&Revert"), _("&Cancel"));
177 void LyXVC::undoLast()
183 void LyXVC::toggleReadOnly()
185 switch (vcs->status()) {
187 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
191 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
200 if (vcs) return true;
205 //string const & LyXVC::version() const
207 // return vcs->version();
210 string const LyXVC::versionString() const
212 return vcs->versionString();
216 string const & LyXVC::locker() const
218 return vcs->locker();
222 string const LyXVC::getLogFile() const
227 string tmpf = tempName(string(), "lyxvclog");
228 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;