]> git.lyx.org Git - lyx.git/blob - src/lyx_main.h
Reduce calls of ::exit()
[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/shared_ptr.hpp>
19 #include <boost/utility.hpp>
20
21 #include <list>
22 #include <string>
23
24 class Buffer;
25 class ErrorItem;
26 class InsetBase;
27 class LyXView;
28 class kb_keymap;
29 namespace lyx {
30         class Session;
31 }
32
33
34 /// initial startup
35 class LyX : boost::noncopyable {
36 public:
37         /**
38          * Execute LyX. The startup sequence is as follows:
39          * -# LyX::exec()
40          * -# LyX::priv_exec()
41          * -# lyx_gui::exec()
42          * -# LyX::exec2()
43          * Step 3 is omitted if no gui is wanted. We need lyx_gui::exec()
44          * only to create the QApplication object in the qt frontend. All
45          * attempts with static and dynamically allocated QApplication
46          * objects lead either to harmless error messages on exit
47          * ("Mutex destroy failure") or crashes (OS X).
48          */
49         static int exec(int & argc, char * argv[]);
50         /// Execute LyX (inner execution loop, \sa exec)
51         int exec2(int & argc, char * argv[]);
52         static LyX & ref();
53         static LyX const & cref();
54
55         /// in the case of failure
56         void emergencyCleanup() const;
57
58         lyx::Session & session();
59         lyx::Session const & session() const;
60
61         void addLyXView(LyXView * lyxview);
62
63         /** redraw \c inset in all the BufferViews in which it is currently
64          *  visible. If successful return a pointer to the owning Buffer.
65          */
66         Buffer const * const updateInset(InsetBase const *) const;
67
68 private:
69         static boost::scoped_ptr<LyX> singleton_;
70
71         LyX();
72         int priv_exec(int & argc, char * argv[]);
73
74         /// initial LyX set up
75         bool init();
76         /// set up the default key bindings
77         void defaultKeyBindings(kb_keymap * kbmap);
78         /// set up the default dead key bindings if requested
79         void deadKeyBindings(kb_keymap * kbmap);
80         /** Check for the existence of the user's support directory and,
81          *  if not present, create it. Exits the program if the directory
82          *  cannot be created.
83          *  \returns true if the user-side configuration script
84          *  (lib/configure) should be re-run in this directory.
85          */
86         bool queryUserLyXDir(bool explicit_userdir);
87         /// read lyxrc/preferences
88         bool readRcFile(std::string const & name);
89         /// read the given ui (menu/toolbar) file
90         bool readUIFile(std::string const & name);
91         /// read the given languages file
92         bool readLanguagesFile(std::string const & name);
93         /// read the given encodings file
94         bool readEncodingsFile(std::string const & name);
95         /// parsing of non-gui LyX options. Returns true if gui
96         bool easyParse(int & argc, char * argv[]);
97         /// shows up a parsing error on screen
98         void printError(ErrorItem const &);
99
100         /// has this user started lyx for the first time?
101         bool first_start;
102         /// the parsed command line batch command if any
103         std::string batch_command;
104
105         /// lyx session, containing lastfiles, lastfilepos, and lastopened
106         boost::scoped_ptr<lyx::Session> session_;
107         ///
108         typedef std::list<LyXView *> ViewList;
109         ViewList views_;
110
111         ///
112         bool geometryOption_;
113
114 };
115
116 #endif // LYX_MAIN_H