\end_document replaces \the_end.
[lyx.git] / src / lyxvc.C
blob220d7c2491381332f1d573c523cf95e14bc749f2
1 #include <config.h>
3 #include "lyxvc.h"
4 #include "vc-backend.h"
5 #include "debug.h"
6 #include "buffer.h"
7 #include "gettext.h"
8 #include "funcrequest.h"
10 #include "frontends/Alert.h"
11 #include "frontends/LyXView.h"
13 #include "support/filetools.h"
14 #include "support/lyxlib.h"
16 #include <unistd.h>
18 using namespace lyx::support;
20 using std::endl;
21 using std::pair;
24 LyXVC::LyXVC()
26         vcs = 0;
27         owner_ = 0;
31 LyXVC::~LyXVC()
33         delete vcs;
37 bool LyXVC::file_found_hook(string const & fn)
39         string found_file;
40         // Check if file is under RCS
41         if (!(found_file = RCS::find_file(fn)).empty()) {
42                 vcs = new RCS(found_file);
43                 vcs->owner(owner_);
44                 return true;
45         }
46         // Check if file is under CVS
47         if (!(found_file = CVS::find_file(fn)).empty()) {
48                 vcs = new CVS(found_file, fn);
49                 vcs->owner(owner_);
50                 return true;
51         }
52         // file is not under any VCS.
53         return false;
57 bool LyXVC::file_not_found_hook(string const & fn)
59         // Check if file is under RCS
60         if (!RCS::find_file(fn).empty())
61                 return true;
62         if (!CVS::find_file(fn).empty())
63                 return true;
64         return false;
68 void LyXVC::buffer(Buffer * buf)
70         owner_ = buf;
74 void LyXVC::registrer()
76         string const filename = owner_->fileName();
78         // there must be a file to save
79         if (!IsFileReadable(filename)) {
80                 Alert::error(_("Document not saved"),
81                              _("You must save the document "
82                                "before it can be registered."));
83                 return;
84         }
86         // it is very likely here that the vcs is not created yet...
87         if (!vcs) {
88                 string const cvs_entries = "CVS/Entries";
90                 if (IsFileReadable(cvs_entries)) {
91                         lyxerr[Debug::LYXVC]
92                                 << "LyXVC: registering "
93                                 << MakeDisplayPath(filename)
94                                 << " with CVS" << endl;
95                         vcs = new CVS(cvs_entries, filename);
97                 } else {
98                         lyxerr[Debug::LYXVC]
99                                 << "LyXVC: registering "
100                                 << MakeDisplayPath(filename)
101                                 << " with RCS" << endl;
102                         vcs = new RCS(filename);
103                 }
105                 vcs->owner(owner_);
106         }
108         lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
109         pair<bool, string> tmp =
110                 Alert::askForText(_("LyX VC: Initial description"),
111                            _("(no initial description)"));
112         if (!tmp.first || tmp.second.empty()) {
113                 // should we insist on checking tmp.second.empty()?
114                 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
115                 return;
116         }
118         vcs->registrer(tmp.second);
122 void LyXVC::checkIn()
125         lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
126         pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
127         if (tmp.first) {
128                 if (tmp.second.empty()) {
129                         tmp.second = _("(no log message)");
130                 }
131                 vcs->checkIn(tmp.second);
132         } else {
133                 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
134         }
138 void LyXVC::checkOut()
140         lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
142         vcs->checkOut();
146 void LyXVC::revert()
148         lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
150         string const file = MakeDisplayPath(owner_->fileName(), 20);
151         string text = bformat(_("Reverting to the stored version of the "
152                 "document %1$s will lose all current changes.\n\n"
153                 "Do you want to revert to the saved version?"), file);
154         int const ret = Alert::prompt(_("Revert to stored version of document?"),
155                 text, 0, 1, _("&Revert"), _("&Cancel"));
157         if (ret == 0)
158                 vcs->revert();
162 void LyXVC::undoLast()
164         vcs->undoLast();
168 void LyXVC::toggleReadOnly()
170         switch (vcs->status()) {
171         case VCS::UNLOCKED:
172                 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
173                 checkOut();
174                 break;
175         case VCS::LOCKED:
176                 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
177                 checkIn();
178                 break;
179         }
183 bool LyXVC::inUse()
185         if (vcs) return true;
186         return false;
190 //string const & LyXVC::version() const
192 //      return vcs->version();
195 string const LyXVC::versionString() const
197         return vcs->versionString();
201 string const & LyXVC::locker() const
203         return vcs->locker();
207 string const LyXVC::getLogFile() const
209         if (!vcs)
210                 return string();
212         string tmpf = tempName(string(), "lyxvclog");
213         lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;
214         vcs->getLog(tmpf);
215         return tmpf;