]> git.lyx.org Git - lyx.git/blob - src/lyx_main.h
78427b757300e4be690209894fad001b8b242b9c
[lyx.git] / src / lyx_main.h
1 // -*- C++ -*-
2 /**
3  * \file lyx_main.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_MAIN_H
15 #define LYX_MAIN_H
16
17 #include <boost/scoped_ptr.hpp>
18 #include <boost/utility.hpp>
19
20 #include <string>
21
22 namespace lyx {
23
24 class Buffer;
25 class BufferList;
26 class Converters;
27 class ErrorItem;
28 class IconvProcessor;
29 class InsetBase;
30 class LyXFunc;
31 class LyXServer;
32 class LyXServerSocket;
33 class LyXView;
34 class Messages;
35 class Session;
36 class kb_keymap;
37
38 extern bool use_gui;
39
40 namespace frontend { class Application; }
41
42 /// initial startup
43 class LyX : boost::noncopyable {
44 public:
45
46         LyX();
47         ~LyX();
48
49         /// Execute LyX.
50         int exec(int & argc, char * argv[]);
51
52         static LyX & ref();
53         static LyX const & cref();
54
55         /// in the case of failure
56         void emergencyCleanup() const;
57
58         ///
59         BufferList & bufferList();
60         BufferList const & bufferList() const;
61         ///
62         Session & session();
63         Session const & session() const;
64         ///
65         LyXFunc & lyxFunc();
66         LyXFunc const & lyxFunc() const;
67         ///
68         LyXServer & server();
69         LyXServer const & server() const;
70         ///
71         LyXServerSocket & socket();
72         LyXServerSocket const & socket() const;
73
74         ///
75         frontend::Application & application();
76         frontend::Application const & application() const;
77
78         ///
79         kb_keymap & topLevelKeymap();
80         kb_keymap const & topLevelKeymap() const;
81         
82         ///
83         Converters & converters();
84         Converters & systemConverters();
85
86         ///
87         Messages & getMessages(std::string const & language);
88         ///
89         Messages & getGuiMessages();
90         ///
91         void setGuiLanguage(std::string const & language);
92
93         ///
94         IconvProcessor & iconvProcessor();
95
96         LyXView * newLyXView();
97
98         /** redraw \c inset in all the BufferViews in which it is currently
99          *  visible. If successful return a pointer to the owning Buffer.
100          */
101         Buffer const * const updateInset(InsetBase const *) const;
102
103         /// Execute batch commands if available.
104         void execBatchCommands();
105
106 private:
107         /// Do some cleanup in preparation of an exit.
108         void prepareExit();
109
110         /// Early exit during the initialisation process.
111         void earlyExit(int status);
112
113         /// Initialise LyX and fills-in the vector of files to be loaded.
114         /**
115         \return exit code failure if any.
116         */
117         int init(int & argc, char * argv[]);
118
119         /// Load files passed at command-line.
120         /**
121         This method is used only in non-GUI mode.
122         */
123         void loadFiles();
124
125         /// Create a View, load files and restore GUI Session.
126         void restoreGuiSession();
127
128         /// Initialize RC font for the GUI.
129         void initGuiFont();
130
131         /// initial LyX set up
132         bool init();
133         /// set up the default key bindings
134         void defaultKeyBindings(kb_keymap * kbmap);
135         /// set up the default dead key bindings if requested
136         void deadKeyBindings(kb_keymap * kbmap);
137         /** Check for the existence of the user's support directory and,
138          *  if not present, create it. Exits the program if the directory
139          *  cannot be created.
140          *  \returns true if the user-side configuration script
141          *  (lib/configure) should be re-run in this directory.
142          */
143         bool queryUserLyXDir(bool explicit_userdir);
144         /// read lyxrc/preferences
145         bool readRcFile(std::string const & name);
146         /// read the given ui (menu/toolbar) file
147         bool readUIFile(std::string const & name);
148         /// read the given languages file
149         bool readLanguagesFile(std::string const & name);
150         /// read the given encodings file
151         bool readEncodingsFile(std::string const & name);
152         /// parsing of non-gui LyX options.
153         void easyParse(int & argc, char * argv[]);
154         /// shows up a parsing error on screen
155         void printError(ErrorItem const &);
156
157         /// has this user started lyx for the first time?
158         bool first_start;
159         /// the parsed command line batch command if any
160         std::string batch_command;
161
162         /// Use the Pimpl idiom to hide the internals.
163         struct Singletons;
164         boost::scoped_ptr<Singletons> pimpl_;
165 };
166
167 } // namespace lyx
168
169 #endif // LYX_MAIN_H