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)),
79 autosave_timeout_(new Timeout(5000)),
80 lyxfunc_(new LyXFunc(this)),
81 dialogs_(new Dialogs(*this)),
82 controlcommand_(new ControlCommandBuffer(*this))
84 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
92 void LyXView::setWorkArea(WorkArea * work_area)
94 work_area_ = work_area;
98 void LyXView::redrawWorkArea()
100 work_area_->redraw();
105 WorkArea * LyXView::workArea()
113 updateLayoutChoice();
116 // Start autosave timer
117 if (lyxrc.autosave) {
118 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
119 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
120 autosave_timeout_->start();
123 intl_->initKeyMapper(lyxrc.use_kbmap);
127 Buffer * LyXView::buffer() const
129 return work_area_->bufferView().buffer();
133 void LyXView::setBuffer(Buffer * b)
135 if (work_area_->bufferView().buffer())
139 getDialogs().hideBufferDependent();
141 work_area_->bufferView().setBuffer(b);
143 if (work_area_->bufferView().buffer()) {
144 // Buffer-dependent dialogs should be updated or
145 // hidden. This should go here because some dialogs (eg ToC)
146 // require bv_->text.
147 getDialogs().updateBufferDependent(true);
148 connectBuffer(*work_area_->bufferView().buffer());
153 updateLayoutChoice();
159 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
161 if (work_area_->bufferView().buffer())
164 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
168 updateLayoutChoice();
171 connectBuffer(*work_area_->bufferView().buffer());
172 showErrorList("Parse");
179 void LyXView::connectBuffer(Buffer & buf)
181 if (errorsConnection_.connected())
186 boost::bind(&LyXView::showErrorList, this, _1));
190 boost::bind(&LyXView::message, this, _1));
194 boost::bind(&LyXView::busy, this, _1));
197 buf.updateTitles.connect(
198 boost::bind(&LyXView::updateWindowTitle, this));
201 buf.resetAutosaveTimers.connect(
202 boost::bind(&LyXView::resetAutosaveTimer, this));
204 readonlyConnection_ =
205 buf.readonly.connect(
206 boost::bind(&LyXView::showReadonly, this, _1));
210 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
214 void LyXView::disconnectBuffer()
216 messageConnection_.disconnect();
217 busyConnection_.disconnect();
218 titleConnection_.disconnect();
219 timerConnection_.disconnect();
220 readonlyConnection_.disconnect();
221 closingConnection_.disconnect();
225 void LyXView::showErrorList(string const & error_type)
227 ErrorList & el = buffer()->errorList(error_type);
229 getDialogs().show("errorlist", error_type);
234 void LyXView::showReadonly(bool)
237 getDialogs().updateBufferDependent(false);
241 BufferView * LyXView::view() const
243 return &work_area_->bufferView();
247 void LyXView::setLayout(string const & layout)
249 toolbars_->setLayout(layout);
253 void LyXView::updateToolbars()
255 bool const math = work_area_->bufferView().cursor().inMathed();
257 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
258 toolbars_->update(math, table);
259 // update redaonly status of open dialogs. This could also be in
260 // updateMenubar(), but since updateToolbars() and updateMenubar()
261 // are always called together it is only here.
262 getDialogs().checkStatus();
266 void LyXView::updateMenubar()
272 void LyXView::autoSave()
274 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
276 if (view()->buffer()) {
282 void LyXView::resetAutosaveTimer()
285 autosave_timeout_->restart();
289 void LyXView::updateLayoutChoice()
291 // Don't show any layouts without a buffer
292 if (!view()->buffer()) {
293 toolbars_->clearLayoutList();
297 // Update the layout display
298 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
299 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
302 if (work_area_->bufferView().cursor().inMathed())
305 string const & layout =
306 work_area_->bufferView().cursor().paragraph().layout()->name();
308 if (layout != current_layout) {
309 toolbars_->setLayout(layout);
310 current_layout = layout;
315 void LyXView::updateWindowTitle()
317 static docstring last_title = lyx::from_ascii("LyX");
318 docstring maximize_title = lyx::from_ascii("LyX");
319 docstring minimize_title = lyx::from_ascii("LyX");
321 if (view()->buffer()) {
322 string const cur_title = buffer()->fileName();
323 if (!cur_title.empty()) {
324 maximize_title += lyx::from_ascii(": ") + makeDisplayPath(cur_title, 30);
325 minimize_title = lyx::from_utf8(onlyFilename(cur_title));
326 if (!buffer()->isClean()) {
327 maximize_title += _(" (changed)");
328 minimize_title += lyx::char_type('*');
330 if (buffer()->isReadonly())
331 maximize_title += _(" (read only)");
335 if (maximize_title != last_title) {
336 setWindowTitle(maximize_title, minimize_title);
337 last_title = maximize_title;
342 void LyXView::dispatch(FuncRequest const & cmd)
344 getLyXFunc().dispatch(cmd);
348 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
350 Buffer const * buffer_ptr = 0;
352 buffer_ptr = work_area_->bufferView().buffer();
354 work_area_->bufferView().update(Update::Force);