3 * Copyright 1995-2002 the LyX Team
4 * Read the file COPYING
6 * \author Lars Gullik Bjornes
7 * \author John Levon <moz@compsoc.man.ac.uk>
13 #pragma implementation
17 #include "minibuffer.h"
23 #include "MenuBackend.h"
27 #include "BufferView.h"
28 #include "bufferview_funcs.h"
29 #include "lyxtextclasslist.h"
31 #include "frontends/Dialogs.h"
32 #include "frontends/Toolbar.h"
33 #include "frontends/Timeout.h"
34 #include "frontends/Menubar.h"
36 #include "support/filetools.h" // OnlyFilename()
38 #include <boost/bind.hpp>
45 string current_layout;
50 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
52 lyxfunc_.reset(new LyXFunc(this));
53 intl_.reset(new Intl);
55 // Give the timeout some default sensible value.
56 autosave_timeout_.reset(new Timeout(5000));
58 dialogs_.reset(new Dialogs(this));
72 // Start autosave timer
74 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
75 autosave_timeout_->start();
78 intl_->InitKeyMapper(lyxrc.use_kbmap);
82 Buffer * LyXView::buffer() const
84 return bufferview_->buffer();
88 BufferView * LyXView::view() const
90 return bufferview_.get();
94 Toolbar * LyXView::getToolbar() const
96 return toolbar_.get();
100 void LyXView::setLayout(string const & layout)
102 toolbar_->setLayout(layout);
106 void LyXView::updateToolbar()
112 LyXFunc * LyXView::getLyXFunc() const
114 return lyxfunc_.get();
118 MiniBuffer * LyXView::getMiniBuffer() const
120 return minibuffer_.get();
124 void LyXView::message(string const & str)
126 minibuffer_->message(str);
130 void LyXView::messagePush(string const & str)
132 minibuffer_->messagePush(str);
136 void LyXView::messagePop()
138 minibuffer_->messagePop();
142 Menubar * LyXView::getMenubar() const
144 return menubar_.get();
148 void LyXView::updateMenubar()
150 if (!view()->buffer() && menubackend.hasMenu("main_nobuffer")) {
151 menubar_->set("main_nobuffer");
153 menubar_->set("main");
160 Intl * LyXView::getIntl() const
166 void LyXView::autoSave()
168 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
170 if (view()->available()) {
176 void LyXView::resetAutosaveTimer()
179 autosave_timeout_->restart();
183 void LyXView::updateLayoutChoice()
185 // don't show any layouts without a buffer
186 if (!view()->buffer()) {
187 toolbar_->clearLayoutList();
191 // update the layout display
192 if (toolbar_->updateLayoutList(buffer()->params.textclass)) {
193 current_layout = textclasslist[buffer()->params.textclass].defaultLayoutName();
196 string const & layout =
197 bufferview_->getLyXText()->cursor.par()->layout()->name();
199 if (layout != current_layout) {
200 toolbar_->setLayout(layout);
201 current_layout = layout;
206 void LyXView::updateWindowTitle()
208 static string last_title = "LyX";
209 string title = "LyX";
210 string icon_title = "LyX";
212 if (view()->available()) {
213 string const cur_title = buffer()->fileName();
214 if (!cur_title.empty()) {
215 title += ": " + MakeDisplayPath(cur_title, 30);
216 if (!buffer()->isLyxClean())
217 title += _(" (changed)");
218 if (buffer()->isReadonly())
219 title += _(" (read only)");
220 // Show only the filename if it's available
221 icon_title = OnlyFilename(cur_title);
225 if (title != last_title) {
226 setWindowTitle(title, icon_title);
232 void LyXView::showState()
234 message(currentState(view()));