]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_main.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[lyx.git] / src / lyx_main.C
index e5a31af35c8b9d56d59244cf26ff141063ac6fe9..1627140e71ebdfbb4462f02ebb3530466f469939 100644 (file)
@@ -40,8 +40,6 @@
 #include "mover.h"
 #include "ToolbarBackend.h"
 
-#include "mathed/math_inset.h"
-
 #include "frontends/Alert.h"
 #include "frontends/lyx_gui.h"
 #include "frontends/LyXView.h"
@@ -71,19 +69,18 @@ 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::quoteName;
 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::mem_fun_ref;
 
 #ifndef CXX_GLOBAL_CSTD
 using std::exit;
@@ -123,8 +120,8 @@ void lyx_exit(int status)
 void showFileError(string const & error)
 {
        Alert::warning(_("Could not read configuration file"),
-                  bformat(_("Error while reading the configuration file\n%1$s.\n"
-                    "Please check your installation."), error));
+                      bformat(_("Error while reading the configuration file\n%1$s.\n"
+                          "Please check your installation."), lyx::from_utf8(error)));
 }
 
 
@@ -132,11 +129,11 @@ void reconfigureUserLyXDir()
 {
        string const configure_command = package().configure_command();
 
-       lyxerr << _("LyX: reconfiguring user directory") << endl;
-       Path p(package().user_support());
+       lyxerr << lyx::to_utf8(_("LyX: reconfiguring user directory")) << endl;
+       lyx::support::Path p(package().user_support());
        Systemcall one;
        one.startscript(Systemcall::Wait, configure_command);
-       lyxerr << "LyX: " << _("Done!") << endl;
+       lyxerr << "LyX: " << lyx::to_utf8(_("Done!")) << endl;
 }
 
 } // namespace anon
