]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.C
Really dull and boring header shit
[lyx.git] / src / frontends / LyXView.C
1 /**
2  * \file LyXView.C
3  * Read the file COPYING
4  *
5  * \author Lars Gullik Bjønnes
6  * \author John Levon 
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "LyXView.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 "funcrequest.h"
27 #include "lyx_cb.h"
28 #include "BufferView.h"
29 #include "bufferview_funcs.h"
30
31 #include "Dialogs.h"
32 #include "Toolbar.h"
33 #include "Timeout.h"
34 #include "Menubar.h"
35 #include "controllers/ControlCommandBuffer.h"
36
37 #include "support/filetools.h" // OnlyFilename()
38
39 #include <boost/bind.hpp>
40
41 #include <sys/time.h>
42 #include <unistd.h>
43
44 using std::endl;
45
46 string current_layout;
47
48
49 LyXView::LyXView()
50         : intl_(new Intl),
51           autosave_timeout_(new Timeout(5000)),
52           lyxfunc_(new LyXFunc(this)),
53           dialogs_(new Dialogs(*this)),
54           controlcommand_(new ControlCommandBuffer(getLyXFunc()))
55 {
56         lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
57 }
58
59
60 LyXView::~LyXView()
61 {
62 }
63
64
65 void LyXView::init()
66 {
67         updateLayoutChoice();
68         updateMenubar();
69
70         // Start autosave timer
71         if (lyxrc.autosave) {
72                 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
73                 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
74                 autosave_timeout_->start();
75         }
76
77         intl_->InitKeyMapper(lyxrc.use_kbmap);
78 }
79
80
81 Buffer * LyXView::buffer() const
82 {
83         return bufferview_->buffer();
84 }
85
86
87 boost::shared_ptr<BufferView> const & LyXView::view() const
88 {
89         return bufferview_;
90 }
91
92
93 void LyXView::setLayout(string const & layout)
94 {
95         toolbar_->setLayout(layout);
96 }
97
98
99 void LyXView::updateToolbar()
100 {
101         toolbar_->update();
102 }
103
104
105 void LyXView::updateMenubar()
106 {
107         menubar_->update();
108 }
109
110
111 void LyXView::autoSave()
112 {
113         lyxerr[Debug::INFO] << "Running autoSave()" << endl;
114
115         if (view()->available()) {
116                 ::AutoSave(view().get());
117         }
118 }
119
120
121 void LyXView::resetAutosaveTimer()
122 {
123         if (lyxrc.autosave)
124                 autosave_timeout_->restart();
125 }
126
127
128 void LyXView::updateLayoutChoice()
129 {
130         // don't show any layouts without a buffer
131         if (!view()->buffer()) {
132                 toolbar_->clearLayoutList();
133                 return;
134         }
135
136         // update the layout display
137         if (toolbar_->updateLayoutList(buffer()->params.textclass)) {
138                 current_layout = buffer()->params.getLyXTextClass().defaultLayoutName();
139         }
140
141         string const & layout =
142                 bufferview_->getLyXText()->cursor.par()->layout()->name();
143
144         if (layout != current_layout) {
145                 toolbar_->setLayout(layout);
146                 current_layout = layout;
147         }
148 }
149
150
151 void LyXView::updateWindowTitle()
152 {
153         static string last_title = "LyX";
154         string title = "LyX";
155         string icon_title = "LyX";
156
157         if (view()->available()) {
158                 string const cur_title = buffer()->fileName();
159                 if (!cur_title.empty()) {
160                         title += ": " + MakeDisplayPath(cur_title, 30);
161                         if (!buffer()->isClean())
162                                 title += _(" (changed)");
163                         if (buffer()->isReadonly())
164                                 title += _(" (read only)");
165                         // Show only the filename if it's available
166                         icon_title = OnlyFilename(cur_title);
167                 }
168         }
169
170         if (title != last_title) {
171                 setWindowTitle(title, icon_title);
172                 last_title = title;
173         }
174 }
175
176
177 void LyXView::dispatch(FuncRequest const & req)
178 {
179         // substitute the correct BufferView here
180         FuncRequest r = req;
181         r.setView(view().get());
182         getLyXFunc().dispatch(r); 
183 }