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