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