@@ -235,8 +232,9 @@ int LyX::exec2(int & argc, char * argv[])
        // other than documents
        for (int argi = 1; argi < argc ; ++argi) {
                if (argv[argi][0] == '-') {
-                       lyxerr << bformat(_("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;
                }
        }
@@ -259,14 +257,6 @@ int LyX::exec2(int & argc, char * argv[])
        if (first_start)
                files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
 
-       // if a file is specified, I assume that user wants to edit *that* file
-       if (files.empty() && lyxrc.load_session) {
-               vector<string> const & lastopened = session_->lastOpenedFiles();
-               files.insert(files.end(), lastopened.begin(), lastopened.end()  );
-       }
-       // clear this list to save a few bytes of RAM
-       session_->clearLastOpenedFiles();
-
        // Execute batch commands if available
        if (!batch_command.empty()) {
 
@@ -283,24 +273,20 @@ int LyX::exec2(int & argc, char * argv[])
                        // the filename if necessary
                        string s = fileSearch(string(), *it, "lyx");
                        if (s.empty()) {
-                               last_loaded = newFile(*it, string(), true);
+                               Buffer * const b = newFile(*it, string(), true);
+                               if (b)
+                                       last_loaded = b;
                        } else {
                                Buffer * buf = bufferlist.newBuffer(s, false);
-                               if (loadLyXFile(buf, s))
+                               if (loadLyXFile(buf, s)) {
                                        last_loaded = buf;
+                                       ErrorList const & el = buf->errorList("Parse");
+                                       if (!el.empty())
+                                               for_each(el.begin(), el.end(),
+                                                       boost::bind(&LyX::printError, this, _1));
+                               }
                                else
                                        bufferlist.release(buf);
-
-                               ErrorList const & el = buf->getErrorList();
-                               if (!el.empty()) {
-                                       // There should be a way to use the following but I (abdel) don't know
-                                       // how to make it compile on MSVC2005.
-                                       //for_each(el.begin(), el.end(), mem_fun_ref(&LyX::printError));
-                                       for (ErrorList::const_iterator it = el.begin();
-                                               it != el.end(); ++it) {
-                                                       printError(*it);
-                                       }
-                               }
                        }
                }
 
@@ -353,9 +339,26 @@ int LyX::exec2(int & argc, char * argv[])
                        width = 0;
                        height = 0;
                }
+               // create the main window
+               LyXView * view = lyx_gui::create_view(width, height, posx, posy, maximize);
+
+               // load files
+               for_each(files.begin(), files.end(),
+                       bind(&LyXView::loadLyXFile, view, _1, true));
+
+               // if a file is specified, I assume that user wants to edit *that* file
+               if (files.empty() && lyxrc.load_session) {
+                       vector<string> const & lastopened = session_->lastOpenedFiles();
+                       // do not add to the lastfile list since these files are restored from
+                       // last seesion, and should be already there (regular files), or should
+                       // not be added at all (help files).
+                       for_each(lastopened.begin(), lastopened.end(),
+                               bind(&LyXView::loadLyXFile, view, _1, false));
+               }
+               // clear this list to save a few bytes of RAM
+               session_->clearLastOpenedFiles();
 
-               return lyx_gui::start(batch_command, files, width, height, posx, posy, maximize);
-
+               return lyx_gui::start(view, batch_command);
        } else {
                // Something went wrong above
                quitLyX(false);
@@ -465,9 +468,9 @@ static void error_handler(int err_sig)
 
 void LyX::printError(ErrorItem const & ei)
 {
-       std::cerr << _("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;
 }
 
 
@@ -515,12 +518,12 @@ bool LyX::init()
        if (!lyxrc.path_prefix.empty())
                prependEnvPath("PATH", lyxrc.path_prefix);
 
-       // Check that user LyX directory is ok. We don't do that if
-       // running in batch mode.
-       if (lyx_gui::use_gui) {
-               if (queryUserLyXDir(package().explicit_user_support()))
-                       reconfigureUserLyXDir();
-       } else {
+       // Check that user LyX directory is ok.
+       if (queryUserLyXDir(package().explicit_user_support()))
+               reconfigureUserLyXDir();
+
+       // no need for a splash when there is no GUI
+       if (!lyx_gui::use_gui) {
                first_start = false;
        }
 
@@ -577,9 +580,9 @@ bool LyX::init()
        if (package().temp_dir().empty()) {
                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));
+                                                   "%1$s. Make sure that this\n"
+                                                   "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
@@ -700,7 +703,7 @@ bool needsUpdate(string const & file)
                addName(package().user_support(), file);
 
        return (! fs::exists(absfile))
-               || (fs::last_write_time(configure_script) 
+               || (fs::last_write_time(configure_script)
                    > fs::last_write_time(absfile));
 }
 
@@ -713,9 +716,9 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
        if (fs::exists(package().user_support()) &&
            fs::is_directory(package().user_support())) {
                first_start = false;
-               
-               return needsUpdate("lyxrc.defaults") 
-                       || needsUpdate("textclass.lst") 
+
+               return needsUpdate("lyxrc.defaults")
+                       || needsUpdate("textclass.lst")
                        || needsUpdate("packages.lst");
        }
 
@@ -727,23 +730,23 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
            Alert::prompt(
                    _("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()),
+                                          "LyX directory, %1$s.\n"
+                                          "It is needed to keep your own configuration."),
+                           lyx::from_utf8(package().user_support())),
                    1, 0,
                    _("&Create directory"),
                    _("&Exit LyX"))) {
-               lyxerr << _("No user LyX directory. Exiting.") << endl;
+               lyxerr << lyx::to_utf8(_("No user LyX directory. Exiting.")) << endl;
                lyx_exit(EXIT_FAILURE);
        }
 
