9 #include "frontends/Alert.h"
11 #include "vc-backend.h"
13 #include "lyx_gui_misc.h"
15 #include "BufferView.h"
17 #include "support/filetools.h"
18 #include "support/lyxlib.h"
38 bool LyXVC::file_found_hook(string const & fn)
41 // Check if file is under RCS
42 if (!(found_file = RCS::find_file(fn)).empty()) {
43 vcs = new RCS(found_file);
47 // Check if file is under CVS
48 if (!(found_file = CVS::find_file(fn)).empty()) {
49 vcs = new CVS(found_file, fn);
53 // file is not under any VCS.
58 bool LyXVC::file_not_found_hook(string const & fn)
60 // Check if file is under RCS
61 if (!RCS::find_file(fn).empty())
63 if (!CVS::find_file(fn).empty())
69 void LyXVC::buffer(Buffer * buf)
75 void LyXVC::registrer()
77 // it is very likely here that the vcs is not created yet...
78 // so... we use RCS as default, later this should perhaps be
81 vcs = new RCS(owner_->fileName());
85 // If the document is changed, we might want to save it
86 if (!vcs->owner()->isLyxClean() &&
87 Alert::askQuestion(_("Changes in document:"),
88 MakeDisplayPath(vcs->owner()->fileName(), 50),
89 _("Save document and proceed?"))) {
90 vcs->owner()->getUser()->owner()
91 ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
94 // Maybe the save fails, or we answered "no". In both cases,
95 // the document will be dirty, and we abort.
96 if (!vcs->owner()->isLyxClean()) {
100 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
101 pair<bool, string> tmp =
102 Alert::askForText(_("LyX VC: Initial description"),
103 _("(no initial description)"));
104 if (!tmp.first || tmp.second.empty()) {
105 // should we insist on checking tmp.second.empty()?
106 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
107 Alert::alert(_("Info"),
108 _("This document has NOT been registered."));
112 vcs->registrer(tmp.second);
116 void LyXVC::checkIn()
118 // If the document is changed, we might want to save it
119 if (!vcs->owner()->isLyxClean() &&
120 Alert::askQuestion(_("Changes in document:"),
121 MakeDisplayPath(vcs->owner()->fileName(), 50),
122 _("Save document and proceed?"))) {
123 vcs->owner()->getUser()->owner()
124 ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
127 // Maybe the save fails, or we answered "no". In both cases,
128 // the document will be dirty, and we abort.
129 if (!vcs->owner()->isLyxClean()) {
133 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
134 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
136 if (tmp.second.empty()) {
137 tmp.second = _("(no log message)");
139 vcs->checkIn(tmp.second);
141 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
146 void LyXVC::checkOut()
148 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
149 if (!vcs->owner()->isLyxClean()
150 && !Alert::askQuestion(_("Changes in document:"),
151 MakeDisplayPath(vcs->owner()->fileName(), 50),
152 _("Ignore changes and proceed with check out?"))) {
163 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
164 // Here we should check if the buffer is dirty. And if it is
165 // we should warn the user that reverting will discard all
166 // changes made since the last check in.
167 if (Alert::askQuestion(_("When you revert, you will loose all changes made"),
168 _("to the document since the last check in."),
169 _("Do you still want to do it?"))) {
176 void LyXVC::undoLast()
182 void LyXVC::toggleReadOnly()
184 switch (vcs->status()) {
186 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
190 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
199 if (vcs) return true;
204 //string const & LyXVC::version() const
206 // return vcs->version();
209 string const LyXVC::versionString() const
211 return vcs->versionString();
215 string const & LyXVC::locker() const
217 return vcs->locker();
221 const string LyXVC::getLogFile() const
226 string tmpf = lyx::tempName(string(), "lyxvclog");
227 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;