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.
22 #include "bufferparams.h"
23 #include "BufferView.h"
24 #include "bufferview_funcs.h"
27 #include "funcrequest.h"
34 #include "MenuBackend.h"
35 #include "paragraph.h"
37 #include "controllers/ControlCommandBuffer.h"
39 #include "support/filetools.h" // OnlyFilename()
41 #include <boost/bind.hpp>
43 #ifdef HAVE_SYS_TIME_H
44 # include <sys/time.h>
50 using lyx::frontend::Gui;
52 using lyx::support::makeDisplayPath;
53 using lyx::support::onlyFilename;
58 using lyx::frontend::ControlCommandBuffer;
60 string current_layout;
67 LyXView::LyXView(Gui & owner)
69 toolbars_(new Toolbars(*this)),
71 autosave_timeout_(new Timeout(5000)),
72 lyxfunc_(new LyXFunc(this)),
73 dialogs_(new Dialogs(*this)),
74 controlcommand_(new ControlCommandBuffer(*this)),
77 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
80 void LyXView::setBufferView(BufferView * buffer_view)
82 bufferview_ = buffer_view;
96 // Start autosave timer
98 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
99 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
100 autosave_timeout_->start();
103 intl_->initKeyMapper(lyxrc.use_kbmap);
107 Buffer * LyXView::buffer() const
109 return bufferview_->buffer();
113 BufferView * LyXView::view() const
119 void LyXView::setLayout(string const & layout)
121 toolbars_->setLayout(layout);
125 void LyXView::updateToolbars()
127 bool const math = bufferview_->cursor().inMathed();
129 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
130 toolbars_->update(math, table);
131 // update redaonly status of open dialogs. This could also be in
132 // updateMenubar(), but since updateToolbars() and updateMenubar()
133 // are always called together it is only here.
134 getDialogs().checkStatus();
138 void LyXView::updateMenubar()
144 void LyXView::autoSave()
146 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
148 if (view()->available()) {
154 void LyXView::resetAutosaveTimer()
157 autosave_timeout_->restart();
161 void LyXView::updateLayoutChoice()
163 // Don't show any layouts without a buffer
164 if (!view()->buffer()) {
165 toolbars_->clearLayoutList();
169 // Update the layout display
170 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
171 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
174 if (bufferview_->cursor().inMathed())
177 string const & layout =
178 bufferview_->cursor().paragraph().layout()->name();
180 if (layout != current_layout) {
181 toolbars_->setLayout(layout);
182 current_layout = layout;
187 void LyXView::updateWindowTitle()
189 static string last_title = "LyX";
190 string maximize_title = "LyX";
191 string minimize_title = "LyX";
193 if (view()->available()) {
194 string const cur_title = buffer()->fileName();
195 if (!cur_title.empty()) {
196 maximize_title += ": " + makeDisplayPath(cur_title, 30);
197 minimize_title = onlyFilename(cur_title);
198 if (!buffer()->isClean()) {
199 maximize_title += _(" (changed)");
200 minimize_title += '*';
202 if (buffer()->isReadonly())
203 maximize_title += _(" (read only)");
207 if (maximize_title != last_title) {
208 setWindowTitle(maximize_title, minimize_title);
209 last_title = maximize_title;
214 void LyXView::dispatch(FuncRequest const & cmd)
216 getLyXFunc().dispatch(cmd);
220 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
222 Buffer const * buffer_ptr = 0;
224 buffer_ptr = bufferview_->buffer();
226 bufferview_->update(Update::Force);