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