]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_main.C
* lyx_gui: create_view(), start() and exit() functions deleted.
[lyx.git] / src / lyx_main.C
index a01b2c7f47507223a4cdd8d71a6d266442765482..18e7453ff59822ca544788440489110e0e74565c 100644 (file)
 #include "lyxfunc.h"
 #include "lyxlex.h"
 #include "lyxrc.h"
-#include "lyxtextclasslist.h"
 #include "lyxserver.h"
+#include "lyxtextclasslist.h"
 #include "MenuBackend.h"
 #include "mover.h"
 #include "ToolbarBackend.h"
 
-#include "mathed/math_inset.h"
-
 #include "frontends/Alert.h"
+#include "frontends/Application.h"
 #include "frontends/lyx_gui.h"
 #include "frontends/LyXView.h"
 
 #include "support/environment.h"
 #include "support/filetools.h"
+#include "support/fontutils.h"
 #include "support/lyxlib.h"
 #include "support/convert.h"
 #include "support/os.h"
@@ -71,7 +71,6 @@ using lyx::support::getEnv;
 using lyx::support::i18nLibFileSearch;
 using lyx::support::libFileSearch;
 using lyx::support::package;
-using lyx::support::Path;
 using lyx::support::prependEnvPath;
 using lyx::support::rtrim;
 using lyx::support::Systemcall;
@@ -84,6 +83,7 @@ namespace fs = boost::filesystem;
 using std::endl;
 using std::string;
 using std::vector;
+using std::for_each;
 
 #ifndef CXX_GLOBAL_CSTD
 using std::exit;
@@ -92,11 +92,6 @@ using std::system;
 #endif
 
 
-extern LyXServer * lyxserver;
-
-// This is the global bufferlist object
-BufferList bufferlist;
-
 // convenient to have it here.
 boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
@@ -113,9 +108,12 @@ void lyx_exit(int status)
        // FIXME: We should not directly call exit(), since it only
        // guarantees a return to the system, no application cleanup.
        // This may cause troubles with not executed destructors.
-       if (lyx_gui::use_gui)
-               // lyx_gui::exit may return and only schedule the exit
-               lyx_gui::exit(status);
+       if (lyx_gui::use_gui) {
+               theApp->exit(status);
+               // Restore original font resources after Application is destroyed.
+               lyx::support::restoreFontResources();
+       }
+
        exit(status);
 }
 
@@ -133,7 +131,7 @@ void reconfigureUserLyXDir()
        string const configure_command = package().configure_command();
 
        lyxerr << lyx::to_utf8(_("LyX: reconfiguring user directory")) << endl;
-       Path p(package().user_support());
+       lyx::support::Path p(package().user_support());
        Systemcall one;
        one.startscript(Systemcall::Wait, configure_command);
        lyxerr << "LyX: " << lyx::to_utf8(_("Done!")) << endl;
@@ -222,8 +220,11 @@ int LyX::priv_exec(int & argc, char * argv[])
                                   lyx::support::top_build_dir_is_one_level_up);
 
        // Start the real execution loop.
-       if (lyx_gui::use_gui)
+       if (lyx_gui::use_gui) {
+               // Force adding of font path _before_ Application is initialized
+               lyx::support::addFontResources();
                return lyx_gui::exec(argc, argv);
+       }
        else
                return exec2(argc, argv);
 }
@@ -280,7 +281,7 @@ int LyX::exec2(int & argc, char * argv[])
                                if (b)
                                        last_loaded = b;
                        } else {
-                               Buffer * buf = bufferlist.newBuffer(s, false);
+                               Buffer * buf = theApp->bufferList().newBuffer(s, false);
                                if (loadLyXFile(buf, s)) {
                                        last_loaded = buf;
                                        ErrorList const & el = buf->errorList("Parse");
@@ -289,7 +290,7 @@ int LyX::exec2(int & argc, char * argv[])
                                                        boost::bind(&LyX::printError, this, _1));
                                }
                                else
-                                       bufferlist.release(buf);
+                                       theApp->bufferList().release(buf);
                        }
                }
 
@@ -343,7 +344,8 @@ int LyX::exec2(int & argc, char * argv[])
                        height = 0;
                }
                // create the main window
-               LyXView * view = lyx_gui::create_view(width, height, posx, posy, maximize);
+               LyXView * view = &theApp->createView(width, height, posx, posy, maximize);
+               ref().addLyXView(view);
 
                // load files
                for_each(files.begin(), files.end(),
@@ -361,7 +363,7 @@ int LyX::exec2(int & argc, char * argv[])
                // clear this list to save a few bytes of RAM
                session_->clearLastOpenedFiles();
 
-               return lyx_gui::start(view, batch_command);
+               return theApp->start(batch_command);
        } else {
                // Something went wrong above
                quitLyX(false);
@@ -663,9 +665,8 @@ void LyX::emergencyCleanup() const
        // contain documents etc. which might be helpful on
        // a crash
 
-       bufferlist.emergencyWriteAll();
-       if (lyxserver)
-               lyxserver->emergencyCleanup();
+       theApp->bufferList().emergencyWriteAll();
+       theApp->server().emergencyCleanup();
 }