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.
21 #include "bufferparams.h"
22 #include "BufferView.h"
23 #include "bufferview_funcs.h"
26 #include "funcrequest.h"
33 #include "MenuBackend.h"
34 #include "paragraph.h"
36 #include "controllers/ControlCommandBuffer.h"
38 #include "support/filetools.h" // OnlyFilename()
40 #include <boost/bind.hpp>
47 using lyx::support::MakeDisplayPath;
48 using lyx::support::OnlyFilename;
53 using lyx::frontend::ControlCommandBuffer;
55 string current_layout;
59 : toolbars_(new Toolbars(*this)),
61 autosave_timeout_(new Timeout(5000)),
62 lyxfunc_(new LyXFunc(this)),
63 dialogs_(new Dialogs(*this)),
64 controlcommand_(new ControlCommandBuffer(*this))
66 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
80 // Start autosave timer
82 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
83 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
84 autosave_timeout_->start();
87 intl_->InitKeyMapper(lyxrc.use_kbmap);
91 Buffer * LyXView::buffer() const
93 return bufferview_->buffer();
97 boost::shared_ptr<BufferView> const & LyXView::view() const
103 void LyXView::setLayout(string const & layout)
105 toolbars_->setLayout(layout);
109 void LyXView::updateToolbars()
111 bool const math = bufferview_->cursor().inMathed();
113 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
114 toolbars_->update(math, table);
115 // update redaonly status of open dialogs. This could also be in
116 // updateMenubar(), but since updateToolbars() and updateMenubar()
117 // are always called together it is only here.
118 getDialogs().checkStatus();
122 void LyXView::updateMenubar()
128 void LyXView::autoSave()
130 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
132 if (view()->available()) {
133 ::AutoSave(view().get());
138 void LyXView::resetAutosaveTimer()
141 autosave_timeout_->restart();
145 void LyXView::updateLayoutChoice()
147 // Don't show any layouts without a buffer
148 if (!view()->buffer()) {
149 toolbars_->clearLayoutList();
153 // Update the layout display
154 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
155 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
158 if (bufferview_->cursor().inMathed())
161 string const & layout =
162 bufferview_->cursor().paragraph().layout()->name();
164 if (layout != current_layout) {
165 toolbars_->setLayout(layout);
166 current_layout = layout;
171 void LyXView::updateWindowTitle()
173 static string last_title = "LyX";
174 string maximize_title = "LyX";
175 string minimize_title = "LyX";
177 if (view()->available()) {
178 string const cur_title = buffer()->fileName();
179 if (!cur_title.empty()) {
180 maximize_title += ": " + MakeDisplayPath(cur_title, 30);
181 minimize_title = OnlyFilename(cur_title);
182 if (!buffer()->isClean()) {
183 maximize_title += _(" (changed)");
184 minimize_title += '*';
186 if (buffer()->isReadonly())
187 maximize_title += _(" (read only)");
191 if (maximize_title != last_title) {
192 setWindowTitle(maximize_title, minimize_title);
193 last_title = maximize_title;
198 void LyXView::dispatch(FuncRequest const & cmd)
200 getLyXFunc().dispatch(cmd);
204 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
206 Buffer const * buffer_ptr = 0;
208 buffer_ptr = bufferview_->buffer();
209 bufferview_->update();