3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
23 #include "bufferparams.h"
24 #include "BufferView.h"
25 #include "bufferview_funcs.h"
28 #include "funcrequest.h"
35 #include "MenuBackend.h"
36 #include "paragraph.h"
38 #include "controllers/ControlCommandBuffer.h"
40 #include "support/lstrings.h"
41 #include "support/filetools.h" // OnlyFilename()
43 #include <boost/bind.hpp>
45 #ifdef HAVE_SYS_TIME_H
46 # include <sys/time.h>
52 using lyx::frontend::Gui;
53 using lyx::frontend::WorkArea;
55 using lyx::support::bformat;
56 using lyx::support::makeDisplayPath;
57 using lyx::support::onlyFilename;
62 using lyx::frontend::ControlCommandBuffer;
64 string current_layout;
72 LyXView::LyXView(Gui & owner)
75 toolbars_(new Toolbars(*this)),
77 autosave_timeout_(new Timeout(5000)),
78 lyxfunc_(new LyXFunc(this)),
79 dialogs_(new Dialogs(*this)),
80 controlcommand_(new ControlCommandBuffer(*this))
82 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
90 void LyXView::setWorkArea(WorkArea * work_area)
92 work_area_ = work_area;
96 void LyXView::redrawWorkArea()
103 WorkArea * LyXView::workArea()
111 updateLayoutChoice();
114 // Start autosave timer
115 if (lyxrc.autosave) {
116 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
117 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
118 autosave_timeout_->start();
121 intl_->initKeyMapper(lyxrc.use_kbmap);
125 Buffer * LyXView::buffer() const
127 return work_area_->bufferView().buffer();
131 void LyXView::setBuffer(Buffer * b)
133 if (work_area_->bufferView().buffer())
136 work_area_->bufferView().setBuffer(b);
139 updateLayoutChoice();
143 setLayout(work_area_->bufferView().firstLayout());
149 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
151 if (work_area_->bufferView().buffer())
154 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
157 updateLayoutChoice();
160 connectBuffer(*work_area_->bufferView().buffer());
161 setLayout(work_area_->bufferView().firstLayout());
168 void LyXView::connectBuffer(Buffer & buf)
170 if (errorsConnection_.connected())
173 // FIXME: (Abdel 15/07/2006) The connection below is not used for
175 // Nevertheless, it would be a very good idea to replace all manual
176 // calls of showErrorList to a call of the new modified
177 // "Buffer::errors" boost signal.
180 boost::bind(&LyXView::showErrorList, this, _1));
184 boost::bind(&LyXView::message, this, _1));
188 boost::bind(&LyXView::busy, this, _1));
191 buf.updateTitles.connect(
192 boost::bind(&LyXView::updateWindowTitle, this));
195 buf.resetAutosaveTimers.connect(
196 boost::bind(&LyXView::resetAutosaveTimer, this));
198 readonlyConnection_ =
199 buf.readonly.connect(
200 boost::bind(&LyXView::showReadonly, this, _1));
204 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
208 void LyXView::disconnectBuffer()
210 messageConnection_.disconnect();
211 busyConnection_.disconnect();
212 titleConnection_.disconnect();
213 timerConnection_.disconnect();
214 readonlyConnection_.disconnect();
215 closingConnection_.disconnect();
219 void LyXView::showErrorList(string const & action)
221 Buffer * b = work_area_->bufferView().buffer();
222 if (!b->getErrorList().empty()) {
223 string const title = bformat(_("%1$s Errors (%2$s)"),
224 action, buffer()->fileName());
225 getDialogs().show("errorlist", title);
230 void LyXView::showReadonly(bool)
233 getDialogs().updateBufferDependent(false);
237 BufferView * LyXView::view() const
239 return &work_area_->bufferView();
243 void LyXView::setLayout(string const & layout)
245 toolbars_->setLayout(layout);
249 void LyXView::updateToolbars()
251 bool const math = work_area_->bufferView().cursor().inMathed();
253 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
254 toolbars_->update(math, table);
255 // update redaonly status of open dialogs. This could also be in
256 // updateMenubar(), but since updateToolbars() and updateMenubar()
257 // are always called together it is only here.
258 getDialogs().checkStatus();
262 void LyXView::updateMenubar()
268 void LyXView::autoSave()
270 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
272 if (view()->available()) {
278 void LyXView::resetAutosaveTimer()
281 autosave_timeout_->restart();
285 void LyXView::updateLayoutChoice()
287 // Don't show any layouts without a buffer
288 if (!view()->buffer()) {
289 toolbars_->clearLayoutList();
293 // Update the layout display
294 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
295 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
298 if (work_area_->bufferView().cursor().inMathed())
301 string const & layout =
302 work_area_->bufferView().cursor().paragraph().layout()->name();
304 if (layout != current_layout) {
305 toolbars_->setLayout(layout);
306 current_layout = layout;
311 void LyXView::updateWindowTitle()
313 static string last_title = "LyX";
314 string maximize_title = "LyX";
315 string minimize_title = "LyX";
317 if (view()->available()) {
318 string const cur_title = buffer()->fileName();
319 if (!cur_title.empty()) {
320 maximize_title += ": " + makeDisplayPath(cur_title, 30);
321 minimize_title = onlyFilename(cur_title);
322 if (!buffer()->isClean()) {
323 maximize_title += _(" (changed)");
324 minimize_title += '*';
326 if (buffer()->isReadonly())
327 maximize_title += _(" (read only)");
331 if (maximize_title != last_title) {
332 setWindowTitle(maximize_title, minimize_title);
333 last_title = maximize_title;
338 void LyXView::dispatch(FuncRequest const & cmd)
340 getLyXFunc().dispatch(cmd);
344 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
346 Buffer const * buffer_ptr = 0;
348 buffer_ptr = work_area_->bufferView().buffer();
350 work_area_->bufferView().update(Update::Force);