]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlDialogs.h
prepare writing info messages to the minibuffer
[lyx.git] / src / frontends / controllers / ControlDialogs.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2001 The LyX Team.
8  *
9  * ======================================================
10  *
11  * \file ControlDialogs.h
12  * \author Angus Leeming <a.leeming@ic.ac.uk>
13  *
14  * ControlDialog is to be used as a parent class for dialogs that are not
15  * views onto parameters of insets. (An ugly description I know, but I hope 
16  * the meaning is clear! Can anyone do any better?) Examples would be the 
17  * Document and Paragraph dialogs.
18  */
19
20 #ifndef CONTROLDIALOGS_H
21 #define CONTROLDIALOGS_H
22
23 #include "ControlConnections.h"
24 #include "debug.h"
25
26 /** Base class to control connection/disconnection of signals with the LyX
27     kernel for dialogs NOT used with insets.
28     The Base class will be either ControlConnectBI or ControlConnectBD.
29  */
30 template <class Base>
31 class ControlDialog : public Base
32 {
33 public:
34         ///
35         ControlDialog(LyXView &, Dialogs &);
36
37 protected:
38         /// Show the dialog.
39         virtual void show();
40         /// Hide the dialog.
41         virtual void hide();
42         /// Update the dialog.
43         virtual void update();
44
45         /// clean-up on hide.
46         virtual void clearParams() {}
47         /// set the params before show or update
48         virtual void setParams() {}
49
50 private:
51         /// is the dialog built ?
52         bool dialog_built_;
53 };
54
55
56 #include "LyXView.h"
57
58 template <class Base>
59 ControlDialog<Base>::ControlDialog(LyXView & lv, Dialogs & d)
60         : Base(lv, d), dialog_built_(false)
61 {}
62
63
64 template <class Base>
65 void ControlDialog<Base>::show()
66 {
67         if (isBufferDependent() && !lv_.view()->available())
68                 return;
69
70         connect();
71
72         setParams();
73         if (emergency_exit_) {
74                 hide();
75                 return;
76         }
77
78         if (!dialog_built_) {
79                 view().build();
80                 dialog_built_ = true;
81         }
82
83         bc().readOnly(isReadonly());
84         view().show();
85 }
86
87 template <class Base>
88 void ControlDialog<Base>::update()
89 {
90         if (isBufferDependent() && !lv_.view()->available())
91                 return;
92
93         setParams();
94         if (emergency_exit_) {
95                 hide();
96                 return;
97         }
98
99         bc().readOnly(isReadonly());
100         view().update();
101 }
102
103 template <class Base>
104 void ControlDialog<Base>::hide()
105 {
106         emergency_exit_ = false;
107         clearParams();
108
109         disconnect();
110         view().hide();
111 }
112
113 #endif // CONTROLDIALOGS_H