1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "frontends/LyXView.h"
18 #include "minibuffer.h"
24 #include "MenuBackend.h"
25 #include "bufferview_funcs.h" // CurrentState()
28 #include "BufferView.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()
43 extern void AutoSave(BufferView *);
44 extern void QuitLyX();
46 string current_layout;
51 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
52 lyxfunc = new LyXFunc(this);
56 // Give the timeout some default sensible value.
57 autosave_timeout = new Timeout(5000);
59 dialogs_ = new Dialogs(this);
60 Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
72 delete autosave_timeout;
77 void LyXView::resize()
83 /// returns the buffer currently shown in the main form.
84 Buffer * LyXView::buffer() const
86 return bufferview->buffer();
90 BufferView * LyXView::view() const
96 Toolbar * LyXView::getToolbar() const
102 void LyXView::setLayout(string const & layout)
104 toolbar->setLayout(layout);
108 void LyXView::updateToolbar()
114 LyXFunc * LyXView::getLyXFunc() const
120 MiniBuffer * LyXView::getMiniBuffer() const
126 void LyXView::message(string const & str)
128 minibuffer->message(str);
132 void LyXView::messagePush(string const & str)
134 minibuffer->messagePush(str);
138 void LyXView::messagePop()
140 minibuffer->messagePop();
144 Menubar * LyXView::getMenubar() const
150 void LyXView::updateMenubar()
152 if ((!view() || !view()->buffer())
153 && menubackend.hasMenu("main_nobuffer"))
154 menubar->set("main_nobuffer");
156 menubar->set("main");
161 Intl * LyXView::getIntl() const
167 // Callback for autosave timer
168 void LyXView::AutoSave()
170 lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
171 if (view()->available())
176 /// Reset autosave timer
177 void LyXView::resetAutosaveTimer()
180 autosave_timeout->restart();
184 void LyXView::invalidateLayoutChoice()
190 void LyXView::updateLayoutChoice()
192 // This has a side-effect that the layouts are not showed when no
193 // document is loaded.
194 if (!view() || !view()->buffer()) {
195 toolbar->clearLayoutList();
199 // Update the layout display
200 if (last_textclass != int(buffer()->params.textclass)) {
201 toolbar->updateLayoutList(true);
202 last_textclass = int(buffer()->params.textclass);
203 current_layout = textclasslist[last_textclass].defaultLayoutName();
205 toolbar->updateLayoutList(false);
208 string const & layout =
209 bufferview->getLyXText()->cursor.par()->layout();
211 if (layout != current_layout) {
212 toolbar->setLayout(layout);
213 current_layout = layout;
218 // Updates the title of the window with the filename of the current document
219 void LyXView::updateWindowTitle()
221 static string last_title = "LyX";
222 string title = "LyX";
223 string icon_title = "LyX";
225 if (view()->available()) {
226 string const cur_title = buffer()->fileName();
227 if (!cur_title.empty()) {
228 title += ": " + MakeDisplayPath(cur_title, 30);
229 if (!buffer()->isLyxClean())
230 title += _(" (Changed)");
231 if (buffer()->isReadonly())
232 title += _(" (read only)");
233 /* Show only the filename if it's available. */
234 icon_title = OnlyFilename(cur_title);
237 if (title != last_title) {
238 setWindowTitle(title, icon_title);
244 void LyXView::showState()
246 message(currentState(view()));