4 #include "vc-backend.h"
7 #include "BufferView.h"
9 #include "funcrequest.h"
11 #include "frontends/Alert.h"
12 #include "frontends/LyXView.h"
14 #include "support/filetools.h"
15 #include "support/lyxlib.h"
22 /* WARNING: Several of the vcs-> methods end up
23 * deleting this object via BufferView::reload() !
39 bool LyXVC::file_found_hook(string const & fn)
42 // Check if file is under RCS
43 if (!(found_file = RCS::find_file(fn)).empty()) {
44 vcs = new RCS(found_file);
48 // Check if file is under CVS
49 if (!(found_file = CVS::find_file(fn)).empty()) {
50 vcs = new CVS(found_file, fn);
54 // file is not under any VCS.
59 bool LyXVC::file_not_found_hook(string const & fn)
61 // Check if file is under RCS
62 if (!RCS::find_file(fn).empty())
64 if (!CVS::find_file(fn).empty())
70 void LyXVC::buffer(Buffer * buf)
76 void LyXVC::registrer()
78 string const filename = owner_->fileName();
80 // there must be a file to save
81 if (!IsFileReadable(filename)) {
82 Alert::alert(_("File not saved"),
83 _("You must save the file"),
84 _("before it can be registered."));
88 // it is very likely here that the vcs is not created yet...
90 string const cvs_entries = "CVS/Entries";
92 if (IsFileReadable(cvs_entries)) {
94 << "LyXVC: registering "
95 << MakeDisplayPath(filename)
96 << " with CVS" << endl;
97 vcs = new CVS(cvs_entries, filename);
101 << "LyXVC: registering "
102 << MakeDisplayPath(filename)
103 << " with RCS" << endl;
104 vcs = new RCS(filename);
110 // If the document is changed, we might want to save it
111 if (!vcs->owner()->isClean() &&
112 Alert::askQuestion(_("Changes in document:"),
113 MakeDisplayPath(filename, 50),
114 _("Save document and proceed?"))) {
115 vcs->owner()->getUser()->owner()
116 ->dispatch(FuncRequest(LFUN_MENUWRITE));
119 // Maybe the save fails, or we answered "no". In both cases,
120 // the document will be dirty, and we abort.
121 if (!vcs->owner()->isClean())
124 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
125 pair<bool, string> tmp =
126 Alert::askForText(_("LyX VC: Initial description"),
127 _("(no initial description)"));
128 if (!tmp.first || tmp.second.empty()) {
129 // should we insist on checking tmp.second.empty()?
130 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
131 Alert::alert(_("Info"),
132 _("This document has NOT been registered."));
136 vcs->registrer(tmp.second);
140 void LyXVC::checkIn()
142 // If the document is changed, we might want to save it
143 if (!vcs->owner()->isClean() &&
144 Alert::askQuestion(_("Changes in document:"),
145 MakeDisplayPath(vcs->owner()->fileName(), 50),
146 _("Save document and proceed?"))) {
147 vcs->owner()->getUser()->owner()
148 ->dispatch(FuncRequest(LFUN_MENUWRITE));
151 // Maybe the save fails, or we answered "no". In both cases,
152 // the document will be dirty, and we abort.
153 if (!vcs->owner()->isClean())
156 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
157 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
159 if (tmp.second.empty()) {
160 tmp.second = _("(no log message)");
162 vcs->checkIn(tmp.second);
164 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
169 void LyXVC::checkOut()
171 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
172 if (!vcs->owner()->isClean()
173 && !Alert::askQuestion(_("Changes in document:"),
174 MakeDisplayPath(vcs->owner()->fileName(), 50),
175 _("Ignore changes and proceed with check out?"))) {
185 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
186 // Here we should check if the buffer is dirty. And if it is
187 // we should warn the user that reverting will discard all
188 // changes made since the last check in.
189 if (Alert::askQuestion(_("When you revert, you will loose all changes made"),
190 _("to the document since the last check in."),
191 _("Do you still want to do it?"))) {
198 void LyXVC::undoLast()
204 void LyXVC::toggleReadOnly()
206 switch (vcs->status()) {
208 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
212 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
221 if (vcs) return true;
226 //string const & LyXVC::version() const
228 // return vcs->version();
231 string const LyXVC::versionString() const
233 return vcs->versionString();
237 string const & LyXVC::locker() const
239 return vcs->locker();
243 const string LyXVC::getLogFile() const
248 string tmpf = lyx::tempName(string(), "lyxvclog");
249 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;