8 #include "vc-backend.h"
11 #include "BufferView.h"
16 #include "frontends/Alert.h"
18 #include "support/filetools.h"
19 #include "support/lyxlib.h"
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 // it is very likely here that the vcs is not created yet...
80 string const cvs_entries = "CVS/Entries";
82 if (IsFileReadable(cvs_entries)) {
84 << "LyXVC: registering "
85 << MakeDisplayPath(owner_->fileName())
86 << " with CVS" << endl;
87 vcs = new CVS(cvs_entries, owner_->fileName());
91 << "LyXVC: registering "
92 << MakeDisplayPath(owner_->fileName())
93 << " with RCS" << endl;
94 vcs = new RCS(owner_->fileName());
100 // If the document is changed, we might want to save it
101 if (!vcs->owner()->isLyxClean() &&
102 Alert::askQuestion(_("Changes in document:"),
103 MakeDisplayPath(vcs->owner()->fileName(), 50),
104 _("Save document and proceed?"))) {
105 vcs->owner()->getUser()->owner()
106 ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
109 // Maybe the save fails, or we answered "no". In both cases,
110 // the document will be dirty, and we abort.
111 if (!vcs->owner()->isLyxClean()) {
115 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
116 pair<bool, string> tmp =
117 Alert::askForText(_("LyX VC: Initial description"),
118 _("(no initial description)"));
119 if (!tmp.first || tmp.second.empty()) {
120 // should we insist on checking tmp.second.empty()?
121 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
122 Alert::alert(_("Info"),
123 _("This document has NOT been registered."));
127 vcs->registrer(tmp.second);
131 void LyXVC::checkIn()
133 // If the document is changed, we might want to save it
134 if (!vcs->owner()->isLyxClean() &&
135 Alert::askQuestion(_("Changes in document:"),
136 MakeDisplayPath(vcs->owner()->fileName(), 50),
137 _("Save document and proceed?"))) {
138 vcs->owner()->getUser()->owner()
139 ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
142 // Maybe the save fails, or we answered "no". In both cases,
143 // the document will be dirty, and we abort.
144 if (!vcs->owner()->isLyxClean()) {
148 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
149 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
151 if (tmp.second.empty()) {
152 tmp.second = _("(no log message)");
154 vcs->checkIn(tmp.second);
156 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
161 void LyXVC::checkOut()
163 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
164 if (!vcs->owner()->isLyxClean()
165 && !Alert::askQuestion(_("Changes in document:"),
166 MakeDisplayPath(vcs->owner()->fileName(), 50),
167 _("Ignore changes and proceed with check out?"))) {
178 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
179 // Here we should check if the buffer is dirty. And if it is
180 // we should warn the user that reverting will discard all
181 // changes made since the last check in.
182 if (Alert::askQuestion(_("When you revert, you will loose all changes made"),
183 _("to the document since the last check in."),
184 _("Do you still want to do it?"))) {
191 void LyXVC::undoLast()
197 void LyXVC::toggleReadOnly()
199 switch (vcs->status()) {
201 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
205 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
214 if (vcs) return true;
219 //string const & LyXVC::version() const
221 // return vcs->version();
224 string const LyXVC::versionString() const
226 return vcs->versionString();
230 string const & LyXVC::locker() const
232 return vcs->locker();
236 const string LyXVC::getLogFile() const
241 string tmpf = lyx::tempName(string(), "lyxvclog");
242 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;