1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
#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-09-27 18:44:28 +00:00
|
|
|
#include "lyx_gui_misc.h"
|
1999-11-09 23:52:04 +00:00
|
|
|
#include "buffer.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
1999-11-09 23:52:04 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyxfunc.h"
|
1999-11-09 23:52:04 +00:00
|
|
|
#include "LyXView.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
LyXVC::LyXVC()
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
browser = 0;
|
1999-11-09 23:52:04 +00:00
|
|
|
owner_ = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXVC::~LyXVC()
|
|
|
|
{
|
|
|
|
if (browser) {
|
|
|
|
if (browser->LaTeXLog->visible)
|
|
|
|
fl_hide_form(browser->LaTeXLog);
|
|
|
|
fl_free_form(browser->LaTeXLog);
|
|
|
|
}
|
2000-01-25 12:35:27 +00:00
|
|
|
if (vcs) { // DEL LINE
|
1999-11-09 23:52:04 +00:00
|
|
|
delete vcs;
|
2000-01-25 12:35:27 +00:00
|
|
|
} // DEL LINE
|
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...
|
|
|
|
// so... we use RCS as default, later this should perhaps be
|
|
|
|
// a lyxrc option.
|
|
|
|
if (!vcs) {
|
1999-12-10 00:07:59 +00:00
|
|
|
vcs = new RCS(owner_->fileName());
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs->owner(owner_);
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// If the document is changed, we might want to save it
|
1999-11-09 23:52:04 +00:00
|
|
|
if (!vcs->owner()->isLyxClean() &&
|
1999-09-27 18:44:28 +00:00
|
|
|
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()
|
|
|
|
->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;
|
1999-12-30 02:35:43 +00:00
|
|
|
pair<bool, string> tmp = askForText(_("LyX VC: Initial description"),
|
|
|
|
_("(no initial description)"));
|
|
|
|
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-12-30 02:35:43 +00:00
|
|
|
WriteAlert(_("Info"),
|
|
|
|
_("This document has NOT been registered."));
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-11-09 23:52:04 +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
|
1999-11-09 23:52:04 +00:00
|
|
|
if (!vcs->owner()->isLyxClean() &&
|
1999-09-27 18:44:28 +00:00
|
|
|
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()
|
|
|
|
->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;
|
1999-12-30 02:35:43 +00:00
|
|
|
pair<bool, string> tmp = askForText(_("LyX VC: Log Message"));
|
|
|
|
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;
|
1999-11-09 23:52:04 +00:00
|
|
|
if (!vcs->owner()->isLyxClean()
|
1999-09-27 18:44:28 +00:00
|
|
|
&& !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();
|
|
|
|
|
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.
|
|
|
|
if (AskQuestion(_("When you revert, you will loose all changes made"),
|
|
|
|
_("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()
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
switch (vcs->stat()) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
string const & LyXVC::version() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
return vcs->version();
|
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
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// This is a hack anyway so I'll put it here in the mean time.
|
1999-11-04 01:40:20 +00:00
|
|
|
void LyXVC::logClose(FL_OBJECT * obj, long)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_hide_form(This->browser->LaTeXLog);
|
|
|
|
}
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
// and, hack over hack, here is a C wrapper :)
|
1999-11-04 01:40:20 +00:00
|
|
|
extern "C" void C_LyXVC_logClose(FL_OBJECT * ob, long data)
|
1999-10-25 14:18:30 +00:00
|
|
|
{
|
|
|
|
LyXVC::logClose(ob, data);
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void LyXVC::logUpdate(FL_OBJECT * obj, long)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
|
1999-09-27 18:44:28 +00:00
|
|
|
This->showLog();
|
|
|
|
}
|
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
extern "C" void C_LyXVC_logUpdate(FL_OBJECT *ob, long data)
|
|
|
|
{
|
|
|
|
LyXVC::logUpdate(ob, data);
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
void LyXVC::viewLog(string const & fil)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-25 14:50:26 +00:00
|
|
|
static int ow = -1, oh;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!browser) {
|
1999-11-04 01:40:20 +00:00
|
|
|
FL_OBJECT * obj;
|
1999-09-27 18:44:28 +00:00
|
|
|
browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
|
|
|
|
|
|
|
|
browser->LaTeXLog = fl_bgn_form(FL_NO_BOX, 470, 380);
|
1999-11-04 01:40:20 +00:00
|
|
|
browser->LaTeXLog->u_vdata = this;
|
1999-09-27 18:44:28 +00:00
|
|
|
obj = fl_add_box(FL_UP_BOX, 0, 0, 470, 380, "");
|
1999-11-04 01:40:20 +00:00
|
|
|
browser->browser_latexlog = fl_add_browser(FL_NORMAL_BROWSER,
|
|
|
|
10, 10,
|
|
|
|
450, 320, "");
|
|
|
|
obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30,
|
|
|
|
_("Close"));
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
1999-10-25 14:18:30 +00:00
|
|
|
fl_set_object_callback(obj, C_LyXVC_logClose, 0);
|
1999-11-15 12:01:38 +00:00
|
|
|
obj = fl_add_button(FL_NORMAL_BUTTON, 370, 340, 90, 30,
|
1999-09-27 18:44:28 +00:00
|
|
|
idex(_("Update|#Uu")));
|
1999-11-15 12:01:38 +00:00
|
|
|
fl_set_button_shortcut(obj, scex(_("Update|#Uu")), 1);
|
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
|
|
|
fl_set_object_callback(obj, C_LyXVC_logUpdate, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_end_form();
|
1999-10-02 16:21:10 +00:00
|
|
|
fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
|
1999-11-04 01:40:20 +00:00
|
|
|
fl_add_browser_line(browser->browser_latexlog,
|
1999-11-09 23:52:04 +00:00
|
|
|
_("No VC History!"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (browser->LaTeXLog->visible) {
|
|
|
|
fl_raise_form(browser->LaTeXLog);
|
|
|
|
} else {
|
|
|
|
fl_show_form(browser->LaTeXLog,
|
|
|
|
FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
|
1999-11-09 23:52:04 +00:00
|
|
|
_("VC History"));
|
1999-10-25 14:50:26 +00:00
|
|
|
if (ow < 0) {
|
|
|
|
ow = browser->LaTeXLog->w;
|
|
|
|
oh = browser->LaTeXLog->h;
|
|
|
|
}
|
|
|
|
fl_set_form_minsize(browser->LaTeXLog, ow, oh);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::showLog()
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmpf = tmpnam(0);
|
1999-11-09 23:52:04 +00:00
|
|
|
vcs->getLog(tmpf);
|
1999-09-27 18:44:28 +00:00
|
|
|
viewLog(tmpf);
|
|
|
|
unlink(tmpf.c_str());
|
|
|
|
}
|