]> git.lyx.org Git - lyx.git/blob - src/frontends/Dialog.cpp
Fix memory leak.
[lyx.git] / src / frontends / Dialog.cpp
1 /**
2  * \file Dialog.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Dialog.h"
14
15 #include "FuncRequest.h"
16 #include "FuncStatus.h"
17 #include "LyXFunc.h"
18
19 #include "frontends/LyXView.h"
20 #include "frontends/Dialogs.h" // FIXME
21
22 #include "Buffer.h"
23
24
25 namespace lyx {
26 namespace frontend {
27
28
29 Dialog::~Dialog()
30 {}
31
32
33 Controller::Controller(Dialog & parent)
34         : parent_(parent), lyxview_(0)
35 {}
36
37
38 Controller::Controller(Dialog * parent)
39         : parent_(*parent), lyxview_(0)
40 {}
41
42
43 Controller::~Controller()
44 {}
45
46
47 bool Controller::canApply() const
48 {
49         FuncRequest const fr(getLfun(), dialog().name());
50         FuncStatus const fs(getStatus(fr));
51         return fs.enabled();
52 }
53
54
55 void Controller::dispatch(FuncRequest const & fr) const
56 {
57         lyxview_->dispatch(fr);
58 }
59
60
61 void Controller::updateDialog(std::string const & name) const
62 {
63         dispatch(FuncRequest(LFUN_DIALOG_UPDATE, name));
64 }
65
66
67 void Controller::disconnect(std::string const & name) const
68 {
69         lyxview_->getDialogs().disconnect(name);
70 }
71
72
73 bool Controller::isBufferAvailable() const
74 {
75         return lyxview_->buffer() != 0;
76 }
77
78
79 bool Controller::isBufferReadonly() const
80 {
81         if (!lyxview_->buffer())
82                 return true;
83         return lyxview_->buffer()->isReadonly();
84 }
85
86
87 std::string const Controller::bufferFilepath() const
88 {
89         return buffer().filePath();
90 }
91
92
93 KernelDocType Controller::docType() const
94 {
95         if (buffer().isLatex())
96                 return LATEX;
97         if (buffer().isLiterate())
98                 return LITERATE;
99
100         return DOCBOOK;
101 }
102
103
104 BufferView * Controller::bufferview()
105 {
106         return lyxview_->view();
107 }
108
109
110 BufferView const * Controller::bufferview() const
111 {
112         return lyxview_->view();
113 }
114
115
116 Buffer & Controller::buffer()
117 {
118         BOOST_ASSERT(lyxview_->buffer());
119         return *lyxview_->buffer();
120 }
121
122
123 Buffer const & Controller::buffer() const
124 {
125         BOOST_ASSERT(lyxview_->buffer());
126         return *lyxview_->buffer();
127 }
128
129 } // namespace frontend
130 } // namespace lyx