]> git.lyx.org Git - lyx.git/blob - src/LyX.h
2a83af88c873b7132b79f0cc5da0ed118ed2ad1b
[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 setRcGuiLanguage();
95
96         ///
97         frontend::LyXView * newLyXView();
98
99         /// Execute batch commands if available.
100         void execBatchCommands();
101
102 private:
103         /// noncopyable
104         LyX(LyX const &);
105         void operator=(LyX const &);
106
107         /// Do some cleanup in preparation of an exit.
108         void prepareExit();
109
110         /// Early exit during the initialisation process.
111         void earlyExit(int status);
112
113         /// Initialise LyX and fills-in the vector of files to be loaded.
114         /**
115         \return exit code failure if any.
116         */
117         int init(int & argc, char * argv[]);
118
119         /// Load files passed at command-line.
120         /// return true on success false if we encounter an error
121         /**
122         This method is used only in non-GUI mode.
123         */
124         bool loadFiles();
125
126         /// initial LyX set up
127         bool init();
128         /** Check for the existence of the user's support directory and,
129          *  if not present, create it. Exits the program if the directory
130          *  cannot be created.
131          *  \returns true if the user-side configuration script
132          *  (lib/configure) should be re-run in this directory.
133          */
134         bool queryUserLyXDir(bool explicit_userdir);
135         /// read lyxrc/preferences
136         bool readRcFile(std::string const & name);
137         /// read the given languages file
138         bool readLanguagesFile(std::string const & name);
139         /// read the encodings.
140         /// \param enc_name encodings definition file
141         /// \param symbols_name unicode->LaTeX mapping file
142         bool readEncodingsFile(std::string const & enc_name,
143                                std::string const & symbols_name);
144         /// parsing of non-gui LyX options.
145         void easyParse(int & argc, char * argv[]);
146         /// shows up a parsing error on screen
147         void printError(ErrorItem const &);
148
149         /// Use the Pimpl idiom to hide the internals.
150         // Mostly used for singletons.
151         struct Impl;
152         Impl * pimpl_;
153
154         /// has this user started lyx for the first time?
155         bool first_start;
156
157         friend Movers & theMovers();
158         friend Mover const & getMover(std::string  const & fmt);
159         friend void setMover(std::string const & fmt, std::string const & command);
160         friend Movers & theSystemMovers();
161         friend frontend::Application * theApp();
162         friend KeyMap & theTopLevelKeymap();
163 };
164
165 } // namespace lyx
166
167 #endif // LYX_H