]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.h
Crash fix.
[lyx.git] / src / frontends / qt4 / GuiDialog.h
1 // -*- C++ -*-
2 /**
3  * \file GuiDialog.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GUIDIALOG_H
13 #define GUIDIALOG_H
14
15 #include "DialogView.h"
16 #include "ButtonController.h"
17
18 #include "insets/InsetCommandParams.h"
19
20 namespace lyx {
21 namespace frontend {
22
23 /** \c Dialog collects the different parts of a Model-Controller-View
24  *  split of a generic dialog together.
25  */
26 class GuiDialog : public DialogView
27 {
28         Q_OBJECT
29
30 public:
31         /// \param lv is the access point for the dialog to the LyX kernel.
32         /// \param name is the identifier given to the dialog by its parent
33         /// container.
34         explicit GuiDialog(GuiView & lv, std::string const & name);
35
36 public Q_SLOTS:
37         /** \name Buttons
38          *  These methods are publicly accessible because they are invoked
39          *  by the View when the user presses... guess what ;-)
40          */
41         // Restore button clicked
42         void slotRestore();
43         // OK button clicked
44         void slotOK();
45         // Apply button clicked
46         void slotApply();
47         // Close button clicked or closed from WindowManager
48         void slotClose();
49
50 public:
51         /** Check whether we may apply our data.
52          *
53          *  The buttons are disabled if not and (re-)enabled if yes.
54          */
55         void setButtonsValid(bool valid);
56
57         /** \name Dialog Components
58          *  Methods to access the various components making up a dialog.
59          */
60         //@{
61         ButtonController const & bc() const { return bc_; }
62         ButtonController & bc() { return bc_; }
63         //@}
64
65         /// the dialog has changed contents
66         virtual void changed();
67
68         virtual void enableView(bool enable);
69
70         /// default: do nothing
71         virtual void applyView() {}
72         /// default: do nothing
73         virtual void updateContents() {}
74
75 public:
76         /// is the dialog currently valid ?
77         virtual bool isValid() { return true; }
78
79 public:
80
81         /** When applying, it's useful to know whether the dialog is about
82          *  to close or not (no point refreshing the display for example).
83          */
84         bool isClosing() const { return is_closing_; }
85
86         /// Update the display of the dialog whilst it is still visible.
87         virtual void updateView();
88
89 private:
90         ButtonController bc_;
91         /// are we updating ?
92         bool updating_;
93
94         bool is_closing_;
95 };
96
97
98 class GuiCommand : public GuiDialog
99 {
100 public:
101         /// We need to know with what sort of inset we're associated.
102         // FIXME This should probably be an InsetCode
103         GuiCommand(GuiView &, std::string const & name);
104         ///
105         bool initialiseParams(std::string const & data);
106         /// clean-up on hide.
107         void clearParams() { params_.clear(); }
108         /// clean-up on hide.
109         void dispatchParams();
110         ///
111         bool isBufferDependent() const { return true; }
112
113 protected:
114         ///
115         InsetCommandParams params_;
116         //FIXME It should be possible to eliminate lfun_name_
117         //now and recover that information from params().insetType().
118         //But let's not do that quite yet.
119         /// Flags what action is taken by Kernel::dispatch()
120         std::string const lfun_name_;
121 };
122
123 } // namespace frontend
124 } // namespace lyx
125
126 #endif // GUIDIALOG_H