]> git.lyx.org Git - lyx.git/blob - src/lyxvc.C
Fix working of the spellchecker dialog with ispell when there are no
[lyx.git] / src / lyxvc.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include <unistd.h>
8
9 #include "lyxvc.h"
10 #include "vc-backend.h"
11 #include "debug.h"
12 #include "lyx_gui_misc.h"
13 #include "buffer.h"
14 #include "BufferView.h"
15 #include "gettext.h"
16 #include "support/filetools.h"
17 #include "support/lyxlib.h"
18 #include "LyXView.h"
19 #include "lyxfunc.h"
20
21 using std::endl;
22 using std::pair;
23
24 LyXVC::LyXVC()
25 {
26         vcs = 0;
27         owner_ = 0;
28 }
29
30
31 LyXVC::~LyXVC()
32 {
33         delete vcs;
34 }
35
36
37 bool LyXVC::file_found_hook(string const & fn)
38 {
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;
54 }
55
56
57 bool LyXVC::file_not_found_hook(string const & fn)
58 {
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;
65 }
66
67
68 void LyXVC::buffer(Buffer * buf)
69 {
70         owner_ = buf;
71 }
72
73
74 void LyXVC::registrer()
75 {
76         // it is very likely here that the vcs is not created yet...
77         // so... we use RCS as default, later this should perhaps be
78         // a lyxrc option.
79         if (!vcs) {
80                 vcs = new RCS(owner_->fileName());
81                 vcs->owner(owner_);
82         }
83         
84         // If the document is changed, we might want to save it
85         if (!vcs->owner()->isLyxClean() && 
86             AskQuestion(_("Changes in document:"),
87                         MakeDisplayPath(vcs->owner()->fileName(), 50),
88                         _("Save document and proceed?"))) {
89                 vcs->owner()->getUser()->owner()
90                         ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
91         }
92
93         // Maybe the save fails, or we answered "no". In both cases,
94         // the document will be dirty, and we abort.
95         if (!vcs->owner()->isLyxClean()) {
96                 return;
97         }
98
99         lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
100         pair<bool, string> tmp =
101                 askForText(_("LyX VC: Initial description"),
102                            _("(no initial description)"));
103         if (!tmp.first || tmp.second.empty()) {
104                 // should we insist on checking tmp.second.empty()?
105                 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
106                 WriteAlert(_("Info"),
107                            _("This document has NOT been registered."));
108                 return;
109         }
110         
111         vcs->registrer(tmp.second);
112 }
113
114
115 void LyXVC::checkIn()
116 {
117         // If the document is changed, we might want to save it
118         if (!vcs->owner()->isLyxClean() && 
119             AskQuestion(_("Changes in document:"),
120                         MakeDisplayPath(vcs->owner()->fileName(), 50),
121                         _("Save document and proceed?"))) {
122                 vcs->owner()->getUser()->owner()
123                         ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
124         }
125
126         // Maybe the save fails, or we answered "no". In both cases,
127         // the document will be dirty, and we abort.
128         if (!vcs->owner()->isLyxClean()) {
129                 return;
130         }
131
132         lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
133         pair<bool, string> tmp = askForText(_("LyX VC: Log Message"));
134         if (tmp.first) {
135                 if (tmp.second.empty()) {
136                         tmp.second = _("(no log message)");
137                 }
138                 vcs->checkIn(tmp.second);
139         } else {
140                 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
141         }
142 }
143
144
145 void LyXVC::checkOut()
146 {
147         lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
148         if (!vcs->owner()->isLyxClean() 
149             && !AskQuestion(_("Changes in document:"),
150                            MakeDisplayPath(vcs->owner()->fileName(), 50),
151                            _("Ignore changes and proceed with check out?"))) {
152                 return;
153         }
154
155         vcs->checkOut();
156         
157 }
158
159
160 void LyXVC::revert()
161 {
162         lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
163         // Here we should check if the buffer is dirty. And if it is
164         // we should warn the user that reverting will discard all
165         // changes made since the last check in.
166         if (AskQuestion(_("When you revert, you will loose all changes made"),
167                         _("to the document since the last check in."),
168                         _("Do you still want to do it?"))) {
169
170                 vcs->revert();
171         }
172 }
173
174
175 void LyXVC::undoLast()
176 {
177         vcs->undoLast();
178 }
179
180
181 void LyXVC::toggleReadOnly()
182 {
183         switch (vcs->status()) {
184         case VCS::UNLOCKED:
185                 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
186                 checkOut();
187                 break;
188         case VCS::LOCKED:
189                 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
190                 checkIn();
191                 break;
192         }
193 }
194
195
196 bool LyXVC::inUse()
197 {
198         if (vcs) return true;
199         return false;
200 }
201
202
203 //string const & LyXVC::version() const
204 //{
205 //      return vcs->version();
206 //}
207
208 string const LyXVC::versionString() const
209 {
210         return vcs->versionString();
211 }
212
213
214 string const & LyXVC::locker() const
215 {
216         return vcs->locker();
217 }
218
219
220 const string LyXVC::getLogFile() const
221 {
222         if (!vcs)
223                 return string();
224
225         string tmpf = lyx::tempName(string(), "lyxvclog");
226         lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;
227         vcs->getLog(tmpf);
228         return tmpf;
229 }