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