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 "errorlist.h"
29 #include "funcrequest.h"
36 #include "MenuBackend.h"
37 #include "paragraph.h"
39 #include "controllers/ControlCommandBuffer.h"
41 #include "support/lstrings.h"
42 #include "support/filetools.h" // OnlyFilename()
44 #include <boost/bind.hpp>
46 #ifdef HAVE_SYS_TIME_H
47 # include <sys/time.h>
53 using lyx::frontend::Gui;
54 using lyx::frontend::WorkArea;
56 using lyx::support::bformat;
57 using lyx::support::makeDisplayPath;
58 using lyx::support::onlyFilename;
63 using lyx::frontend::ControlCommandBuffer;
65 string current_layout;
73 LyXView::LyXView(Gui & owner)
76 toolbars_(new Toolbars(*this)),
78 autosave_timeout_(new Timeout(5000)),
79 lyxfunc_(new LyXFunc(this)),
80 dialogs_(new Dialogs(*this)),
81 controlcommand_(new ControlCommandBuffer(*this))
83 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
91 void LyXView::setWorkArea(WorkArea * work_area)
93 work_area_ = work_area;
97 void LyXView::redrawWorkArea()
104 WorkArea * LyXView::workArea()
112 updateLayoutChoice();
115 // Start autosave timer
116 if (lyxrc.autosave) {
117 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
118 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
119 autosave_timeout_->start();
122 intl_->initKeyMapper(lyxrc.use_kbmap);
126 Buffer * LyXView::buffer() const
128 return work_area_->bufferView().buffer();
132 void LyXView::setBuffer(Buffer * b)
134 if (work_area_->bufferView().buffer())
138 getDialogs().hideBufferDependent();
140 work_area_->bufferView().setBuffer(b);
142 updateLayoutChoice();
144 if (work_area_->bufferView().buffer()) {
145 // Buffer-dependent dialogs should be updated or
146 // hidden. This should go here because some dialogs (eg ToC)
147 // require bv_->text.
148 getDialogs().updateBufferDependent(true);
149 connectBuffer(*work_area_->bufferView().buffer());
150 setLayout(work_area_->bufferView().firstLayout());
160 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
162 if (work_area_->bufferView().buffer())
165 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
169 updateLayoutChoice();
172 connectBuffer(*work_area_->bufferView().buffer());
173 setLayout(work_area_->bufferView().firstLayout());
174 showErrorList("Parse");
181 void LyXView::connectBuffer(Buffer & buf)
183 if (errorsConnection_.connected())
188 boost::bind(&LyXView::showErrorList, this, _1));
192 boost::bind(&LyXView::message, this, _1));
196 boost::bind(&LyXView::busy, this, _1));
199 buf.updateTitles.connect(
200 boost::bind(&LyXView::updateWindowTitle, this));
203 buf.resetAutosaveTimers.connect(
204 boost::bind(&LyXView::resetAutosaveTimer, this));
206 readonlyConnection_ =
207 buf.readonly.connect(
208 boost::bind(&LyXView::showReadonly, this, _1));
212 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
216 void LyXView::disconnectBuffer()
218 messageConnection_.disconnect();
219 busyConnection_.disconnect();
220 titleConnection_.disconnect();
221 timerConnection_.disconnect();
222 readonlyConnection_.disconnect();
223 closingConnection_.disconnect();
227 void LyXView::showErrorList(string const & error_type)
229 ErrorList & el = buffer()->errorList(error_type);
231 getDialogs().show("errorlist", error_type);
236 void LyXView::showReadonly(bool)
239 getDialogs().updateBufferDependent(false);
243 BufferView * LyXView::view() const
245 return &work_area_->bufferView();
249 void LyXView::setLayout(string const & layout)
251 toolbars_->setLayout(layout);
255 void LyXView::updateToolbars()
257 bool const math = work_area_->bufferView().cursor().inMathed();
259 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
260 toolbars_->update(math, table);
261 // update redaonly status of open dialogs. This could also be in
262 // updateMenubar(), but since updateToolbars() and updateMenubar()
263 // are always called together it is only here.
264 getDialogs().checkStatus();
268 void LyXView::updateMenubar()
274 void LyXView::autoSave()
276 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
278 if (view()->available()) {
284 void LyXView::resetAutosaveTimer()
287 autosave_timeout_->restart();
291 void LyXView::updateLayoutChoice()
293 // Don't show any layouts without a buffer
294 if (!view()->buffer()) {
295 toolbars_->clearLayoutList();
299 // Update the layout display
300 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
301 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
304 if (work_area_->bufferView().cursor().inMathed())
307 string const & layout =
308 work_area_->bufferView().cursor().paragraph().layout()->name();
310 if (layout != current_layout) {
311 toolbars_->setLayout(layout);
312 current_layout = layout;
317 void LyXView::updateWindowTitle()
319 static string last_title = "LyX";
320 string maximize_title = "LyX";
321 string minimize_title = "LyX";
323 if (view()->available()) {
324 string const cur_title = buffer()->fileName();
325 if (!cur_title.empty()) {
326 maximize_title += ": " + makeDisplayPath(cur_title, 30);
327 minimize_title = onlyFilename(cur_title);
328 if (!buffer()->isClean()) {
329 maximize_title += _(" (changed)");
330 minimize_title += '*';
332 if (buffer()->isReadonly())
333 maximize_title += _(" (read only)");
337 if (maximize_title != last_title) {
338 setWindowTitle(maximize_title, minimize_title);
339 last_title = maximize_title;
344 void LyXView::dispatch(FuncRequest const & cmd)
346 getLyXFunc().dispatch(cmd);
350 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
352 Buffer const * buffer_ptr = 0;
354 buffer_ptr = work_area_->bufferView().buffer();
356 work_area_->bufferView().update(Update::Force);