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