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;
57 using lyx::support::bformat;
58 using lyx::support::makeDisplayPath;
59 using lyx::support::onlyFilename;
64 using lyx::frontend::ControlCommandBuffer;
66 string current_layout;
74 LyXView::LyXView(Gui & owner)
77 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();
124 Buffer * LyXView::buffer() const
126 return work_area_->bufferView().buffer();
130 void LyXView::setBuffer(Buffer * b)
132 if (work_area_->bufferView().buffer())
136 getDialogs().hideBufferDependent();
138 work_area_->bufferView().setBuffer(b);
140 if (work_area_->bufferView().buffer()) {
141 // Buffer-dependent dialogs should be updated or
142 // hidden. This should go here because some dialogs (eg ToC)
143 // require bv_->text.
144 getDialogs().updateBufferDependent(true);
145 connectBuffer(*work_area_->bufferView().buffer());
150 updateLayoutChoice();
156 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
158 if (work_area_->bufferView().buffer())
161 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
165 updateLayoutChoice();
168 connectBuffer(*work_area_->bufferView().buffer());
169 showErrorList("Parse");
176 void LyXView::connectBuffer(Buffer & buf)
178 if (errorsConnection_.connected())
183 boost::bind(&LyXView::showErrorList, this, _1));
187 boost::bind(&LyXView::message, this, _1));
191 boost::bind(&LyXView::busy, this, _1));
194 buf.updateTitles.connect(
195 boost::bind(&LyXView::updateWindowTitle, this));
198 buf.resetAutosaveTimers.connect(
199 boost::bind(&LyXView::resetAutosaveTimer, this));
201 readonlyConnection_ =
202 buf.readonly.connect(
203 boost::bind(&LyXView::showReadonly, this, _1));
207 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
211 void LyXView::disconnectBuffer()
213 messageConnection_.disconnect();
214 busyConnection_.disconnect();
215 titleConnection_.disconnect();
216 timerConnection_.disconnect();
217 readonlyConnection_.disconnect();
218 closingConnection_.disconnect();
222 void LyXView::showErrorList(string const & error_type)
224 ErrorList & el = buffer()->errorList(error_type);
226 getDialogs().show("errorlist", error_type);
231 void LyXView::showReadonly(bool)
234 getDialogs().updateBufferDependent(false);
238 BufferView * LyXView::view() const
240 return &work_area_->bufferView();
244 void LyXView::setLayout(string const & layout)
246 toolbars_->setLayout(layout);
250 void LyXView::updateToolbars()
252 bool const math = work_area_->bufferView().cursor().inMathed();
254 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
255 toolbars_->update(math, table);
256 // update redaonly status of open dialogs. This could also be in
257 // updateMenubar(), but since updateToolbars() and updateMenubar()
258 // are always called together it is only here.
259 getDialogs().checkStatus();
263 void LyXView::updateMenubar()
269 void LyXView::autoSave()
271 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
273 if (view()->buffer()) {
279 void LyXView::resetAutosaveTimer()
282 autosave_timeout_->restart();
286 void LyXView::updateLayoutChoice()
288 // Don't show any layouts without a buffer
289 if (!view()->buffer()) {
290 toolbars_->clearLayoutList();
294 // Update the layout display
295 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
296 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
299 if (work_area_->bufferView().cursor().inMathed())
302 string const & layout =
303 work_area_->bufferView().cursor().paragraph().layout()->name();
305 if (layout != current_layout) {
306 toolbars_->setLayout(layout);
307 current_layout = layout;
312 void LyXView::updateWindowTitle()
314 static docstring last_title = lyx::from_ascii("LyX");
315 docstring maximize_title = lyx::from_ascii("LyX");
316 docstring minimize_title = lyx::from_ascii("LyX");
318 if (view()->buffer()) {
319 string const cur_title = buffer()->fileName();
320 if (!cur_title.empty()) {
321 maximize_title += lyx::from_ascii(": ") + makeDisplayPath(cur_title, 30);
322 minimize_title = lyx::from_utf8(onlyFilename(cur_title));
323 if (!buffer()->isClean()) {
324 maximize_title += _(" (changed)");
325 minimize_title += lyx::char_type('*');
327 if (buffer()->isReadonly())
328 maximize_title += _(" (read only)");
332 if (maximize_title != last_title) {
333 setWindowTitle(maximize_title, minimize_title);
334 last_title = maximize_title;
339 void LyXView::dispatch(FuncRequest const & cmd)
341 getLyXFunc().dispatch(cmd);
345 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
347 Buffer const * buffer_ptr = 0;
349 buffer_ptr = work_area_->bufferView().buffer();
351 work_area_->bufferView().update(Update::Force);