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())
137 work_area_->bufferView().setBuffer(b);
140 updateLayoutChoice();
144 setLayout(work_area_->bufferView().firstLayout());
150 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
152 if (work_area_->bufferView().buffer())
155 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
156 showErrorList("Parse");
160 updateLayoutChoice();
163 connectBuffer(*work_area_->bufferView().buffer());
164 setLayout(work_area_->bufferView().firstLayout());
171 void LyXView::connectBuffer(Buffer & buf)
173 if (errorsConnection_.connected())
178 boost::bind(&LyXView::showErrorList, this, _1));
182 boost::bind(&LyXView::message, this, _1));
186 boost::bind(&LyXView::busy, this, _1));
189 buf.updateTitles.connect(
190 boost::bind(&LyXView::updateWindowTitle, this));
193 buf.resetAutosaveTimers.connect(
194 boost::bind(&LyXView::resetAutosaveTimer, this));
196 readonlyConnection_ =
197 buf.readonly.connect(
198 boost::bind(&LyXView::showReadonly, this, _1));
202 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
206 void LyXView::disconnectBuffer()
208 messageConnection_.disconnect();
209 busyConnection_.disconnect();
210 titleConnection_.disconnect();
211 timerConnection_.disconnect();
212 readonlyConnection_.disconnect();
213 closingConnection_.disconnect();
217 void LyXView::showErrorList(string const & error_type)
219 ErrorList & el = buffer()->errorList(error_type);
221 getDialogs().show("errorlist", error_type);
226 void LyXView::showReadonly(bool)
229 getDialogs().updateBufferDependent(false);
233 BufferView * LyXView::view() const
235 return &work_area_->bufferView();
239 void LyXView::setLayout(string const & layout)
241 toolbars_->setLayout(layout);
245 void LyXView::updateToolbars()
247 bool const math = work_area_->bufferView().cursor().inMathed();
249 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
250 toolbars_->update(math, table);
251 // update redaonly status of open dialogs. This could also be in
252 // updateMenubar(), but since updateToolbars() and updateMenubar()
253 // are always called together it is only here.
254 getDialogs().checkStatus();
258 void LyXView::updateMenubar()
264 void LyXView::autoSave()
266 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
268 if (view()->available()) {
274 void LyXView::resetAutosaveTimer()
277 autosave_timeout_->restart();
281 void LyXView::updateLayoutChoice()
283 // Don't show any layouts without a buffer
284 if (!view()->buffer()) {
285 toolbars_->clearLayoutList();
289 // Update the layout display
290 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
291 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
294 if (work_area_->bufferView().cursor().inMathed())
297 string const & layout =
298 work_area_->bufferView().cursor().paragraph().layout()->name();
300 if (layout != current_layout) {
301 toolbars_->setLayout(layout);
302 current_layout = layout;
307 void LyXView::updateWindowTitle()
309 static string last_title = "LyX";
310 string maximize_title = "LyX";
311 string minimize_title = "LyX";
313 if (view()->available()) {
314 string const cur_title = buffer()->fileName();
315 if (!cur_title.empty()) {
316 maximize_title += ": " + makeDisplayPath(cur_title, 30);
317 minimize_title = onlyFilename(cur_title);
318 if (!buffer()->isClean()) {
319 maximize_title += _(" (changed)");
320 minimize_title += '*';
322 if (buffer()->isReadonly())
323 maximize_title += _(" (read only)");
327 if (maximize_title != last_title) {
328 setWindowTitle(maximize_title, minimize_title);
329 last_title = maximize_title;
334 void LyXView::dispatch(FuncRequest const & cmd)
336 getLyXFunc().dispatch(cmd);
340 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
342 Buffer const * buffer_ptr = 0;
344 buffer_ptr = work_area_->bufferView().buffer();
346 work_area_->bufferView().update(Update::Force);