]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_main.C
* lyx_gui: parse_lyxrc() and getStatus() methods deleted.
[lyx.git] / src / lyx_main.C
index 16d231b2440cd6dcb331306842a1e18aa5051e95..958f2fdd39a9bc4fe48183b28ad16976cfc56bbc 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,17 +71,19 @@ 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;
 
+using lyx::docstring;
+
 namespace os = lyx::support::os;
 namespace fs = boost::filesystem;
 
 using std::endl;
 using std::string;
 using std::vector;
+using std::for_each;
 
 #ifndef CXX_GLOBAL_CSTD
 using std::exit;
@@ -90,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;
 
@@ -111,18 +108,21 @@ 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);
 }
 
 
 void showFileError(string const & error)
 {
-       Alert::warning(lyx::to_utf8(_("Could not read configuration file")),
-                      bformat(lyx::to_utf8(_("Error while reading the configuration file\n%1$s.\n"
-                                             "Please check your installation.")), error));
+       Alert::warning(_("Could not read configuration file"),
+                      bformat(_("Error while reading the configuration file\n%1$s.\n"
+                          "Please check your installation."), lyx::from_utf8(error)));
 }
 
 
@@ -131,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;
@@ -220,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);
 }
@@ -233,8 +236,9 @@ int LyX::exec2(int & argc, char * argv[])
        // other than documents
        for (int argi = 1; argi < argc ; ++argi) {
                if (argv[argi][0] == '-') {
-                       lyxerr << bformat(lyx::to_utf8(_("Wrong command line option `%1$s'. Exiting.")),
-                               argv[argi]) << endl;
+                       lyxerr << lyx::to_utf8(
+                               bformat(_("Wrong command line option `%1$s'. Exiting."),
+                               lyx::from_utf8(argv[argi]))) << endl;
                        return EXIT_FAILURE;
                }
        }
@@ -246,9 +250,6 @@ int LyX::exec2(int & argc, char * argv[])
        if (!success)
                return EXIT_FAILURE;
 
-       if (lyx_gui::use_gui)
-               lyx_gui::parse_lyxrc();
-
        vector<string> files;
 
        for (int argi = argc - 1; argi >= 1; --argi)
@@ -277,7 +278,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");
@@ -286,7 +287,7 @@ int LyX::exec2(int & argc, char * argv[])
                                                        boost::bind(&LyX::printError, this, _1));
                                }
                                else
-                                       bufferlist.release(buf);
+                                       theApp->bufferList().release(buf);
                        }
                }
 
@@ -340,7 +341,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(),
@@ -358,7 +360,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);
@@ -468,9 +470,9 @@ static void error_handler(int err_sig)
 
 void LyX::printError(ErrorItem const & ei)
 {
-       std::cerr << lyx::to_utf8(_("LyX: ")) << ei.error
-                 << ':' << ei.description << std::endl;
-
+       docstring tmp = _("LyX: ") + ei.error + lyx::char_type(':')
+               + ei.description;
+       std::cerr << lyx::to_utf8(tmp) << std::endl;
 }
 
 
@@ -494,11 +496,16 @@ bool LyX::init()
        }
 
        if (lyxrc.roman_font_name.empty())
-               lyxrc.roman_font_name = lyx_gui::roman_font_name();
+               lyxrc.roman_font_name = 
+                       lyx_gui::use_gui? theApp->romanFontName(): "serif";
+
        if (lyxrc.sans_font_name.empty())
-               lyxrc.sans_font_name = lyx_gui::sans_font_name();
+               lyxrc.sans_font_name =
+                       lyx_gui::use_gui? theApp->sansFontName(): "sans";
+
        if (lyxrc.typewriter_font_name.empty())
-               lyxrc.typewriter_font_name = lyx_gui::typewriter_font_name();
+               lyxrc.typewriter_font_name =
+                       lyx_gui::use_gui? theApp->typewriterFontName(): "monospace";
 
        //
        // Read configuration files
@@ -578,11 +585,11 @@ bool LyX::init()
 
        package().temp_dir() = createLyXTmpDir(lyxrc.tempdir_path);
        if (package().temp_dir().empty()) {
-               Alert::error(lyx::to_utf8(_("Could not create temporary directory")),
-                            bformat(lyx::to_utf8(_("Could not create a temporary directory in\n"
+               Alert::error(_("Could not create temporary directory"),
+                            bformat(_("Could not create a temporary directory in\n"
                                                    "%1$s. Make sure that this\n"
-                                                   "path exists and is writable and try again.")),
-                                    lyxrc.tempdir_path));
+                                                   "path exists and is writable and try again."),
+                                    lyx::from_utf8(lyxrc.tempdir_path)));
                // createLyXTmpDir() tries sufficiently hard to create a
                // usable temp dir, so the probability to come here is
                // close to zero. We therefore don't try to overcome this
@@ -660,9 +667,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();
 }
 
 
@@ -728,20 +734,20 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
        // to create it. If the user says "no", then exit.
        if (explicit_userdir &&
            Alert::prompt(
-                   lyx::to_utf8(_("Missing user LyX directory")),
-                   bformat(lyx::to_utf8(_("You have specified a non-existent user "
+                   _("Missing user LyX directory"),
+                   bformat(_("You have specified a non-existent user "
                                           "LyX directory, %1$s.\n"
-                                          "It is needed to keep your own configuration.")),
-                           package().user_support()),
+                                          "It is needed to keep your own configuration."),
+                           lyx::from_utf8(package().user_support())),
                    1, 0,
-                   lyx::to_utf8(_("&Create directory")),
-                   lyx::to_utf8(_("&Exit LyX")))) {
+                   _("&Create directory"),
+                   _("&Exit LyX"))) {
                lyxerr << lyx::to_utf8(_("No user LyX directory. Exiting.")) << endl;
                lyx_exit(EXIT_FAILURE);
        }
 
-       lyxerr << bformat(lyx::to_utf8(_("LyX: Creating directory %1$s")),
-                         package().user_support())
+       lyxerr << lyx::to_utf8(bformat(_("LyX: Creating directory %1$s"),
+                         lyx::from_utf8(package().user_support())))
               << endl;
 
        if (!createDirectory(package().user_support(), 0755)) {
@@ -906,7 +912,7 @@ int parse_dbg(string const & arg, string const &)
                Debug::showTags(lyxerr);
                exit(0);
        }
-       lyxerr << bformat(lyx::to_utf8(_("Setting debug level to %1$s")), arg) << endl;
+       lyxerr << lyx::to_utf8(bformat(_("Setting debug level to %1$s"), lyx::from_utf8(arg))) << endl;
 
        lyxerr.level(Debug::value(arg));
        Debug::showLevel(lyxerr, lyxerr.level());