8 #include "vc-backend.h"
11 #include "BufferView.h"
15 #include "frontends/Alert.h"
16 #include "frontends/LyXView.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 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()->isLyxClean() &&
112 Alert::askQuestion(_("Changes in document:"),
113 MakeDisplayPath(filename, 50),
114 _("Save document and proceed?"))) {
115 vcs->owner()->getUser()->owner()
116 ->getLyXFunc()->dispatch(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()->isLyxClean()) {
125 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
126 pair<bool, string> tmp =
127 Alert::askForText(_("LyX VC: Initial description"),
128 _("(no initial description)"));
129 if (!tmp.first || tmp.second.empty()) {
130 // should we insist on checking tmp.second.empty()?
131 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
132 Alert::alert(_("Info"),
133 _("This document has NOT been registered."));
137 vcs->registrer(tmp.second);
141 void LyXVC::checkIn()
143 // If the document is changed, we might want to save it
144 if (!vcs->owner()->isLyxClean() &&
145 Alert::askQuestion(_("Changes in document:"),
146 MakeDisplayPath(vcs->owner()->fileName(), 50),
147 _("Save document and proceed?"))) {
148 vcs->owner()->getUser()->owner()
149 ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
152 // Maybe the save fails, or we answered "no". In both cases,
153 // the document will be dirty, and we abort.
154 if (!vcs->owner()->isLyxClean()) {
158 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
159 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
161 if (tmp.second.empty()) {
162 tmp.second = _("(no log message)");
164 vcs->checkIn(tmp.second);
166 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
171 void LyXVC::checkOut()
173 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
174 if (!vcs->owner()->isLyxClean()
175 && !Alert::askQuestion(_("Changes in document:"),
176 MakeDisplayPath(vcs->owner()->fileName(), 50),
177 _("Ignore changes and proceed with check out?"))) {
188 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
189 // Here we should check if the buffer is dirty. And if it is
190 // we should warn the user that reverting will discard all
191 // changes made since the last check in.
192 if (Alert::askQuestion(_("When you revert, you will loose all changes made"),
193 _("to the document since the last check in."),
194 _("Do you still want to do it?"))) {
201 void LyXVC::undoLast()
207 void LyXVC::toggleReadOnly()
209 switch (vcs->status()) {
211 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
215 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
224 if (vcs) return true;
229 //string const & LyXVC::version() const
231 // return vcs->version();
234 string const LyXVC::versionString() const
236 return vcs->versionString();
240 string const & LyXVC::locker() const
242 return vcs->locker();
246 const string LyXVC::getLogFile() const
251 string tmpf = lyx::tempName(string(), "lyxvclog");
252 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;