]> git.lyx.org Git - lyx.git/blob - src/LyXFunc.h
Embedding: saving inzip name to .lyx file so that embedded files can always be found...
[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 "TextClassPtr.h"
21
22 #include "support/docstring.h"
23
24 namespace lyx {
25
26 class Buffer;
27 class BufferView;
28 class FuncRequest;
29 class FuncStatus;
30 class KeySymbol;
31 class Text;
32
33 namespace support {
34 class FileName;
35 }
36
37 namespace frontend {
38 class LyXView;
39 }
40
41 /** This class encapsulates all the LyX command operations.
42     This is the class of the LyX's "high level event handler".
43     Every user command is processed here, either invocated from
44     keyboard or from the GUI. All GUI objects, including buttons and
45     menus should use this class and never call kernel functions directly.
46 */
47 class LyXFunc
48 {
49 public:
50         ///
51         explicit LyXFunc();
52
53         /// LyX dispatcher, executes lyx actions.
54         void dispatch(FuncRequest const &);
55
56         ///
57         void setLyXView(frontend::LyXView * lv);
58
59         ///
60         void initKeySequences(KeyMap * kb);
61
62         /// return the status bar state string
63         docstring const viewStatusMessage();
64
65         ///
66         void processKeySym(KeySymbol const & key, KeyModifier state);
67
68         ///
69         FuncStatus getStatus(FuncRequest const & action) const;
70
71         /// The last key was meta
72         bool wasMetaKey() const;
73
74         /// True if lyxfunc reports an error
75         bool errorStat() const { return errorstat; }
76         /// Buffer to store result messages
77         void setMessage(docstring const & m) const;
78         /// Buffer to store result messages
79         void setErrorMessage(docstring const &) const;
80         /// Buffer to store result messages
81         docstring const getMessage() const { return dispatch_buffer; }
82         /// Handle a accented char key sequence
83         void handleKeyFunc(kb_action action);
84         /// goto a bookmark
85         /// openFile: whether or not open a file if the file is not opened
86         /// switchToBuffer: whether or not switch to buffer if the buffer is
87         ///             not the current buffer
88         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
89
90         /// load a buffer into the current workarea.
91         Buffer * loadAndViewFile(support::FileName const &  name, ///< File to load.
92                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
93
94         /// cursor x position before dispatch started
95         int cursorBeforeDispatchX() const {
96                 return cursorPosBeforeDispatchX_;
97         }
98         /// cursor y position before dispatch started
99         int cursorBeforeDispatchY() const {
100                 return cursorPosBeforeDispatchY_;
101         }
102
103 private:
104         ///
105         BufferView * view() const;
106
107         ///
108         frontend::LyXView * lyx_view_;
109
110         /// the last character added to the key sequence, in UCS4 encoded form
111         char_type encoded_last_key;
112
113         ///
114         KeySequence keyseq;
115         ///
116         KeySequence cancel_meta_seq;
117         ///
118         KeyModifier meta_fake_bit;
119
120         /// cursor position before dispatch started
121         int cursorPosBeforeDispatchX_;
122         int cursorPosBeforeDispatchY_;
123
124         /// Error status, only Dispatch can change this flag
125         mutable bool errorstat;
126
127         /** Buffer to store messages and result data. Is there a
128             good reason to have this one as static in Dispatch? (Ale)
129         */
130         mutable docstring dispatch_buffer;
131
132         /// send a post-dispatch status message
133         void sendDispatchMessage(docstring const & msg,
134                 FuncRequest const & ev);
135
136         ///
137         void open(std::string const &);
138         ///
139         void doImport(std::string const &);
140         ///
141         void closeBuffer();
142         ///
143         void reloadBuffer();
144         ///
145         bool ensureBufferClean(BufferView * bv);
146         ///
147         void updateLayout(TextClassPtr const & oldlayout, Buffer * buffer);
148 };
149
150 /// Implementation is in LyX.cpp
151 extern LyXFunc & theLyXFunc();
152
153 /// Implementation is in LyX.cpp
154 extern FuncStatus getStatus(FuncRequest const & action);
155
156 /// Implementation is in LyX.cpp
157 extern void dispatch(FuncRequest const & action);
158
159 } // namespace lyx
160
161 #endif