-       lyxerr << bformat(_("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)) {
                // Failed, so let's exit.
-               lyxerr << _("Failed to create directory. Exiting.")
+               lyxerr << lyx::to_utf8(_("Failed to create directory. Exiting."))
                       << endl;
                lyx_exit(EXIT_FAILURE);
        }
@@ -899,11 +902,11 @@ typedef boost::function<int(string const &, string const &)> cmd_helper;
 int parse_dbg(string const & arg, string const &)
 {
        if (arg.empty()) {
-               lyxerr << _("List of supported debug flags:") << endl;
+               lyxerr << lyx::to_utf8(_("List of supported debug flags:")) << endl;
                Debug::showTags(lyxerr);
                exit(0);
        }
-       lyxerr << bformat(_("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());
@@ -914,7 +917,7 @@ int parse_dbg(string const & arg, string const &)
 int parse_help(string const &, string const &)
 {
        lyxerr <<
-               _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
+               lyx::to_utf8(_("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
                  "Command line switches (case sensitive):\n"
                  "\t-help              summarize LyX usage\n"
                  "\t-userdir dir       set user directory to dir\n"
@@ -931,7 +934,7 @@ int parse_help(string const &, string const &)
                  "                  where fmt is the import format of choice\n"
                  "                  and file.xxx is the file to be imported.\n"
                  "\t-version        summarize version and build info\n"
-                 "Check the LyX man page for more details.") << endl;
+                              "Check the LyX man page for more details.")) << endl;
        exit(0);
        return 0;
 }
@@ -939,7 +942,7 @@ int parse_help(string const &, string const &)
 int parse_version(string const &, string const &)
 {
        lyxerr << "LyX " << lyx_version
-              << " of " << lyx_release_date << endl;
+              << " (" << lyx_release_date << ")" << endl;
        lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
 
        lyxerr << lyx_version_info << endl;
@@ -950,7 +953,7 @@ int parse_version(string const &, string const &)
 int parse_sysdir(string const & arg, string const &)
 {
        if (arg.empty()) {
-               lyxerr << _("Missing directory for -sysdir switch") << endl;
+               lyxerr << lyx::to_utf8(_("Missing directory for -sysdir switch")) << endl;
                exit(1);
        }
        cl_system_support = arg;
@@ -960,7 +963,7 @@ int parse_sysdir(string const & arg, string const &)
 int parse_userdir(string const & arg, string const &)
 {
        if (arg.empty()) {
-               lyxerr << _("Missing directory for -userdir switch") << endl;
+               lyxerr << lyx::to_utf8(_("Missing directory for -userdir switch")) << endl;
                exit(1);
        }
        cl_user_support = arg;
@@ -970,7 +973,7 @@ int parse_userdir(string const & arg, string const &)
 int parse_execute(string const & arg, string const &)
 {
        if (arg.empty()) {
-               lyxerr << _("Missing command string after --execute switch") << endl;
+               lyxerr << lyx::to_utf8(_("Missing command string after --execute switch")) << endl;
                exit(1);
        }
        batch = arg;
@@ -980,8 +983,8 @@ int parse_execute(string const & arg, string const &)
 int parse_export(string const & type, string const &)
 {
        if (type.empty()) {
-               lyxerr << _("Missing file type [eg latex, ps...] after "
-                       "--export switch") << endl;
+               lyxerr << lyx::to_utf8(_("Missing file type [eg latex, ps...] after "
+                                        "--export switch")) << endl;
                exit(1);
        }
        batch = "buffer-export " + type;
@@ -992,12 +995,12 @@ int parse_export(string const & type, string const &)
 int parse_import(string const & type, string const & file)
 {
        if (type.empty()) {
-               lyxerr << _("Missing file type [eg latex, ps...] after "
-                       "--import switch") << endl;
+               lyxerr << lyx::to_utf8(_("Missing file type [eg latex, ps...] after "
+                                        "--import switch")) << endl;
                exit(1);
        }
        if (file.empty()) {
-               lyxerr << _("Missing filename for --import") << endl;
+               lyxerr << lyx::to_utf8(_("Missing filename for --import")) << endl;
                exit(1);
        }