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 "bufferview_funcs.h" // CurrentState()
29 #include "BufferView.h"
30 #include "lyxtextclasslist.h"
32 #include "frontends/Dialogs.h"
33 #include "frontends/Toolbar.h"
34 #include "frontends/Timeout.h"
35 #include "frontends/Menubar.h"
37 #include "support/filetools.h" // OnlyFilename()
44 extern void AutoSave(BufferView *);
45 extern void QuitLyX();
47 string current_layout;
52 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
53 lyxfunc = new LyXFunc(this);
57 // Give the timeout some default sensible value.
58 autosave_timeout = new Timeout(5000);
60 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));
78 delete autosave_timeout;
83 void LyXView::resize()
89 /// returns the buffer currently shown in the main form.
90 Buffer * LyXView::buffer() const
92 return bufferview->buffer();
96 BufferView * LyXView::view() const
102 Toolbar * LyXView::getToolbar() const
108 void LyXView::setLayout(string const & layout)
110 toolbar->setLayout(layout);
114 void LyXView::updateToolbar()
120 LyXFunc * LyXView::getLyXFunc() const
126 MiniBuffer * LyXView::getMiniBuffer() const
132 void LyXView::message(string const & str)
134 minibuffer->message(str);
138 void LyXView::messagePush(string const & str)
140 minibuffer->messagePush(str);
144 void LyXView::messagePop()
146 minibuffer->messagePop();
150 Menubar * LyXView::getMenubar() const
156 void LyXView::updateMenubar()
158 if ((!view() || !view()->buffer())
159 && menubackend.hasMenu("main_nobuffer"))
160 menubar->set("main_nobuffer");
162 menubar->set("main");
167 Intl * LyXView::getIntl() const
173 // Callback for autosave timer
174 void LyXView::AutoSave()
176 lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
177 if (view()->available())
182 /// Reset autosave timer
183 void LyXView::resetAutosaveTimer()
186 autosave_timeout->restart();
190 void LyXView::invalidateLayoutChoice()
196 void LyXView::updateLayoutChoice()
198 // This has a side-effect that the layouts are not showed when no
199 // document is loaded.
200 if (!view() || !view()->buffer()) {
201 toolbar->clearLayoutList();
205 // Update the layout display
206 if (last_textclass != int(buffer()->params.textclass)) {
207 toolbar->updateLayoutList(true);
208 last_textclass = int(buffer()->params.textclass);
209 current_layout = textclasslist[last_textclass].defaultLayoutName();
211 toolbar->updateLayoutList(false);
214 string const & layout =
215 bufferview->getLyXText()->cursor.par()->layout();
217 if (layout != current_layout) {
218 toolbar->setLayout(layout);
219 current_layout = layout;
224 // Updates the title of the window with the filename of the current document
225 void LyXView::updateWindowTitle()
227 static string last_title = "LyX";
228 string title = "LyX";
229 string icon_title = "LyX";
231 if (view()->available()) {
232 string const cur_title = buffer()->fileName();
233 if (!cur_title.empty()) {
234 title += ": " + MakeDisplayPath(cur_title, 30);
235 if (!buffer()->isLyxClean())
236 title += _(" (Changed)");
237 if (buffer()->isReadonly())
238 title += _(" (read only)");
239 /* Show only the filename if it's available. */
240 icon_title = OnlyFilename(cur_title);
243 if (title != last_title) {
244 setWindowTitle(title, icon_title);
250 void LyXView::showState()
252 message(currentState(view()));