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;
84 void LyXView::setWorkArea(WorkArea * work_area)
86 work_area_ = work_area;
100 // Start autosave timer
101 if (lyxrc.autosave) {
102 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
103 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
104 autosave_timeout_->start();
107 intl_->initKeyMapper(lyxrc.use_kbmap);
111 Buffer * LyXView::buffer() const
113 return work_area_->bufferView().buffer();
117 BufferView * LyXView::view() const
119 return &work_area_->bufferView();
123 void LyXView::setLayout(string const & layout)
125 toolbars_->setLayout(layout);
129 void LyXView::updateToolbars()
131 bool const math = work_area_->bufferView().cursor().inMathed();
133 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
134 toolbars_->update(math, table);
135 // update redaonly status of open dialogs. This could also be in
136 // updateMenubar(), but since updateToolbars() and updateMenubar()
137 // are always called together it is only here.
138 getDialogs().checkStatus();
142 void LyXView::updateMenubar()
148 void LyXView::autoSave()
150 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
152 if (view()->available()) {
158 void LyXView::resetAutosaveTimer()
161 autosave_timeout_->restart();
165 void LyXView::updateLayoutChoice()
167 // Don't show any layouts without a buffer
168 if (!view()->buffer()) {
169 toolbars_->clearLayoutList();
173 // Update the layout display
174 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
175 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
178 if (work_area_->bufferView().cursor().inMathed())
181 string const & layout =
182 work_area_->bufferView().cursor().paragraph().layout()->name();
184 if (layout != current_layout) {
185 toolbars_->setLayout(layout);
186 current_layout = layout;
191 void LyXView::updateWindowTitle()
193 static string last_title = "LyX";
194 string maximize_title = "LyX";
195 string minimize_title = "LyX";
197 if (view()->available()) {
198 string const cur_title = buffer()->fileName();
199 if (!cur_title.empty()) {
200 maximize_title += ": " + makeDisplayPath(cur_title, 30);
201 minimize_title = onlyFilename(cur_title);
202 if (!buffer()->isClean()) {
203 maximize_title += _(" (changed)");
204 minimize_title += '*';
206 if (buffer()->isReadonly())
207 maximize_title += _(" (read only)");
211 if (maximize_title != last_title) {
212 setWindowTitle(maximize_title, minimize_title);
213 last_title = maximize_title;
218 void LyXView::dispatch(FuncRequest const & cmd)
220 getLyXFunc().dispatch(cmd);
224 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
226 Buffer const * buffer_ptr = 0;
228 buffer_ptr = work_area_->bufferView().buffer();
230 work_area_->bufferView().update(Update::Force);