]> git.lyx.org Git - lyx.git/blob - src/LyXView.C
hfilltextclean.diff
[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 using lyx::layout_type;
41
42 extern void AutoSave(BufferView *);
43 extern void QuitLyX();
44
45 layout_type current_layout = 0;
46
47
48 LyXView::LyXView()
49 {
50         lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
51         lyxfunc = new LyXFunc(this);
52
53         intl = new Intl;
54
55         dialogs_ = new Dialogs(this);
56         // temporary until all dialogs moved into Dialogs.
57         dialogs_->updateBufferDependent
58                 .connect(SigC::slot(&updateAllVisibleBufferRelatedDialogs));
59         dialogs_->hideBufferDependent
60                 .connect(SigC::slot(&CloseAllBufferRelatedDialogs));
61         Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
62         Dialogs::redrawGUI.connect(SigC::slot(&RedrawAllBufferRelatedDialogs));
63 }
64
65
66 LyXView::~LyXView()
67 {
68         delete menubar;
69         delete toolbar;
70         delete bufferview;
71         delete minibuffer;
72         delete lyxfunc;
73         delete intl;
74         delete dialogs_;
75 }
76
77
78 void LyXView::resize() 
79 {
80         view()->resize();
81 }
82
83
84 /// returns the buffer currently shown in the main form.
85 Buffer * LyXView::buffer() const
86 {
87         return bufferview->buffer();
88 }
89
90
91 BufferView * LyXView::view() const
92 {
93         return bufferview;
94 }
95
96
97 Toolbar * LyXView::getToolbar() const
98 {
99         return toolbar;
100 }
101
102
103 void LyXView::setLayout(layout_type layout)
104 {
105         toolbar->setLayout(layout);
106 }
107
108
109 void LyXView::updateToolbar()
110 {
111         toolbar->update();
112         menubar->update();
113 }
114
115
116 LyXFunc * LyXView::getLyXFunc() const
117 {
118         return lyxfunc;
119 }
120
121
122 MiniBuffer * LyXView::getMiniBuffer() const
123 {
124         return minibuffer;
125 }
126
127
128 void LyXView::message(string const & str)
129 {
130         minibuffer->message(str);
131 }
132
133
134 void LyXView::messagePush(string const & str)
135 {
136         minibuffer->messagePush(str);
137 }
138
139
140 void LyXView::messagePop()
141 {
142         minibuffer->messagePop();
143 }
144
145
146 Menubar * LyXView::getMenubar() const
147 {
148         return menubar;
149 }
150
151
152 void LyXView::updateMenubar() 
153 {
154         if ((!view() || !view()->buffer())
155             && menubackend.hasMenu("main_nobuffer"))
156                 menubar->set("main_nobuffer");
157         else
158                 menubar->set("main");
159 }
160
161
162 Intl * LyXView::getIntl() const
163 {
164         return intl;
165 }
166
167
168 // Callback for autosave timer
169 void LyXView::AutoSave()
170 {
171         lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
172         if (view()->available())
173                 ::AutoSave(view());
174 }
175
176
177 /// Reset autosave timer
178 void LyXView::resetAutosaveTimer()
179 {
180         if (lyxrc.autosave)
181                 autosave_timeout.restart();
182 }
183
184
185 void LyXView::invalidateLayoutChoice()
186 {
187         last_textclass = -1;
188 }
189
190
191 void LyXView::updateLayoutChoice()
192 {
193         // This has a side-effect that the layouts are not showed when no
194         // document is loaded.
195         if (!view() || !view()->buffer()) {
196                 toolbar->clearLayoutList();
197                 return; 
198         }
199
200         // Update the layout display
201         if (last_textclass != int(buffer()->params.textclass)) {
202                 toolbar->updateLayoutList(true);
203                 last_textclass = int(buffer()->params.textclass);
204                 current_layout = 0;
205         } else {
206                 toolbar->updateLayoutList(false);
207         }
208         
209         layout_type layout = 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         last_title = title;
239 }
240
241
242 void LyXView::showState()
243 {
244         message(currentState(view()));
245         getToolbar()->update();
246         menubar->update();
247 }