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"
35 bool LyXVC::file_found_hook(string const & fn)
38 // Check if file is under RCS
39 if (!(found_file = RCS::find_file(fn)).empty()) {
40 vcs = new RCS(found_file);
44 // Check if file is under CVS
45 if (!(found_file = CVS::find_file(fn)).empty()) {
46 vcs = new CVS(found_file, fn);
50 // file is not under any VCS.
55 bool LyXVC::file_not_found_hook(string const & fn)
57 // Check if file is under RCS
58 if (!RCS::find_file(fn).empty())
60 if (!CVS::find_file(fn).empty())
66 void LyXVC::buffer(Buffer * buf)
72 void LyXVC::registrer()
74 string const filename = owner_->fileName();
76 // there must be a file to save
77 if (!IsFileReadable(filename)) {
78 Alert::alert(_("File not saved"),
79 _("You must save the file"),
80 _("before it can be registered."));
84 // it is very likely here that the vcs is not created yet...
86 string const cvs_entries = "CVS/Entries";
88 if (IsFileReadable(cvs_entries)) {
90 << "LyXVC: registering "
91 << MakeDisplayPath(filename)
92 << " with CVS" << endl;
93 vcs = new CVS(cvs_entries, filename);
97 << "LyXVC: registering "
98 << MakeDisplayPath(filename)
99 << " with RCS" << endl;
100 vcs = new RCS(filename);
106 // If the document is changed, we might want to save it
107 if (!vcs->owner()->isClean() &&
108 Alert::askQuestion(_("Changes in document:"),
109 MakeDisplayPath(filename, 50),
110 _("Save document and proceed?"))) {
111 vcs->owner()->getUser()->owner()
112 ->dispatch(FuncRequest(LFUN_MENUWRITE));
115 // Maybe the save fails, or we answered "no". In both cases,
116 // the document will be dirty, and we abort.
117 if (!vcs->owner()->isClean())
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;
127 Alert::alert(_("Info"),
128 _("This document has NOT been registered."));
132 vcs->registrer(tmp.second);
136 void LyXVC::checkIn()
138 // If the document is changed, we might want to save it
139 if (!vcs->owner()->isClean() &&
140 Alert::askQuestion(_("Changes in document:"),
141 MakeDisplayPath(vcs->owner()->fileName(), 50),
142 _("Save document and proceed?"))) {
143 vcs->owner()->getUser()->owner()
144 ->dispatch(FuncRequest(LFUN_MENUWRITE));
147 // Maybe the save fails, or we answered "no". In both cases,
148 // the document will be dirty, and we abort.
149 if (!vcs->owner()->isClean())
152 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
153 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
155 if (tmp.second.empty()) {
156 tmp.second = _("(no log message)");
158 vcs->checkIn(tmp.second);
160 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
165 void LyXVC::checkOut()
167 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
168 if (!vcs->owner()->isClean()
169 && !Alert::askQuestion(_("Changes in document:"),
170 MakeDisplayPath(vcs->owner()->fileName(), 50),
171 _("Ignore changes and proceed with check out?"))) {
182 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
183 // Here we should check if the buffer is dirty. And if it is
184 // we should warn the user that reverting will discard all
185 // changes made since the last check in.
186 if (Alert::askQuestion(_("When you revert, you will loose all changes made"),
187 _("to the document since the last check in."),
188 _("Do you still want to do it?"))) {
195 void LyXVC::undoLast()
201 void LyXVC::toggleReadOnly()
203 switch (vcs->status()) {
205 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
209 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
218 if (vcs) return true;
223 //string const & LyXVC::version() const
225 // return vcs->version();
228 string const LyXVC::versionString() const
230 return vcs->versionString();
234 string const & LyXVC::locker() const
236 return vcs->locker();
240 const string LyXVC::getLogFile() const
245 string tmpf = lyx::tempName(string(), "lyxvclog");
246 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;