]> git.lyx.org Git - lyx.git/blob - src/LyX.h
76f9d59fe3e1399e5c970c021004a92d733e05d9
[lyx.git] / src / LyX.h
1 // -*- C++ -*-
2 /**
3  * \file LyX.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  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef LYX_H
15 #define LYX_H
16
17 #include <boost/scoped_ptr.hpp>
18 #include <boost/noncopyable.hpp>
19
20 #include <string>
21
22 namespace lyx {
23
24 namespace support {
25 class FileName;
26 }
27
28 class Buffer;
29 class BufferList;
30 class Converters;
31 class ErrorItem;
32 class Inset;
33 class LyXFunc;
34 class Server;
35 class ServerSocket;
36 class Messages;
37 class Mover;
38 class Movers;
39 class Session;
40 class KeyMap;
41 class CmdDef;
42
43 extern bool use_gui;
44
45 namespace frontend {
46 class Application;
47 class LyXView;
48 }
49
50 /// initial startup
51 class LyX : boost::noncopyable {
52 public:
53
54         LyX();
55         ~LyX();
56
57         /// Execute LyX.
58         int exec(int & argc, char * argv[]);
59
60         static LyX & ref();
61         static LyX const & cref();
62
63         /// in the case of failure
64         void emergencyCleanup() const;
65
66         ///
67         BufferList & bufferList();
68         BufferList const & bufferList() const;
69         ///
70         Session & session();
71         Session const & session() const;
72         ///
73         LyXFunc & lyxFunc();
74         LyXFunc const & lyxFunc() const;
75         ///
76         Server & server();
77         Server const & server() const;
78         ///
79         ServerSocket & socket();
80         ServerSocket const & socket() const;
81
82         ///
83         frontend::Application & application();
84         frontend::Application const & application() const;
85
86         ///
87         KeyMap & topLevelKeymap();
88         KeyMap const & topLevelKeymap() const;
89
90         ///
91         CmdDef & topLevelCmdDef();
92
93         ///
94         Converters & converters();
95         Converters & systemConverters();
96
97         ///
98         Messages & getMessages(std::string const & language);
99         ///
100         Messages & getGuiMessages();
101         ///
102         void setGuiLanguage(std::string const & language);
103
104         ///
105         frontend::LyXView * newLyXView();
106
107         /** redraw \c inset in all the BufferViews in which it is currently
108          *  visible. If successful return a pointer to the owning Buffer.
109          */
110         Buffer const * updateInset(Inset const *) const;
111
112         void hideDialogs(std::string const & name, Inset * inset) const;
113
114         /// Execute batch commands if available.
115         void execBatchCommands();
116
117         ///
118         void addFileToLoad(support::FileName const &);
119
120 private:
121         /// Do some cleanup in preparation of an exit.
122         void prepareExit();
123
124         /// Early exit during the initialisation process.
125         void earlyExit(int status);
126
127         /// Initialise LyX and fills-in the vector of files to be loaded.
128         /**
129         \return exit code failure if any.
130         */
131         int init(int & argc, char * argv[]);
132
133         /// Load files passed at command-line.
134         /**
135         This method is used only in non-GUI mode.
136         */
137         void loadFiles();
138
139         /// Create a View, load files and restore GUI Session.
140         void restoreGuiSession();
141
142         /// Initialize RC font for the GUI.
143         void initGuiFont();
144
145         /// initial LyX set up
146         bool init();
147         /// set up the default dead key bindings if requested
148         void deadKeyBindings(KeyMap * kbmap);
149         /** Check for the existence of the user's support directory and,
150          *  if not present, create it. Exits the program if the directory
151          *  cannot be created.
152          *  \returns true if the user-side configuration script
153          *  (lib/configure) should be re-run in this directory.
154          */
155         bool queryUserLyXDir(bool explicit_userdir);
156         /// read lyxrc/preferences
157         bool readRcFile(std::string const & name);
158         /// read the given ui (menu/toolbar) file
159         bool readUIFile(std::string const & name, bool include = false);
160         /// read the given languages file
161         bool readLanguagesFile(std::string const & name);
162         /// read the encodings.
163         /// \param enc_name encodings definition file
164         /// \param symbols_name unicode->LaTeX mapping file
165         bool readEncodingsFile(std::string const & enc_name,
166                                std::string const & symbols_name);
167         /// parsing of non-gui LyX options.
168         void easyParse(int & argc, char * argv[]);
169         /// shows up a parsing error on screen
170         void printError(ErrorItem const &);
171
172         /// has this user started lyx for the first time?
173         bool first_start;
174         /// the parsed command line batch command if any
175         std::string batch_command;
176
177         /// Use the Pimpl idiom to hide the internals.
178         struct Singletons;
179         boost::scoped_ptr<Singletons> pimpl_;
180
181         friend Movers & theMovers();
182         friend Mover const & getMover(std::string  const & fmt);
183         friend void setMover(std::string const & fmt, std::string const & command);
184         friend Movers & theSystemMovers();
185         friend frontend::Application * theApp();
186 };
187
188 } // namespace lyx
189
190 #endif // LYX_H