]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.cpp
move GuiCommand into hedar of its own. InsetCommandParams.h is expensive
[lyx.git] / src / frontends / qt4 / GuiDialog.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 "GuiDialog.h"
14 #include "GuiCommand.h"
15
16 #include "GuiView.h"
17 #include "qt_helpers.h"
18 #include "FuncRequest.h"
19
20 #include "insets/InsetCommand.h"
21
22 #include "support/debug.h"
23
24 #include <QCloseEvent>
25
26 using namespace std;
27
28 namespace lyx {
29 namespace frontend {
30
31 GuiDialog::GuiDialog(GuiView & lv, QString const & name, QString const & title)
32         :  QDialog(&lv), Dialog(lv, name, "LyX: " + title), is_closing_(false)
33 {}
34
35
36 void GuiDialog::closeEvent(QCloseEvent * ev)
37 {
38         slotClose();
39         ev->accept();
40 }
41
42
43 void GuiDialog::setButtonsValid(bool valid)
44 {
45         bc().setValid(valid);
46 }
47
48
49 void GuiDialog::slotApply()
50 {
51         apply();
52         bc().apply();
53 }
54
55
56 void GuiDialog::slotOK()
57 {
58         is_closing_ = true;
59         apply();
60         is_closing_ = false;
61         hideView();
62         bc().ok();
63 }
64
65
66 void GuiDialog::slotClose()
67 {
68         hideView();
69         bc().cancel();
70 }
71
72
73 void GuiDialog::slotRestore()
74 {
75         // Tell the controller that a request to refresh the dialog's contents
76         // has been received. It's up to the controller to supply the necessary
77         // info by calling GuiDialog::updateView().
78         updateDialog();
79         bc().restore();
80 }
81
82
83 void GuiDialog::changed()
84 {
85         if (updating_)
86                 return;
87         bc().setValid(isValid());
88 }
89
90
91 void GuiDialog::enableView(bool enable)
92 {
93         bc().setReadOnly(!enable);
94         bc().setValid(enable);
95         Dialog::enableView(enable);
96 }
97
98
99 void GuiDialog::updateView()
100 {
101         setUpdatesEnabled(false);
102
103         bc().setReadOnly(isBufferReadonly());
104         // protect the BC from unwarranted state transitions
105         updating_ = true;
106         updateContents();
107         updating_ = false;
108         // The widgets may not be valid, so refresh the button controller
109         bc().refresh();
110
111         setUpdatesEnabled(true);
112 }
113
114
115 /////////////////////////////////////////////////////////////////////
116 //
117 // Command based dialogs
118 //
119 /////////////////////////////////////////////////////////////////////
120
121
122 GuiCommand::GuiCommand(GuiView & lv, QString const & name,
123         QString const & title)
124         : GuiDialog(lv, name, title), params_(insetCode(fromqstr(name))),
125                 lfun_name_(fromqstr(name))
126 {
127 }
128
129
130 bool GuiCommand::initialiseParams(string const & data)
131 {
132         // The name passed with LFUN_INSET_APPLY is also the name
133         // used to identify the mailer.
134         InsetCommand::string2params(lfun_name_, data, params_);
135         return true;
136 }
137
138
139 void GuiCommand::dispatchParams()
140 {
141         if (lfun_name_.empty())
142                 return;
143
144         string const lfun = InsetCommand::params2string(lfun_name_, params_);
145         dispatch(FuncRequest(getLfun(), lfun));
146 }
147
148 } // namespace frontend
149 } // namespace lyx
150
151 #include "GuiDialog_moc.cpp"