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;
89 void LyXView::setWorkArea(WorkArea * work_area)
91 work_area_ = work_area;
95 void LyXView::redrawWorkArea()
103 updateLayoutChoice();
106 // Start autosave timer
107 if (lyxrc.autosave) {
108 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
109 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
110 autosave_timeout_->start();
113 intl_->initKeyMapper(lyxrc.use_kbmap);
117 Buffer * LyXView::buffer() const
119 return work_area_->bufferView().buffer();
123 BufferView * LyXView::view() const
125 return &work_area_->bufferView();
129 void LyXView::setLayout(string const & layout)
131 toolbars_->setLayout(layout);
135 void LyXView::updateToolbars()
137 bool const math = work_area_->bufferView().cursor().inMathed();
139 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
140 toolbars_->update(math, table);
141 // update redaonly status of open dialogs. This could also be in
142 // updateMenubar(), but since updateToolbars() and updateMenubar()
143 // are always called together it is only here.
144 getDialogs().checkStatus();
148 void LyXView::updateMenubar()
154 void LyXView::autoSave()
156 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
158 if (view()->available()) {
164 void LyXView::resetAutosaveTimer()
167 autosave_timeout_->restart();
171 void LyXView::updateLayoutChoice()
173 // Don't show any layouts without a buffer
174 if (!view()->buffer()) {
175 toolbars_->clearLayoutList();
179 // Update the layout display
180 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
181 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
184 if (work_area_->bufferView().cursor().inMathed())
187 string const & layout =
188 work_area_->bufferView().cursor().paragraph().layout()->name();
190 if (layout != current_layout) {
191 toolbars_->setLayout(layout);
192 current_layout = layout;
197 void LyXView::updateWindowTitle()
199 static string last_title = "LyX";
200 string maximize_title = "LyX";
201 string minimize_title = "LyX";
203 if (view()->available()) {
204 string const cur_title = buffer()->fileName();
205 if (!cur_title.empty()) {
206 maximize_title += ": " + makeDisplayPath(cur_title, 30);
207 minimize_title = onlyFilename(cur_title);
208 if (!buffer()->isClean()) {
209 maximize_title += _(" (changed)");
210 minimize_title += '*';
212 if (buffer()->isReadonly())
213 maximize_title += _(" (read only)");
217 if (maximize_title != last_title) {
218 setWindowTitle(maximize_title, minimize_title);
219 last_title = maximize_title;
224 void LyXView::dispatch(FuncRequest const & cmd)
226 getLyXFunc().dispatch(cmd);
230 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
232 Buffer const * buffer_ptr = 0;
234 buffer_ptr = work_area_->bufferView().buffer();
236 work_area_->bufferView().update(Update::Force);