1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#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"
|
2002-05-27 00:41:32 +00:00
|
|
|
#include "gettext.h"
|
2002-08-13 17:43:40 +00:00
|
|
|
#include "funcrequest.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-03-25 22:07:48 +00:00
|
|
|
#include "frontends/Alert.h"
|
2002-05-27 00:41:32 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2002-03-25 22:07:48 +00:00
|
|
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lyxlib.h"
|
2003-03-30 20:25:44 +00:00
|
|
|
#include "support/BoostFormat.h"
|
2002-03-25 22:07:48 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2003-03-08 05:37:54 +00:00
|
|
|
/* WARNING: Several of the vcs-> methods end up
|
|
|
|
* deleting this object via BufferView::reload() !
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-29 07:09:13 +00:00
|
|
|
bool LyXVC::ensureClean()
|
|
|
|
{
|
|
|
|
if (owner_->isClean())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
string const file = MakeDisplayPath(owner_->fileName(), 30);
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
boost::format fmt(_("The document %1$s has unsaved changes.\n\nDo you want to save the document?"));
|
|
|
|
fmt % file;
|
|
|
|
string text = fmt.str();
|
|
|
|
#else
|
|
|
|
string text = _("The document ");
|
|
|
|
text += file + _(" has unsaved changes.\n\nDo you want to save the document?");
|
|
|
|
#endif
|
|
|
|
int const ret = Alert::prompt(_("Save changed document?"),
|
2003-04-27 16:40:50 +00:00
|
|
|
text, 0, 1, _("&Save"), _("&Cancel"));
|
2003-03-29 07:09:13 +00:00
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
vcs->owner()->getUser()->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
|
|
|
|
}
|
|
|
|
|
|
|
|
return owner_->isClean();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void LyXVC::registrer()
|
|
|
|
{
|
2002-05-31 01:14:53 +00:00
|
|
|
string const filename = owner_->fileName();
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-05-31 01:14:53 +00:00
|
|
|
// there must be a file to save
|
|
|
|
if (!IsFileReadable(filename)) {
|
2003-03-29 10:29:38 +00:00
|
|
|
Alert::error(_("Document not saved"),
|
|
|
|
_("You must save the document "
|
|
|
|
"before it can be registered."));
|
2002-05-31 01:14:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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 "
|
2002-05-31 01:14:53 +00:00
|
|
|
<< MakeDisplayPath(filename)
|
2002-03-26 12:11:43 +00:00
|
|
|
<< " with CVS" << endl;
|
2002-05-31 01:14:53 +00:00
|
|
|
vcs = new CVS(cvs_entries, filename);
|
2002-03-26 12:11:43 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
lyxerr[Debug::LYXVC]
|
|
|
|
<< "LyXVC: registering "
|
2002-05-31 01:14:53 +00:00
|
|
|
<< MakeDisplayPath(filename)
|
2002-03-26 12:11:43 +00:00
|
|
|
<< " with RCS" << endl;
|
2002-05-31 01:14:53 +00:00
|
|
|
vcs = new RCS(filename);
|
2002-03-26 12:11:43 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// Maybe the save fails, or we answered "no". In both cases,
|
|
|
|
// the document will be dirty, and we abort.
|
2003-03-29 07:09:13 +00:00
|
|
|
if (!ensureClean())
|
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;
|
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
|
2003-03-29 07:09:13 +00:00
|
|
|
if (!vcs->owner()->isClean()) {
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs->owner()->getUser()->owner()
|
2002-08-13 17:43:40 +00:00
|
|
|
->dispatch(FuncRequest(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.
|
2002-08-13 17:43:40 +00:00
|
|
|
if (!vcs->owner()->isClean())
|
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;
|
2003-03-29 07:09:13 +00:00
|
|
|
if (!ensureClean())
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs->checkOut();
|
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-11-09 23:52:04 +00:00
|
|
|
|
2003-03-29 07:09:13 +00:00
|
|
|
string const file = MakeDisplayPath(owner_->fileName(), 20);
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
boost::format fmt(_("Reverting to the stored version of the document %1$s will "
|
|
|
|
"lose all current changes.\n\nDo you want to revert to the saved version?"));
|
|
|
|
fmt % file;
|
|
|
|
string text = fmt.str();
|
|
|
|
#else
|
|
|
|
string text = _("Reverting to the stored version of the document ");
|
|
|
|
text += file + _(" will lose all current changes.\n\nDo you want to revert to the saved version?");
|
|
|
|
#endif
|
|
|
|
int const ret = Alert::prompt(_("Revert to stored version of document?"),
|
2003-04-27 16:40:50 +00:00
|
|
|
text, 0, 1, _("&Revert"), _("&Cancel"));
|
2003-03-29 07:09:13 +00:00
|
|
|
|
|
|
|
if (ret == 0)
|
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
|
|
|
}
|