]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_main.C
get builddir!=srcdir compiling working; allow successful make even without noweb...
[lyx.git] / src / lyx_main.C
index db2e00c1aa08b3b3752b2141587736e135d6ec5c..84378364bcb54d74483b7e37c7e24688723855fe 100644 (file)
 #include <cstdlib>
 #include <csignal>
 
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include "version.h"
 #include "lyx_main.h"
 #include "lyx_gui.h"
 #include "layout.h"
 #include "gettext.h"
 #include "kbmap.h"
+#include "MenuBackend.h"
+#include "ToolbarDefaults.h"
+#include "lyxlex.h"
 
 using std::endl;
 
 extern void LoadLyXFile(string const &);
+extern void QuitLyX();
 
 string system_lyxdir;
 string build_lyxdir;
@@ -89,8 +97,6 @@ LyX::LyX(int * argc, char * argv[])
                }
        }
        
-
-
        // Initialization of LyX (reads lyxrc and more)
        lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
        init(argc, argv, gui);
@@ -131,7 +137,8 @@ LyX::LyX(int * argc, char * argv[])
 
        // Execute batch commands if available
        if (!batch_command.empty()) {
-               lyxerr << "About to handle -x '" << batch_command << "'" << endl;
+               lyxerr << "About to handle -x '"
+                      << batch_command << "'" << endl;
 
                // no buffer loaded, create one
                if (!last_loaded)
@@ -144,6 +151,7 @@ LyX::LyX(int * argc, char * argv[])
                // Maybe we could do something more clever than aborting...
                if (dispatched) {
                        lyxerr << "We are done!" << endl;
+                       QuitLyX();
                        return;
                }
 
@@ -396,13 +404,19 @@ void LyX::init(int */*argc*/, char **argv, bool gui)
        //
 
        ReadRcFile("lyxrc.defaults");
-       ReadRcFile("lyxrc");
+//     system_lyxrc = lyxrc;
+       // If there is a preferences file we read that instead
+       // of the old lyxrc file.
+       if (!ReadRcFile("preferences"))
+           ReadRcFile("lyxrc");
 
        // Ensure that we have really read a bind file, so that LyX is
        // usable.
        if (!lyxrc.hasBindFile)
                lyxrc.ReadBindFile();
 
+       // Read menus
+       ReadUIFile(lyxrc.ui_file);
 
        // Bind the X dead keys to the corresponding LyX functions if
        // necessary. 
@@ -551,13 +565,13 @@ void LyX::queryUserLyXDir(bool explicit_userdir)
 
        // Run configure in user lyx directory
        Path p(user_lyxdir);
-       system(AddName(system_lyxdir, "configure").c_str());
+       ::system(AddName(system_lyxdir, "configure").c_str());
        lyxerr << "LyX: " << _("Done!") << endl;
 }
 
 
 // Read the rc file `name'
-void LyX::ReadRcFile(string const & name)
+bool LyX::ReadRcFile(string const & name)
 {
        lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
        
@@ -569,9 +583,66 @@ void LyX::ReadRcFile(string const & name)
                        WriteAlert(_("LyX Warning!"), 
                                   _("Error while reading ")+lyxrc_path+".",
                                   _("Using built-in defaults."));
+                       return false;
                }
+               return true;
        } else
                lyxerr[Debug::INIT] << "Could not find " << name << endl;
+       return false;
+}
+
+
+// Read the ui file `name'
+void LyX::ReadUIFile(string const & name)
+{
+       enum Uitags {
+               ui_menuset = 1,
+               ui_toolbar,
+               ui_last
+       };
+
+       struct keyword_item uitags[ui_last-1] = {
+               { "menuset", ui_menuset },
+               { "toolbar", ui_toolbar }
+       };
+
+       lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
+       
+       string ui_path = LibFileSearch("ui", name, "ui");
+
+       if (ui_path.empty()) {
+               lyxerr[Debug::INIT] << "Could not find " << name << endl;
+               return;
+       }
+       
+       lyxerr[Debug::INIT] << "Found " << name
+                           << " in " << ui_path << endl;
+       LyXLex lex(uitags, ui_last - 1);
+       lex.setFile(ui_path);
+       if (!lex.IsOK()) {
+               lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
+                      << endl;
+       }
+       
+       if (lyxerr.debugging(Debug::PARSER))
+               lex.printTable(lyxerr);
+
+       while (lex.IsOK()) {
+               switch(lex.lex()) {
+               case ui_menuset: 
+                       menubackend.read(lex);
+                       break;
+
+               case ui_toolbar:
+                       toolbardefaults.read(lex);
+                       break;
+
+               default:
+                       lex.printError("LyX::ReadUFile: "
+                                      "Unknown menu tag: `$$Token'");
+                       break;
+               }
+       }
 }
 
 
@@ -591,13 +662,10 @@ void commandLineHelp()
        lyxerr <<
                _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
                  "Command line switches (case sensitive):\n"
-                 "\t-help           summarize LyX usage\n"
-                 "\t-userdir dir      try to set user directory to dir\n"
-                 "\t-sysdir dir       try to set system directory to dir\n"
-                 "\t-width x        set the width of the main window\n"
-                 "\t-height y       set the height of the main window\n"
-                 "\t-xpos x         set the x position of the main window\n"
-                 "\t-ypos y         set the y position of the main window\n"
+                 "\t-help              summarize LyX usage\n"
+                 "\t-userdir dir       try to set user directory to dir\n"
+                 "\t-sysdir dir        try to set system directory to dir\n"
+                 "\t-geometry WxH+X+Y  set geometry of the main window\n"
                   "\t-dbg feature[,feature]...\n"
                   "                  select the features to debug.\n"
                   "                  Type `lyx -dbg' to see the list of features\n"
@@ -673,22 +741,8 @@ bool LyX::easyParse(int * argc, char * argv[])
                        if (i + 1 < *argc) {
                                string type(argv[i+1]);
                                removeargs = 2;
-
-                               if (type == "tex")
-                                       type = "latex";
-                               else if (type == "ps")
-                                       type = "postscript";
-                               else if (type == "text" || type == "txt")
-                                       type = "ascii";
-
-                               if (type == "latex" || type == "postscript"
-                                   || type == "linuxdoc" || type == "docbook"
-                                   || type == "ascii" || type == "html") 
-                                       batch_command = "buffer-export " + type;
-                               else
-                                       lyxerr << _("Unknown file type '")
-                                              << type << _("' after ")
-                                              << arg << _(" switch!") << endl;
+                               batch_command = "buffer-export " + type;
+                               gui = false;
                        } else
                                lyxerr << _("Missing file type [eg latex, "
                                            "ps...] after ")