]> git.lyx.org Git - lyx.git/blob - src/LyX.h
Enable OK/Apply buttons when resetting to class defaults.
[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         friend class LyXConsoleApp;
64 public:
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 commandline commands if no GUI was requested.
89         int execWithoutGui(int & argc, char * argv[]);
90
91         /// Execute batch commands if available.
92         void execCommands();
93
94         /// initial LyX set up
95         bool init();
96         /** Check for the existence of the user's support directory and,
97          *  if not present, create it. Exits the program if the directory
98          *  cannot be created.
99          *  \returns true if the user-side configuration script
100          *  (lib/configure) should be re-run in this directory.
101          */
102         bool queryUserLyXDir(bool explicit_userdir);
103         /// read lyxrc/preferences
104         /// \param check_format: whether to try to convert the format of
105         /// the file, if there is a mismatch.
106         bool readRcFile(std::string const & name, bool check_format = false);
107         /// read the given languages file
108         bool readLanguagesFile(std::string const & name);
109         /// read the encodings.
110         /// \param enc_name encodings definition file
111         /// \param symbols_name unicode->LaTeX mapping file
112         bool readEncodingsFile(std::string const & enc_name,
113                                std::string const & symbols_name);
114         /// parsing of non-gui LyX options.
115         void easyParse(int & argc, char * argv[]);
116         /// shows up a parsing error on screen
117         void printError(ErrorItem const &);
118
119         ///
120         Messages & messages(std::string const & language);
121
122         /// Use the Pimpl idiom to hide the internals.
123         // Mostly used for singletons.
124         struct Impl;
125         Impl * pimpl_;
126
127         /// has this user started lyx for the first time?
128         bool first_start;
129
130         friend FuncStatus getStatus(FuncRequest const & action);
131         friend DispatchResult const & dispatch(FuncRequest const & action);
132         friend void dispatch(FuncRequest const & action, DispatchResult & dr);
133         friend std::vector<std::string> & theFilesToLoad();
134         friend BufferList & theBufferList();
135         friend Server & theServer();
136         friend ServerSocket & theServerSocket();
137         friend Converters & theConverters();
138         friend Converters & theSystemConverters();
139         friend Messages const & getMessages(std::string const & language);
140         friend Messages const & getGuiMessages();
141         friend KeyMap & theTopLevelKeymap();
142         friend Movers & theMovers();
143         friend Mover const & getMover(std::string const & fmt);
144         friend void setMover(std::string const & fmt, std::string const & command);
145         friend Movers & theSystemMovers();
146         friend frontend::Application * theApp();
147         friend Session & theSession();
148         friend LaTeXFonts & theLaTeXFonts();
149         friend CmdDef & theTopLevelCmdDef();
150         friend SpellChecker * theSpellChecker();
151         friend void setSpellChecker();
152         friend void emergencyCleanup();
153         friend void execBatchCommands();
154         friend void lyx_exit(int exit_code);
155 };
156
157
158 /// in the case of failure
159 void emergencyCleanup();
160 /// Try to exit LyX properly.
161 /// \p exit_code is 0 by default, if a non zero value is passed,
162 /// emergencyCleanup() will be called before exiting.
163 void lyx_exit(int exit_code);
164 /// Execute batch commands if available.
165 void execBatchCommands();
166
167 ///
168 FuncStatus getStatus(FuncRequest const & action);
169
170 ///
171 DispatchResult const & dispatch(FuncRequest const & action);
172
173 ///
174 void dispatch(FuncRequest const & action, DispatchResult & dr);
175
176 } // namespace lyx
177
178 #endif // LYX_H