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>
45 using lyx::support::MakeDisplayPath;
46 using lyx::support::OnlyFilename;
51 using lyx::frontend::ControlCommandBuffer;
53 string current_layout;
57 : toolbars_(new Toolbars(*this)),
59 autosave_timeout_(new Timeout(5000)),
60 lyxfunc_(new LyXFunc(this)),
61 dialogs_(new Dialogs(*this)),
62 controlcommand_(new ControlCommandBuffer(*this))
64 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
78 // Start autosave timer
80 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
81 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
82 autosave_timeout_->start();
85 intl_->InitKeyMapper(lyxrc.use_kbmap);
89 Buffer * LyXView::buffer() const
91 return bufferview_->buffer();
95 boost::shared_ptr<BufferView> const & LyXView::view() const
101 void LyXView::setLayout(string const & layout)
103 toolbars_->setLayout(layout);
107 void LyXView::updateToolbars()
109 bool const math = bufferview_->cursor().inMathed();
111 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
112 toolbars_->update(math, table);
116 void LyXView::updateMenubar()
122 void LyXView::autoSave()
124 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
126 if (view()->available()) {
127 ::AutoSave(view().get());
132 void LyXView::resetAutosaveTimer()
135 autosave_timeout_->restart();
139 void LyXView::updateLayoutChoice()
141 // don't show any layouts without a buffer
142 if (!view()->buffer()) {
143 toolbars_->clearLayoutList();
147 // update the layout display
148 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
149 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
152 if (bufferview_->cursor().inMathed())
155 string const & layout =
156 bufferview_->cursor().paragraph().layout()->name();
158 if (layout != current_layout) {
159 toolbars_->setLayout(layout);
160 current_layout = layout;
165 void LyXView::updateWindowTitle()
167 static string last_title = "LyX";
168 string maximize_title = "LyX";
169 string minimize_title = "LyX";
171 if (view()->available()) {
172 string const cur_title = buffer()->fileName();
173 if (!cur_title.empty()) {
174 maximize_title += ": " + MakeDisplayPath(cur_title, 30);
175 minimize_title = OnlyFilename(cur_title);
176 if (!buffer()->isClean()) {
177 maximize_title += _(" (changed)");
178 minimize_title += '*';
180 if (buffer()->isReadonly())
181 maximize_title += _(" (read only)");
185 if (maximize_title != last_title) {
186 setWindowTitle(maximize_title, minimize_title);
187 last_title = maximize_title;
192 void LyXView::dispatch(FuncRequest const & cmd)
194 getLyXFunc().dispatch(cmd);
198 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
200 Buffer const * buffer_ptr = 0;
202 buffer_ptr = bufferview_->buffer();
203 bufferview_->update();