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