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...
79 // so... we use RCS as default, later this should perhaps be
82 vcs = new RCS(owner_->fileName());
86 // If the document is changed, we might want to save it
87 if (!vcs->owner()->isLyxClean() &&
88 Alert::askQuestion(_("Changes in document:"),
89 MakeDisplayPath(vcs->owner()->fileName(), 50),
90 _("Save document and proceed?"))) {
91 vcs->owner()->getUser()->owner()
92 ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
95 // Maybe the save fails, or we answered "no". In both cases,
96 // the document will be dirty, and we abort.
97 if (!vcs->owner()->isLyxClean()) {
101 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
102 pair<bool, string> tmp =
103 Alert::askForText(_("LyX VC: Initial description"),
104 _("(no initial description)"));
105 if (!tmp.first || tmp.second.empty()) {
106 // should we insist on checking tmp.second.empty()?
107 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
108 Alert::alert(_("Info"),
109 _("This document has NOT been registered."));
113 vcs->registrer(tmp.second);
117 void LyXVC::checkIn()
119 // If the document is changed, we might want to save it
120 if (!vcs->owner()->isLyxClean() &&
121 Alert::askQuestion(_("Changes in document:"),
122 MakeDisplayPath(vcs->owner()->fileName(), 50),
123 _("Save document and proceed?"))) {
124 vcs->owner()->getUser()->owner()
125 ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
128 // Maybe the save fails, or we answered "no". In both cases,
129 // the document will be dirty, and we abort.
130 if (!vcs->owner()->isLyxClean()) {
134 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
135 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
137 if (tmp.second.empty()) {
138 tmp.second = _("(no log message)");
140 vcs->checkIn(tmp.second);
142 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
147 void LyXVC::checkOut()
149 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
150 if (!vcs->owner()->isLyxClean()
151 && !Alert::askQuestion(_("Changes in document:"),
152 MakeDisplayPath(vcs->owner()->fileName(), 50),
153 _("Ignore changes and proceed with check out?"))) {
164 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
165 // Here we should check if the buffer is dirty. And if it is
166 // we should warn the user that reverting will discard all
167 // changes made since the last check in.
168 if (Alert::askQuestion(_("When you revert, you will loose all changes made"),
169 _("to the document since the last check in."),
170 _("Do you still want to do it?"))) {
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 const string LyXVC::getLogFile() const
227 string tmpf = lyx::tempName(string(), "lyxvclog");
228 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;