]> git.lyx.org Git - lyx.git/blob - src/LyXView.C
Fix fuer #209
[lyx.git] / src / LyXView.C
1
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "LyXView.h"
19 #include "minibuffer.h"
20 #include "debug.h"
21 #include "intl.h"
22 #include "lyxrc.h"
23 #include "lyxtext.h"
24 #include "buffer.h"
25 #include "MenuBackend.h"
26 #include "lyx_gui_misc.h"       // [update,Close,Redraw]AllBufferRelatedDialogs
27 #include "bufferview_funcs.h" // CurrentState()
28 #include "gettext.h"
29 #include "lyxfunc.h"
30 #include "BufferView.h"
31
32 #include "frontends/Dialogs.h"
33 #include "frontends/Toolbar.h"
34 #include "frontends/Menubar.h"
35
36 #include "support/filetools.h"        // OnlyFilename()
37
38 #include <sys/time.h>
39 #include <unistd.h>
40
41 using std::endl;
42 using lyx::layout_type;
43
44 extern void AutoSave(BufferView *);
45 extern void QuitLyX();
46
47 layout_type current_layout = 0;
48
49
50 LyXView::LyXView()
51 {
52         lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
53         lyxfunc = new LyXFunc(this);
54
55         intl = new Intl;
56
57         dialogs_ = new Dialogs(this);
58         // temporary until all dialogs moved into Dialogs.
59         dialogs_->updateBufferDependent
60                 .connect(SigC::slot(&updateAllVisibleBufferRelatedDialogs));
61         dialogs_->hideBufferDependent
62                 .connect(SigC::slot(&CloseAllBufferRelatedDialogs));
63         Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
64         Dialogs::redrawGUI.connect(SigC::slot(&RedrawAllBufferRelatedDialogs));
65 }
66
67
68 LyXView::~LyXView()
69 {
70         delete menubar;
71         delete toolbar;
72         delete bufferview;
73         delete minibuffer;
74         delete lyxfunc;
75         delete intl;
76         delete dialogs_;
77 }
78
79
80 void LyXView::resize() 
81 {
82         view()->resize();
83 }
84
85
86 /// returns the buffer currently shown in the main form.
87 Buffer * LyXView::buffer() const
88 {
89         return bufferview->buffer();
90 }
91
92
93 BufferView * LyXView::view() const
94 {
95         return bufferview;
96 }
97
98
99 Toolbar * LyXView::getToolbar() const
100 {
101         return toolbar;
102 }
103
104
105 void LyXView::setLayout(layout_type layout)
106 {
107         toolbar->setLayout(layout);
108 }
109
110
111 void LyXView::updateToolbar()
112 {
113         toolbar->update();
114 }
115
116
117 LyXFunc * LyXView::getLyXFunc() const
118 {
119         return lyxfunc;
120 }
121
122
123 MiniBuffer * LyXView::getMiniBuffer() const
124 {
125         return minibuffer;
126 }
127
128
129 void LyXView::message(string const & str)
130 {
131         minibuffer->message(str);
132 }
133
134
135 void LyXView::messagePush(string const & str)
136 {
137         minibuffer->messagePush(str);
138 }
139
140
141 void LyXView::messagePop()
142 {
143         minibuffer->messagePop();
144 }
145
146
147 Menubar * LyXView::getMenubar() const
148 {
149         return menubar;
150 }
151
152
153 void LyXView::updateMenubar() 
154 {
155         if ((!view() || !view()->buffer())
156             && menubackend.hasMenu("main_nobuffer"))
157                 menubar->set("main_nobuffer");
158         else
159                 menubar->set("main");
160         menubar->update();
161 }
162
163
164 Intl * LyXView::getIntl() const
165 {
166         return intl;
167 }
168
169
170 // Callback for autosave timer
171 void LyXView::AutoSave()
172 {
173         lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
174         if (view()->available())
175                 ::AutoSave(view());
176 }
177
178
179 /// Reset autosave timer
180 void LyXView::resetAutosaveTimer()
181 {
182         if (lyxrc.autosave)
183                 autosave_timeout.restart();
184 }
185
186
187 void LyXView::invalidateLayoutChoice()
188 {
189         last_textclass = -1;
190 }
191
192
193 void LyXView::updateLayoutChoice()
194 {
195         // This has a side-effect that the layouts are not showed when no
196         // document is loaded.
197         if (!view() || !view()->buffer()) {
198                 toolbar->clearLayoutList();
199                 return; 
200         }
201
202         // Update the layout display
203         if (last_textclass != int(buffer()->params.textclass)) {
204                 toolbar->updateLayoutList(true);
205                 last_textclass = int(buffer()->params.textclass);
206                 current_layout = 0;
207         } else {
208                 toolbar->updateLayoutList(false);
209         }
210         
211         layout_type layout = bufferview->getLyXText()->cursor.par()->getLayout();
212
213         if (layout != current_layout) {
214                 toolbar->setLayout(layout);
215                 current_layout = layout;
216         }
217 }
218
219
220 // Updates the title of the window with the filename of the current document
221 void LyXView::updateWindowTitle()
222 {
223         static string last_title = "LyX";
224         string title = "LyX";
225         string icon_title = "LyX";
226
227         if (view()->available()) {
228                 string const cur_title = buffer()->fileName();
229                 if (!cur_title.empty()){
230                         title += ": " + MakeDisplayPath(cur_title, 30);
231                         if (!buffer()->isLyxClean())
232                                 title += _(" (Changed)");
233                         if (buffer()->isReadonly())
234                                 title += _(" (read only)");
235                         /* Show only the filename if it's available. */
236                         icon_title = OnlyFilename(cur_title);
237                 }
238         }
239         if (title != last_title) {
240                 setWindowTitle(title, icon_title);
241                 last_title = title;
242         }
243 }
244
245
246 void LyXView::showState()
247 {
248         message(currentState(view()));
249 }