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