]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_main.C
Fix deleting of paragraphs after undo (fix #236).
[lyx.git] / src / lyx_main.C
index 1dfd3ced2ff7c763374806bf7bd9d935566efa1c..46143a7020e2fe952b26a3979831f6b1b878be6f 100644 (file)
@@ -9,32 +9,25 @@
  * ====================================================== */
 
 #include <config.h>
-
-#include <cstdlib>
-#include <csignal>
+#include <version.h>
 
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
-#include <version.h>
 #include "lyx_main.h"
 #include "lyx_gui.h"
 #include "LyXView.h"
 #include "lyxfunc.h"
-#include "frontends/Alert.h"
-#include "frontends/GUIRunTime.h"
 #include "lyxrc.h"
-#include "support/path.h"
-#include "support/filetools.h"
 #include "buffer.h"
 #include "bufferlist.h"
 #include "debug.h"
-#include "support/FileInfo.h"
 #include "lastfiles.h"
 #include "intl.h"
 #include "lyxserver.h"
-#include "layout.h"
+//#include "layout.h"
+#include "lyxtextclasslist.h"
 #include "gettext.h"
 #include "kbmap.h"
 #include "MenuBackend.h"
 #include "encoding.h"
 #include "converter.h"
 #include "language.h"
+
+#include "frontends/Alert.h"
+#include "frontends/GUIRunTime.h"
+
+#include "support/path.h"
+#include "support/filetools.h"
+#include "support/FileInfo.h"
 #include "support/os.h"
 
+#include <cstdlib>
+#include <csignal>
+
 using std::endl;
 
 #ifndef CXX_GLOBAL_CSTD
@@ -62,7 +65,7 @@ string user_lyxdir;   // Default $HOME/.lyx
 // Should this be kept global? Asger says Yes.
 DebugStream lyxerr;
 
-LastFiles * lastfiles;
+boost::scoped_ptr<LastFiles> lastfiles;
 
 // This is the global bufferlist object
 BufferList bufferlist;
@@ -77,10 +80,6 @@ boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
 LyX::LyX(int * argc, char * argv[])
 {
-       // Prevent crash with --help
-       lyxGUI = 0;
-       lastfiles = 0;
-
        // Here we need to parse the command line. At least
        // we need to parse for "-dbg" and "-help"
        bool gui = easyParse(argc, argv);
@@ -92,7 +91,7 @@ LyX::LyX(int * argc, char * argv[])
        // Make the GUI object, and let it take care of the
        // command line arguments that concerns it.
        lyxerr[Debug::INIT] << "Initializing LyXGUI..." << endl;
-       lyxGUI = new LyXGUI(this, argc, argv, gui);
+       lyxGUI.reset(new LyXGUI(this, argc, argv, gui));
        lyxerr[Debug::INIT] << "Initializing LyXGUI...done" << endl;
 
        // Now the GUI and LyX have taken care of their arguments, so
@@ -168,7 +167,7 @@ LyX::LyX(int * argc, char * argv[])
 
                // otherwise, let the GUI handle the batch command
                lyxGUI->regBuf(last_loaded);
-               lyxGUI->getLyXView()->getLyXFunc()->dispatch(batch_command);
+               lyxGUI->getLyXView()->getLyXFunc()->verboseDispatch(batch_command, false);
 
                // fall through...
        }
@@ -181,8 +180,6 @@ LyX::LyX(int * argc, char * argv[])
 // A destructor is always necessary  (asierra-970604)
 LyX::~LyX()
 {
-       delete lastfiles;
-       delete lyxGUI;
 }
 
 
@@ -246,17 +243,17 @@ void LyX::init(bool gui)
        // Determine path of binary
        //
 
-       string fullbinpath;
        string binpath = os::binpath();
        string binname = os::binname();
-       fullbinpath = binpath;
-
+       string fullbinname = MakeAbsPath(binname, binpath);
+       
        if (binpath.empty()) {
                lyxerr << _("Warning: could not determine path of binary.")
                       << "\n"
                       << _("If you have problems, try starting LyX with an absolute path.")
                       << endl;
        }
+       lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
        lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
 
        //
@@ -290,30 +287,34 @@ void LyX::init(bool gui)
                searchpath += lyxdir + ';';
        }
 
