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 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);
152 updateLayoutChoice();
156 setLayout(work_area_->bufferView().firstLayout());
162 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
164 if (work_area_->bufferView().buffer())
167 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
168 showErrorList("Parse");
172 updateLayoutChoice();
175 connectBuffer(*work_area_->bufferView().buffer());
176 setLayout(work_area_->bufferView().firstLayout());
183 void LyXView::connectBuffer(Buffer & buf)
185 if (errorsConnection_.connected())
190 boost::bind(&LyXView::showErrorList, this, _1));
194 boost::bind(&LyXView::message, this, _1));
198 boost::bind(&LyXView::busy, this, _1));
201 buf.updateTitles.connect(
202 boost::bind(&LyXView::updateWindowTitle, this));
205 buf.resetAutosaveTimers.connect(
206 boost::bind(&LyXView::resetAutosaveTimer, this));
208 readonlyConnection_ =
209 buf.readonly.connect(
210 boost::bind(&LyXView::showReadonly, this, _1));
214 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
218 void LyXView::disconnectBuffer()
220 messageConnection_.disconnect();
221 busyConnection_.disconnect();
222 titleConnection_.disconnect();
223 timerConnection_.disconnect();
224 readonlyConnection_.disconnect();
225 closingConnection_.disconnect();
229 void LyXView::showErrorList(string const & error_type)
231 ErrorList & el = buffer()->errorList(error_type);
233 getDialogs().show("errorlist", error_type);
238 void LyXView::showReadonly(bool)
241 getDialogs().updateBufferDependent(false);
245 BufferView * LyXView::view() const
247 return &work_area_->bufferView();
251 void LyXView::setLayout(string const & layout)
253 toolbars_->setLayout(layout);
257 void LyXView::updateToolbars()
259 bool const math = work_area_->bufferView().cursor().inMathed();
261 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
262 toolbars_->update(math, table);
263 // update redaonly status of open dialogs. This could also be in
264 // updateMenubar(), but since updateToolbars() and updateMenubar()
265 // are always called together it is only here.
266 getDialogs().checkStatus();
270 void LyXView::updateMenubar()
276 void LyXView::autoSave()
278 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
280 if (view()->available()) {
286 void LyXView::resetAutosaveTimer()
289 autosave_timeout_->restart();
293 void LyXView::updateLayoutChoice()
295 // Don't show any layouts without a buffer
296 if (!view()->buffer()) {
297 toolbars_->clearLayoutList();
301 // Update the layout display
302 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
303 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
306 if (work_area_->bufferView().cursor().inMathed())
309 string const & layout =
310 work_area_->bufferView().cursor().paragraph().layout()->name();
312 if (layout != current_layout) {
313 toolbars_->setLayout(layout);
314 current_layout = layout;
319 void LyXView::updateWindowTitle()
321 static string last_title = "LyX";
322 string maximize_title = "LyX";
323 string minimize_title = "LyX";
325 if (view()->available()) {
326 string const cur_title = buffer()->fileName();
327 if (!cur_title.empty()) {
328 maximize_title += ": " + makeDisplayPath(cur_title, 30);
329 minimize_title = onlyFilename(cur_title);
330 if (!buffer()->isClean()) {
331 maximize_title += _(" (changed)");
332 minimize_title += '*';
334 if (buffer()->isReadonly())
335 maximize_title += _(" (read only)");
339 if (maximize_title != last_title) {
340 setWindowTitle(maximize_title, minimize_title);
341 last_title = maximize_title;
346 void LyXView::dispatch(FuncRequest const & cmd)
348 getLyXFunc().dispatch(cmd);
352 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
354 Buffer const * buffer_ptr = 0;
356 buffer_ptr = work_area_->bufferView().buffer();
358 work_area_->bufferView().update(Update::Force);