]> git.lyx.org Git - lyx.git/blob - src/LyXFunc.h
cosmetics
[lyx.git] / src / LyXFunc.h
1 // -*- C++ -*-
2 /**
3  * \file LyXFunc.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  * \author André Pönitz
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef LYXFUNC_H
16 #define LYXFUNC_H
17
18 #include "KeySequence.h"
19 #include "lfuns.h"
20 #include "TextClass.h"
21
22 #include "support/docstring.h"
23
24 #include <boost/signals/trackable.hpp>
25
26 namespace lyx {
27
28 class Buffer;
29 class BufferView;
30 class FuncRequest;
31 class FuncStatus;
32 class KeySymbol;
33 class Text;
34
35 namespace frontend {
36 class LyXView;
37 }
38
39 /** This class encapsulates all the LyX command operations.
40     This is the class of the LyX's "high level event handler".
41     Every user command is processed here, either invocated from
42     keyboard or from the GUI. All GUI objects, including buttons and
43     menus should use this class and never call kernel functions directly.
44 */
45 class LyXFunc : public boost::signals::trackable {
46 public:
47         ///
48         explicit LyXFunc();
49
50         /// LyX dispatcher, executes lyx actions.
51         void dispatch(FuncRequest const &);
52
53         ///
54         void setLyXView(frontend::LyXView * lv);
55
56         ///
57         void initKeySequences(KeyMap * kb);
58
59         /// return the status bar state string
60         docstring const viewStatusMessage();
61
62         ///
63         void processKeySym(KeySymbol const & key, KeyModifier state);
64
65         ///
66         FuncStatus getStatus(FuncRequest const & action) const;
67
68         /// The last key was meta
69         bool wasMetaKey() const;
70
71         /// True if lyxfunc reports an error
72         bool errorStat() const { return errorstat; }
73         /// Buffer to store result messages
74         void setMessage(docstring const & m) const;
75         /// Buffer to store result messages
76         void setErrorMessage(docstring const &) const;
77         /// Buffer to store result messages
78         docstring const getMessage() const { return dispatch_buffer; }
79         /// Handle a accented char key sequence
80         void handleKeyFunc(kb_action action);
81         /// goto a bookmark
82         /// openFile: whether or not open a file if the file is not opened
83         /// switchToBuffer: whether or not switch to buffer if the buffer is
84         ///             not the current buffer
85         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
86
87 private:
88         ///
89         BufferView * view() const;
90
91         ///
92         frontend::LyXView * lyx_view_;
93
94         /// the last character added to the key sequence, in UCS4 encoded form
95         char_type encoded_last_key;
96
97         ///
98         KeySequence keyseq;
99         ///
100         KeySequence cancel_meta_seq;
101         ///
102         KeyModifier meta_fake_bit;
103
104         /// Error status, only Dispatch can change this flag
105         mutable bool errorstat;
106
107         /** Buffer to store messages and result data. Is there a
108             good reason to have this one as static in Dispatch? (Ale)
109         */
110         mutable docstring dispatch_buffer;
111
112         /// send a post-dispatch status message
113         void sendDispatchMessage(docstring const & msg,
114                 FuncRequest const & ev);
115
116         // I think the following should be moved to BufferView. (Asger)
117         ///
118         void menuNew(std::string const & argument, bool fromTemplate);
119         ///
120         void open(std::string const &);
121         ///
122         void doImport(std::string const &);
123         ///
124         void closeBuffer();
125         ///
126         void reloadBuffer();
127         ///
128         bool ensureBufferClean(BufferView * bv);
129         ///
130         void updateLayout(TextClassPtr const & oldlayout, Buffer * buffer);
131 };
132
133 /// Implementation is in LyX.cpp
134 extern LyXFunc & theLyXFunc();
135
136 /// Implementation is in LyX.cpp
137 extern FuncStatus getStatus(FuncRequest const & action);
138
139 /// Implementation is in LyX.cpp
140 extern void dispatch(FuncRequest const & action);
141
142 } // namespace lyx
143
144 #endif