-       // <path of binary>/TOP_SRCDIR/lib
-       build_lyxdir = MakeAbsPath("../lib", binpath);
-       if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
-               searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
-                                         binpath) + ';';
-               lyxerr[Debug::INIT] << "Checking whether LyX is run in "
-                       "place... yes" << endl;
-       } else {
-               lyxerr[Debug::INIT]
-                       << "Checking whether LyX is run in place... no"
-                       << endl;
-               build_lyxdir.erase();
+       string fullbinpath = binpath;
+       FileInfo file(fullbinname, true);
+       if (file.isLink()) {
+               lyxerr[Debug::INIT] << "binary is a link" << endl;
+               string link;
+               if (LyXReadLink(fullbinname, link)) {
+                       // Path of binary/../share/name of binary/
+                       searchpath += NormalizePath(AddPath(binpath,
+                                                           "../share/") 
+                                                   + OnlyFilename(binname));
+                       searchpath += ';';
+                       fullbinpath = link;
+                       binpath = MakeAbsPath(OnlyPath(fullbinpath));
+               }
        }
-
+       
         bool followlink;
        do {
-         // Path of binary/../share/name of binary/
+               // Path of binary/../share/name of binary/
                searchpath += NormalizePath(AddPath(binpath, "../share/") + 
                      OnlyFilename(binname)) + ';';
 
-         // Follow Symlinks
+               // Follow Symlinks
                FileInfo file(fullbinpath, true);
                followlink = file.isLink();
                if (followlink) {
+                       lyxerr << " directory " << fullbinpath
+                              << " is a link" << endl;
                        string link;
                        if (LyXReadLink(fullbinpath, link)) {
                                fullbinpath = link;
@@ -325,6 +326,20 @@ void LyX::init(bool gui)
                }
        } while (followlink);
 
+       // <path of binary>/TOP_SRCDIR/lib
+       build_lyxdir = MakeAbsPath("../lib", binpath);
+       if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
+               searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
+                                         binpath) + ';';
+               lyxerr[Debug::INIT] << "Checking whether LyX is run in "
+                       "place... yes" << endl;
+       } else {
+               lyxerr[Debug::INIT]
+                       << "Checking whether LyX is run in place... no"
+                       << endl;
+               build_lyxdir.erase();
+       }
+
        // Hardcoded dir
        searchpath += LYX_DIR;
 
@@ -419,12 +434,12 @@ void LyX::init(bool gui)
        //
 
        // Default template path: system_dir/templates
-       if (lyxrc.template_path.empty()){
+       if (lyxrc.template_path.empty()) {
                lyxrc.template_path = AddPath(system_lyxdir, "templates");
        }
    
        // Default lastfiles file: $HOME/.lyx/lastfiles
-       if (lyxrc.lastfiles.empty()){
+       if (lyxrc.lastfiles.empty()) {
                lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
        }
 
@@ -491,9 +506,9 @@ void LyX::init(bool gui)
        // load the lastfiles mini-database
        lyxerr[Debug::INIT] << "Reading lastfiles `"
                            << lyxrc.lastfiles << "'..." << endl; 
-       lastfiles = new LastFiles(lyxrc.lastfiles, 
-                                 lyxrc.check_lastfiles,
-                                 lyxrc.num_lastfiles);
+       lastfiles.reset(new LastFiles(lyxrc.lastfiles, 
+                                     lyxrc.check_lastfiles,
+                                     lyxrc.num_lastfiles));
 
        // start up the lyxserver. (is this a bit early?) (Lgb)
        // 0.12 this will be way to early, we need the GUI to be initialized
@@ -523,6 +538,10 @@ void LyX::defaultKeyBindings(kb_keymap  * kbmap)
        
        kbmap->bind("Delete", LFUN_DELETE);
        kbmap->bind("BackSpace", LFUN_BACKSPACE);
+
+       // sub- and superscript -MV
+       kbmap->bind("~S-underscore", LFUN_SUBSCRIPT);
+       kbmap->bind("~S-asciicircum", LFUN_SUPERSCRIPT);
        
        // kbmap->bindings to enable the use of the numeric keypad
        // e.g. Num Lock set
@@ -648,7 +667,7 @@ bool LyX::readRcFile(string const & name)
        lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
        
        string const lyxrc_path = LibFileSearch(string(), name);
-       if (!lyxrc_path.empty()){
+       if (!lyxrc_path.empty()) {
                lyxerr[Debug::INIT] << "Found " << name
                                    << " in " << lyxrc_path << endl;
                if (lyxrc.read(lyxrc_path) < 0) { 
@@ -713,7 +732,7 @@ void LyX::readUIFile(string const & name)
                        break;
 
                default:
-                       if(!strip(lex.getString()).empty())
+                       if (!strip(lex.getString()).empty())
                                lex.printError("LyX::ReadUIFile: "
                                               "Unknown menu tag: `$$Token'");
                        break;
@@ -883,8 +902,8 @@ bool LyX::easyParse(int * argc, char * argv[])
                }
                else if (arg == "-i" || arg == "--import") {
                        if (i + 1 < *argc) {
-                               string type(argv[i+1]);
-                               string file(argv[i+2]);
+                               string const type(argv[i+1]);
+                               string const file(argv[i+2]);
                                removeargs = 3;
        
                                batch_command = "buffer-import " + type + " " + file;