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