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 "funcrequest.h"
35 #include "MenuBackend.h"
36 #include "paragraph.h"
38 #include "controllers/ControlCommandBuffer.h"
40 #include "support/filetools.h" // OnlyFilename()
42 #include <boost/bind.hpp>
44 #ifdef HAVE_SYS_TIME_H
45 # include <sys/time.h>
51 using lyx::frontend::Gui;
52 using lyx::frontend::WorkArea;
54 using lyx::support::makeDisplayPath;
55 using lyx::support::onlyFilename;
60 using lyx::frontend::ControlCommandBuffer;
62 string current_layout;
70 LyXView::LyXView(Gui & owner)
73 toolbars_(new Toolbars(*this)),
75 autosave_timeout_(new Timeout(5000)),
76 lyxfunc_(new LyXFunc(this)),
77 dialogs_(new Dialogs(*this)),
78 controlcommand_(new ControlCommandBuffer(*this))
80 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
88 void LyXView::setWorkArea(WorkArea * work_area)
90 work_area_ = work_area;
94 void LyXView::redrawWorkArea()
101 WorkArea * LyXView::workArea()
109 updateLayoutChoice();
112 // Start autosave timer
113 if (lyxrc.autosave) {
114 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
115 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
116 autosave_timeout_->start();
119 intl_->initKeyMapper(lyxrc.use_kbmap);
123 Buffer * LyXView::buffer() const
125 return work_area_->bufferView().buffer();
129 void LyXView::setBuffer(Buffer * b)
131 work_area_->bufferView().setBuffer(b);
134 updateLayoutChoice();
137 setLayout(work_area_->bufferView().firstLayout());
142 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
144 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
147 updateLayoutChoice();
150 setLayout(work_area_->bufferView().firstLayout());
155 BufferView * LyXView::view() const
157 return &work_area_->bufferView();
161 void LyXView::setLayout(string const & layout)
163 toolbars_->setLayout(layout);
167 void LyXView::updateToolbars()
169 bool const math = work_area_->bufferView().cursor().inMathed();
171 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
172 toolbars_->update(math, table);
173 // update redaonly status of open dialogs. This could also be in
174 // updateMenubar(), but since updateToolbars() and updateMenubar()
175 // are always called together it is only here.
176 getDialogs().checkStatus();
180 void LyXView::updateMenubar()
186 void LyXView::autoSave()
188 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
190 if (view()->available()) {
196 void LyXView::resetAutosaveTimer()
199 autosave_timeout_->restart();
203 void LyXView::updateLayoutChoice()
205 // Don't show any layouts without a buffer
206 if (!view()->buffer()) {
207 toolbars_->clearLayoutList();
211 // Update the layout display
212 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
213 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
216 if (work_area_->bufferView().cursor().inMathed())
219 string const & layout =
220 work_area_->bufferView().cursor().paragraph().layout()->name();
222 if (layout != current_layout) {
223 toolbars_->setLayout(layout);
224 current_layout = layout;
229 void LyXView::updateWindowTitle()
231 static string last_title = "LyX";
232 string maximize_title = "LyX";
233 string minimize_title = "LyX";
235 if (view()->available()) {
236 string const cur_title = buffer()->fileName();
237 if (!cur_title.empty()) {
238 maximize_title += ": " + makeDisplayPath(cur_title, 30);
239 minimize_title = onlyFilename(cur_title);
240 if (!buffer()->isClean()) {
241 maximize_title += _(" (changed)");
242 minimize_title += '*';
244 if (buffer()->isReadonly())
245 maximize_title += _(" (read only)");
249 if (maximize_title != last_title) {
250 setWindowTitle(maximize_title, minimize_title);
251 last_title = maximize_title;
256 void LyXView::dispatch(FuncRequest const & cmd)
258 getLyXFunc().dispatch(cmd);
262 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
264 Buffer const * buffer_ptr = 0;
266 buffer_ptr = work_area_->bufferView().buffer();
268 work_area_->bufferView().update(Update::Force);