]> git.lyx.org Git - lyx.git/blob - src/LyX.h
* completion infrastructure
[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 "support/strfwd.h"
18
19 namespace lyx {
20
21 namespace support {
22 class FileName;
23 }
24
25 class Buffer;
26 class BufferList;
27 class Converters;
28 class ErrorItem;
29 class Inset;
30 class LyXFunc;
31 class Server;
32 class ServerSocket;
33 class Messages;
34 class Mover;
35 class Movers;
36 class Session;
37 class KeyMap;
38 class CmdDef;
39
40 extern bool use_gui;
41 extern bool quitting;
42
43 namespace frontend {
44 class Application;
45 class LyXView;
46 }
47
48 /// initial startup
49 class LyX {
50 public:
51
52         LyX();
53         ~LyX();
54
55         /// Execute LyX.
56         int exec(int & argc, char * argv[]);
57
58         /// Try to exit LyX properly.
59         /// \p exit_code is 0 by default, if a non zero value is passed,
60         /// emergencyCleanup() will be called before exiting.
61         void exit(int exit_code = 0) const;
62
63         static LyX & ref();
64         static LyX const & cref();
65
66         /// in the case of failure
67         void emergencyCleanup() const;
68
69         ///
70         BufferList & bufferList();
71         BufferList const & bufferList() const;
72         ///
73         Session & session();
74         Session const & session() const;
75         ///
76         LyXFunc & lyxFunc();
77         LyXFunc const & lyxFunc() const;
78         ///
79         Server & server();
80         Server const & server() const;
81         ///
82         ServerSocket & socket();
83         ServerSocket const & socket() const;
84
85         ///
86         frontend::Application & application();
87         frontend::Application const & application() const;
88
89         ///
90         KeyMap & topLevelKeymap();
91         KeyMap const & topLevelKeymap() const;
92
93         ///
94         CmdDef & topLevelCmdDef();
95
96         ///
97         Converters & converters();
98         Converters & systemConverters();
99
100         ///
101         Messages & getMessages(std::string const & language);
102         ///
103         Messages & getGuiMessages();
104         ///
105         void setGuiLanguage(std::string const & language);
106
107         ///
108         frontend::LyXView * newLyXView();
109
110         /// Execute batch commands if available.
111         void execBatchCommands();
112
113         ///
114         void addFileToLoad(std::string const &);
115
116 private:
117         /// noncopyable
118         LyX(LyX const &);
119         void operator=(LyX const &);
120
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         /// initial LyX set up
140         bool init();
141         /// set up the default dead key bindings if requested
142         void deadKeyBindings(KeyMap * kbmap);
143         /** Check for the existence of the user's support directory and,
144          *  if not present, create it. Exits the program if the directory
145          *  cannot be created.
146          *  \returns true if the user-side configuration script
147          *  (lib/configure) should be re-run in this directory.
148          */
149         bool queryUserLyXDir(bool explicit_userdir);
150         /// read lyxrc/preferences
151         bool readRcFile(std::string const & name);
152         /// read the given ui (menu/toolbar) file
153         bool readUIFile(std::string const & name, bool include = false);
154         /// read the given languages file
155         bool readLanguagesFile(std::string const & name);
156         /// read the encodings.
157         /// \param enc_name encodings definition file
158         /// \param symbols_name unicode->LaTeX mapping file
159         bool readEncodingsFile(std::string const & enc_name,
160                                std::string const & symbols_name);
161         /// parsing of non-gui LyX options.
162         void easyParse(int & argc, char * argv[]);
163         /// shows up a parsing error on screen
164         void printError(ErrorItem const &);
165
166         /// Use the Pimpl idiom to hide the internals.
167         // Mostly used for singletons.
168         struct Impl;
169         Impl * pimpl_;
170
171         /// has this user started lyx for the first time?
172         bool first_start;
173
174         friend Movers & theMovers();
175         friend Mover const & getMover(std::string  const & fmt);
176         friend void setMover(std::string const & fmt, std::string const & command);
177         friend Movers & theSystemMovers();
178         friend frontend::Application * theApp();
179 };
180
181 } // namespace lyx
182
183 #endif // LYX_H