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