]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.C
refactor topCursorVisible() prototype a little. Compile fix
[lyx.git] / src / frontends / LyXView.C
1 /**
2  * \file LyXView.C
3  * Copyright 1995-2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Lars Gullik Bjornes
7  * \author John Levon <moz@compsoc.man.ac.uk>
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "LyXView.h"
17 #include "minibuffer.h"
18 #include "debug.h"
19 #include "intl.h"
20 #include "lyxrc.h"
21 #include "lyxtext.h"
22 #include "buffer.h"
23 #include "MenuBackend.h"
24 #include "gettext.h"
25 #include "lyxfunc.h"
26 #include "lyx_cb.h"
27 #include "BufferView.h"
28 #include "bufferview_funcs.h"
29 #include "lyxtextclasslist.h"
30
31 #include "frontends/Dialogs.h"
32 #include "frontends/Toolbar.h"
33 #include "frontends/Timeout.h"
34 #include "frontends/Menubar.h"
35
36 #include "support/filetools.h" // OnlyFilename()
37
38 #include <boost/bind.hpp>
39
40 #include <sys/time.h>
41 #include <unistd.h>
42
43 using std::endl;
44
45 extern void AutoSave(BufferView *);
46 extern void QuitLyX();
47
48 string current_layout;
49
50
51 LyXView::LyXView()
52 {
53         lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
54
55         lyxfunc_.reset(new LyXFunc(this));
56         intl_.reset(new Intl);
57
58         // Give the timeout some default sensible value.
59         autosave_timeout_.reset(new Timeout(5000));
60
61         dialogs_.reset(new Dialogs(this));
62         Dialogs::redrawGUI.connect(boost::bind(&LyXView::redraw, this));
63 }
64
65
66 LyXView::~LyXView()
67 {
68 }
69
70
71 void LyXView::resize()
72 {
73         view()->resize();
74 }
75
76
77 Buffer * LyXView::buffer() const
78 {
79         return bufferview_->buffer();
80 }
81
82
83 BufferView * LyXView::view() const
84 {
85         return bufferview_.get();
86 }
87
88
89 Toolbar * LyXView::getToolbar() const
90 {
91         return toolbar_.get();
92 }
93
94
95 void LyXView::setLayout(string const & layout)
96 {
97         toolbar_->setLayout(layout);
98 }
99
100
101 void LyXView::updateToolbar()
102 {
103         toolbar_->update();
104 }
105
106
107 LyXFunc * LyXView::getLyXFunc() const
108 {
109         return lyxfunc_.get();
110 }
111
112
113 MiniBuffer * LyXView::getMiniBuffer() const
114 {
115         return minibuffer_.get();
116 }
117
118
119 void LyXView::message(string const & str)
120 {
121         minibuffer_->message(str);
122 }
123
124
125 void LyXView::messagePush(string const & str)
126 {
127         minibuffer_->messagePush(str);
128 }
129
130
131 void LyXView::messagePop()
132 {
133         minibuffer_->messagePop();
134 }
135
136
137 Menubar * LyXView::getMenubar() const
138 {
139         return menubar_.get();
140 }
141
142
143 void LyXView::updateMenubar()
144 {
145         if (!view()->buffer() && menubackend.hasMenu("main_nobuffer")) {
146                 menubar_->set("main_nobuffer");
147         } else {
148                 menubar_->set("main");
149         }
150
151         menubar_->update();
152 }
153
154
155 Intl * LyXView::getIntl() const
156 {
157         return intl_.get();
158 }
159
160
161 void LyXView::AutoSave()
162 {
163         lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
164         if (view()->available())
165                 ::AutoSave(view());
166 }
167
168
169 void LyXView::resetAutosaveTimer()
170 {
171         if (lyxrc.autosave)
172                 autosave_timeout_->restart();
173 }
174
175
176 void LyXView::invalidateLayoutChoice()
177 {
178         last_textclass_ = -1;
179 }
180
181
182 void LyXView::updateLayoutChoice()
183 {
184         // don't show any layouts without a buffer
185         if (!view()->buffer()) {
186                 toolbar_->clearLayoutList();
187                 return;
188         }
189
190         // update the layout display
191         if (last_textclass_ != int(buffer()->params.textclass)) {
192                 toolbar_->updateLayoutList(true);
193                 last_textclass_ = int(buffer()->params.textclass);
194                 current_layout = textclasslist[last_textclass_].defaultLayoutName();
195         } else {
196                 toolbar_->updateLayoutList(false);
197         }
198
199         string const & layout =
200                 bufferview_->getLyXText()->cursor.par()->layout();
201
202         if (layout != current_layout) {
203                 toolbar_->setLayout(layout);
204                 current_layout = layout;
205         }
206 }
207
208
209 void LyXView::updateWindowTitle()
210 {
211         static string last_title = "LyX";
212         string title = "LyX";
213         string icon_title = "LyX";
214
215         if (view()->available()) {
216                 string const cur_title = buffer()->fileName();
217                 if (!cur_title.empty()) {
218                         title += ": " + MakeDisplayPath(cur_title, 30);
219                         if (!buffer()->isLyxClean())
220                                 title += _(" (changed)");
221                         if (buffer()->isReadonly())
222                                 title += _(" (read only)");
223                         // Show only the filename if it's available
224                         icon_title = OnlyFilename(cur_title);
225                 }
226         }
227
228         if (title != last_title) {
229                 setWindowTitle(title, icon_title);
230                 last_title = title;
231         }
232 }
233
234
235 void LyXView::showState()
236 {
237         message(currentState(view()));
238 }