2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 * ====================================================== */
15 #pragma implementation
19 #include "minibuffer.h"
25 #include "MenuBackend.h"
26 #include "lyx_gui_misc.h" // [update,Close,Redraw]AllBufferRelatedDialogs
27 #include "bufferview_funcs.h" // CurrentState()
30 #include "BufferView.h"
31 #include "lyxtextclasslist.h"
33 #include "frontends/Dialogs.h"
34 #include "frontends/Toolbar.h"
35 #include "frontends/Timeout.h"
36 #include "frontends/Menubar.h"
38 #include "support/filetools.h" // OnlyFilename()
45 extern void AutoSave(BufferView *);
46 extern void QuitLyX();
48 string current_layout;
53 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
54 lyxfunc = new LyXFunc(this);
58 // Give the timeout some default sensible value.
59 autosave_timeout = new Timeout(5000);
61 dialogs_ = new Dialogs(this);
62 dialogs_->hideBufferDependent
63 .connect(SigC::slot(&CloseAllBufferRelatedDialogs));
64 Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
65 Dialogs::redrawGUI.connect(SigC::slot(&RedrawAllBufferRelatedDialogs));
77 delete autosave_timeout;
82 void LyXView::resize()
88 /// returns the buffer currently shown in the main form.
89 Buffer * LyXView::buffer() const
91 return bufferview->buffer();
95 BufferView * LyXView::view() const
101 Toolbar * LyXView::getToolbar() const
107 void LyXView::setLayout(string const & layout)
109 toolbar->setLayout(layout);
113 void LyXView::updateToolbar()
119 LyXFunc * LyXView::getLyXFunc() const
125 MiniBuffer * LyXView::getMiniBuffer() const
131 void LyXView::message(string const & str)
133 minibuffer->message(str);
137 void LyXView::messagePush(string const & str)
139 minibuffer->messagePush(str);
143 void LyXView::messagePop()
145 minibuffer->messagePop();
149 Menubar * LyXView::getMenubar() const
155 void LyXView::updateMenubar()
157 if ((!view() || !view()->buffer())
158 && menubackend.hasMenu("main_nobuffer"))
159 menubar->set("main_nobuffer");
161 menubar->set("main");
166 Intl * LyXView::getIntl() const
172 // Callback for autosave timer
173 void LyXView::AutoSave()
175 lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
176 if (view()->available())
181 /// Reset autosave timer
182 void LyXView::resetAutosaveTimer()
185 autosave_timeout->restart();
189 void LyXView::invalidateLayoutChoice()
195 void LyXView::updateLayoutChoice()
197 // This has a side-effect that the layouts are not showed when no
198 // document is loaded.
199 if (!view() || !view()->buffer()) {
200 toolbar->clearLayoutList();
204 // Update the layout display
205 if (last_textclass != int(buffer()->params.textclass)) {
206 toolbar->updateLayoutList(true);
207 last_textclass = int(buffer()->params.textclass);
208 current_layout = textclasslist[last_textclass].defaultLayoutName();
210 toolbar->updateLayoutList(false);
213 string const & layout =
214 bufferview->getLyXText()->cursor.par()->layout();
216 if (layout != current_layout) {
217 toolbar->setLayout(layout);
218 current_layout = layout;
223 // Updates the title of the window with the filename of the current document
224 void LyXView::updateWindowTitle()
226 static string last_title = "LyX";
227 string title = "LyX";
228 string icon_title = "LyX";
230 if (view()->available()) {
231 string const cur_title = buffer()->fileName();
232 if (!cur_title.empty()) {
233 title += ": " + MakeDisplayPath(cur_title, 30);
234 if (!buffer()->isLyxClean())
235 title += _(" (Changed)");
236 if (buffer()->isReadonly())
237 title += _(" (read only)");
238 /* Show only the filename if it's available. */
239 icon_title = OnlyFilename(cur_title);
242 if (title != last_title) {
243 setWindowTitle(title, icon_title);
249 void LyXView::showState()
251 message(currentState(view()));