1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "lyxvc.h"
|
1999-11-09 23:52:04 +00:00
|
|
|
#include "vc-backend.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-11-09 23:52:04 +00:00
|
|
|
#include "buffer.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2001-04-24 17:33:01 +00:00
|
|
|
#include "lyxfunc.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-03-25 22:07:48 +00:00
|
|
|
#include "frontends/Alert.h"
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::pair;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
LyXVC::LyXVC()
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs = 0;
|
|
|
|
owner_ = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXVC::~LyXVC()
|
|
|
|
{
|
2000-02-04 09:38:32 +00:00
|
|
|
delete vcs;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
bool LyXVC::file_found_hook(string const & fn)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
string found_file;
|
|
|
|
// Check if file is under RCS
|
|
|
|
if (!(found_file = RCS::find_file(fn)).empty()) {
|
|
|
|
vcs = new RCS(found_file);
|
|
|
|
vcs->owner(owner_);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Check if file is under CVS
|
|
|
|
if (!(found_file = CVS::find_file(fn)).empty()) {
|
|
|
|
vcs = new CVS(found_file, fn);
|
|
|
|
vcs->owner(owner_);
|
1999-09-27 18:44:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// file is not under any VCS.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-11 08:23:07 +00:00
|
|
|
bool LyXVC::file_not_found_hook(string const & fn)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-01-11 08:23:07 +00:00
|
|
|
// Check if file is under RCS
|
|
|
|
if (!RCS::find_file(fn).empty())
|
|
|
|
return true;
|
|
|
|
if (!CVS::find_file(fn).empty())
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
void LyXVC::buffer(Buffer * buf)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
owner_ = buf;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::registrer()
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
// it is very likely here that the vcs is not created yet...
|
|
|
|
if (!vcs) {
|
2002-03-26 12:11:43 +00:00
|
|
|
string const cvs_entries = "CVS/Entries";
|
|
|
|
|
|
|
|
if (IsFileReadable(cvs_entries)) {
|
|
|
|
lyxerr[Debug::LYXVC]
|
|
|
|
<< "LyXVC: registering "
|
|
|
|
<< MakeDisplayPath(owner_->fileName())
|
|
|
|
<< " with CVS" << endl;
|
|
|
|
vcs = new CVS(cvs_entries, owner_->fileName());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
lyxerr[Debug::LYXVC]
|
|
|
|
<< "LyXVC: registering "
|
|
|
|
<< MakeDisplayPath(owner_->fileName())
|
|
|
|
<< " with RCS" << endl;
|
|
|
|
vcs = new RCS(owner_->fileName());
|
|
|
|
}
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs->owner(owner_);
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// If the document is changed, we might want to save it
|
2002-03-21 17:27:08 +00:00
|
|
|
if (!vcs->owner()->isLyxClean() &&
|
2001-11-26 10:19:58 +00:00
|
|
|
Alert::askQuestion(_("Changes in document:"),
|
1999-12-10 00:07:59 +00:00
|
|
|
MakeDisplayPath(vcs->owner()->fileName(), 50),
|
1999-09-27 18:44:28 +00:00
|
|
|
_("Save document and proceed?"))) {
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs->owner()->getUser()->owner()
|
2001-07-16 15:42:57 +00:00
|
|
|
->getLyXFunc()->dispatch(LFUN_MENUWRITE);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Maybe the save fails, or we answered "no". In both cases,
|
|
|
|
// the document will be dirty, and we abort.
|
1999-11-09 23:52:04 +00:00
|
|
|
if (!vcs->owner()->isLyxClean()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
|
2000-03-28 02:18:55 +00:00
|
|
|
pair<bool, string> tmp =
|
2001-11-26 10:19:58 +00:00
|
|
|
Alert::askForText(_("LyX VC: Initial description"),
|
2000-03-28 02:18:55 +00:00
|
|
|
_("(no initial description)"));
|
1999-12-30 02:35:43 +00:00
|
|
|
if (!tmp.first || tmp.second.empty()) {
|
|
|
|
// should we insist on checking tmp.second.empty()?
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
|
2001-11-26 10:19:58 +00:00
|
|
|
Alert::alert(_("Info"),
|
1999-12-30 02:35:43 +00:00
|
|
|
_("This document has NOT been registered."));
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-12-30 02:35:43 +00:00
|
|
|
vcs->registrer(tmp.second);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::checkIn()
|
|
|
|
{
|
|
|
|
// If the document is changed, we might want to save it
|
2002-03-21 17:27:08 +00:00
|
|
|
if (!vcs->owner()->isLyxClean() &&
|
2001-11-26 10:19:58 +00:00
|
|
|
Alert::askQuestion(_("Changes in document:"),
|
1999-12-10 00:07:59 +00:00
|
|
|
MakeDisplayPath(vcs->owner()->fileName(), 50),
|
1999-09-27 18:44:28 +00:00
|
|
|
_("Save document and proceed?"))) {
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs->owner()->getUser()->owner()
|
2001-07-16 15:42:57 +00:00
|
|
|
->getLyXFunc()->dispatch(LFUN_MENUWRITE);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Maybe the save fails, or we answered "no". In both cases,
|
|
|
|
// the document will be dirty, and we abort.
|
1999-11-09 23:52:04 +00:00
|
|
|
if (!vcs->owner()->isLyxClean()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
|
2001-11-26 10:19:58 +00:00
|
|
|
pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
|
1999-12-30 02:35:43 +00:00
|
|
|
if (tmp.first) {
|
|
|
|
if (tmp.second.empty()) {
|
|
|
|
tmp.second = _("(no log message)");
|
|
|
|
}
|
|
|
|
vcs->checkIn(tmp.second);
|
|
|
|
} else {
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::checkOut()
|
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
|
2002-03-21 17:27:08 +00:00
|
|
|
if (!vcs->owner()->isLyxClean()
|
2001-11-26 10:19:58 +00:00
|
|
|
&& !Alert::askQuestion(_("Changes in document:"),
|
1999-12-10 00:07:59 +00:00
|
|
|
MakeDisplayPath(vcs->owner()->fileName(), 50),
|
1999-09-27 18:44:28 +00:00
|
|
|
_("Ignore changes and proceed with check out?"))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs->checkOut();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::revert()
|
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
// Here we should check if the buffer is dirty. And if it is
|
|
|
|
// we should warn the user that reverting will discard all
|
|
|
|
// changes made since the last check in.
|
2001-11-26 10:19:58 +00:00
|
|
|
if (Alert::askQuestion(_("When you revert, you will loose all changes made"),
|
1999-09-27 18:44:28 +00:00
|
|
|
_("to the document since the last check in."),
|
|
|
|
_("Do you still want to do it?"))) {
|
1999-11-09 23:52:04 +00:00
|
|
|
|
|
|
|
vcs->revert();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::undoLast()
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs->undoLast();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::toggleReadOnly()
|
|
|
|
{
|
2000-05-17 16:42:35 +00:00
|
|
|
switch (vcs->status()) {
|
1999-11-09 23:52:04 +00:00
|
|
|
case VCS::UNLOCKED:
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
checkOut();
|
|
|
|
break;
|
1999-11-09 23:52:04 +00:00
|
|
|
case VCS::LOCKED:
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
checkIn();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXVC::inUse()
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
if (vcs) return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-19 14:06:27 +00:00
|
|
|
//string const & LyXVC::version() const
|
|
|
|
//{
|
|
|
|
// return vcs->version();
|
|
|
|
//}
|
|
|
|
|
|
|
|
string const LyXVC::versionString() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-19 14:06:27 +00:00
|
|
|
return vcs->versionString();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
string const & LyXVC::locker() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
return vcs->locker();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
|
2001-02-06 17:41:42 +00:00
|
|
|
const string LyXVC::getLogFile() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-06 17:41:42 +00:00
|
|
|
if (!vcs)
|
|
|
|
return string();
|
1999-10-25 14:18:30 +00:00
|
|
|
|
2001-01-08 09:37:13 +00:00
|
|
|
string tmpf = lyx::tempName(string(), "lyxvclog");
|
2001-02-06 17:41:42 +00:00
|
|
|
lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs->getLog(tmpf);
|
2001-02-06 17:41:42 +00:00
|
|
|
return tmpf;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|