]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_main.C
More ascii-export fixes and when making copy of single tabular cells now the
[lyx.git] / src / lyx_main.C
index 6993f748a23af0a2c59aa8ffdfda1748d848fb97..d95b6a9842535f740b60bab71e673078095fda9a 100644 (file)
 #pragma implementation
 #endif
 
-#include "version.h"
+#include <version.h>
 #include "lyx_main.h"
 #include "lyx_gui.h"
 #include "LyXView.h"
 #include "lyxfunc.h"
-#include "lyx_gui_misc.h"
+#include "frontends/Alert.h"
+#include "frontends/GUIRunTime.h"
 #include "lyxrc.h"
 #include "support/path.h"
 #include "support/filetools.h"
@@ -61,7 +62,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;
@@ -76,10 +77,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);
@@ -91,7 +88,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
@@ -180,8 +177,6 @@ LyX::LyX(int * argc, char * argv[])
 // A destructor is always necessary  (asierra-970604)
 LyX::~LyX()
 {
-       delete lastfiles;
-       delete lyxGUI;
 }
 
 
@@ -203,10 +198,10 @@ void error_handler(int err_sig)
        case SIGSEGV:
                lyxerr << "\nlyx: SIGSEGV signal caught" << endl;
                lyxerr <<
-                       "Sorry, you have found a bug in LyX."
-                       " If possible, please read 'Known bugs'\n"
-                       "under the Help menu and then send us "
-                       "a full bug report. Thanks!" << endl;
+                       "Sorry, you have found a bug in LyX. "
+                       "Please read the bug-reporting instructions " 
+                       "in Help->Introduction and send us a bug report, "
+                       "if necessary. Thanks !" << endl;
                break;
        case SIGTERM:
                // no comments
@@ -220,7 +215,7 @@ void error_handler(int err_sig)
        signal(SIGSEGV, SIG_DFL);
        signal(SIGTERM, SIG_DFL);
 
-       bufferlist.emergencyWriteAll();
+       LyX::emergencyCleanup();
 
        lyxerr << "Bye." << endl;
        if (err_sig!= SIGHUP && 
@@ -374,7 +369,6 @@ void LyX::init(bool gui)
                system_lyxdir = LYX_DIR;
                path_shown = true;
        }
-
        // Report the system directory if debugging is on
        if (!path_shown)
                lyxerr[Debug::INIT] << "System directory: '"
@@ -434,7 +428,7 @@ void LyX::init(bool gui)
  
         // Calculate screen dpi as average of x-DPI and y-DPI:
        if (lyxrc.use_gui) {
-               lyxrc.dpi = getScreenDPI();
+               lyxrc.dpi = GUIRunTime::getScreenDPI();
                lyxerr[Debug::INIT] << "DPI setting detected to be "
                                                 << lyxrc.dpi + 0.5 << endl;
        } else {
@@ -491,9 +485,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 +517,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
@@ -557,6 +555,19 @@ void LyX::defaultKeyBindings(kb_keymap  * kbmap)
 }
 
 
+void LyX::emergencyCleanup()
+{
+       // what to do about tmpfiles is non-obvious. we would
+       // like to delete any we find, but our lyxdir might
+       // contain documents etc. which might be helpful on
+       // a crash
+       bufferlist.emergencyWriteAll();
+       if (lyxserver)
+               lyxserver->emergencyCleanup();
+}
+
 // LyX can optionally take over the handling of deadkeys
 void LyX::deadKeyBindings(kb_keymap * kbmap)
 {
@@ -600,7 +611,7 @@ void LyX::queryUserLyXDir(bool explicit_userdir)
        // If the user specified explicitely a directory, ask whether
        // to create it (otherwise, always create it)
        if (explicit_userdir &&
-           !AskQuestion(_("You have specified an invalid LyX directory."),
+           !Alert::askQuestion(_("You have specified an invalid LyX directory."),
                         _("It is needed to keep your own configuration."),
                         _("Should I try to set it up for you (recommended)?"))) {
                lyxerr << _("Running without personal LyX directory.") << endl;
@@ -639,7 +650,7 @@ bool LyX::readRcFile(string const & name)
                lyxerr[Debug::INIT] << "Found " << name
                                    << " in " << lyxrc_path << endl;
                if (lyxrc.read(lyxrc_path) < 0) { 
-                       WriteAlert(_("LyX Warning!"), 
+                       Alert::alert(_("LyX Warning!"), 
                                   _("Error while reading ") + lyxrc_path + ".",
                                   _("Using built-in defaults."));
                        return false;
@@ -752,7 +763,6 @@ void setDebuggingLevel(string const & dbgLevel)
 // Give command line help
 void commandLineHelp()
 {
-       lyxerr << "LyX " LYX_VERSION << " of " LYX_RELEASE << endl;
        lyxerr <<
                _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
                  "Command line switches (case sensitive):\n"
@@ -770,9 +780,21 @@ void commandLineHelp()
                  "\t-i [--import] fmt file.xxx\n"
                  "                  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;
 }
 
+// Give command line version information
+void commandLineVersionInfo()
+{
+       lyxerr << "LyX " << lyx_version
+              << " of " << lyx_release_date << endl;
+       lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
+
+       lyxerr << lyx_version_info << endl;
+}
+
+
 } // namespace anon
 
 
@@ -822,6 +844,11 @@ bool LyX::easyParse(int * argc, char * argv[])
                        commandLineHelp();
                        exit(0);
                } 
+               // Check for --version or -version
+               else if (arg == "--version" || arg == "-version") {
+                       commandLineVersionInfo();
+                       exit(0);
+               }
                // Check for "-nw": No XWindows as for emacs this should
                // give a LyX that could be used in a terminal window.
                //else if (arg == "-nw") {
@@ -854,8 +881,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;
@@ -882,5 +909,3 @@ bool LyX::easyParse(int * argc, char * argv[])
 
        return gui;
 }
-
-