]> git.lyx.org Git - features.git/blobdiff - src/lyx_main.C
clear()->erase() ; lots of using directives for cxx
[features.git] / src / lyx_main.C
index cf616fbc6b9a1ca8e64571648effdbe3c7460076..4f69d52ebe1a05af8aaf101f34baf3eb52031cf8 100644 (file)
@@ -16,6 +16,8 @@
 #include "version.h"
 #include "lyx_main.h"
 #include "lyx_gui.h"
+#include "LyXView.h"
+#include "lyxfunc.h"
 #include "lyx_gui_misc.h"
 #include "lyxrc.h"
 #include "support/path.h"
@@ -30,6 +32,8 @@
 #include "gettext.h"
 #include "kbmap.h"
 
+using std::endl;
+
 extern void LoadLyXFile(string const &);
 
 string system_lyxdir;
@@ -79,7 +83,7 @@ LyX::LyX(int * argc, char * argv[])
 
        // Initialization of LyX (reads lyxrc and more)
        lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
-       init(argc, argv);
+       init(argc, argv, gui);
        lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
 
        lyxGUI->init();
@@ -114,17 +118,33 @@ LyX::LyX(int * argc, char * argv[])
 
        if (last_loaded != 0) {
                lyxerr.debug() << "Yes we loaded some files." << endl;
-               lyxGUI->regBuf(last_loaded);
+               if (lyxrc.use_gui)
+                       lyxGUI->regBuf(last_loaded);
        }
 
        // Execute batch commands if available
-       if (!batch_command.empty() && last_loaded) {
+       if (!batch_command.empty()) {
                lyxerr << "About to handle -x '" << batch_command << "'" << endl;
-               //Buffer buffer("Script Buffer");
-               //buffer.Dispatch(batch_command);
-               last_loaded->Dispatch(batch_command);
-               lyxerr << "We are done!" << endl;
-               return; // Maybe we could do something more clever than aborting..
+
+               // no buffer loaded, create one
+               if (!last_loaded)
+                       last_loaded = bufferlist.newFile("tmpfile", string());
+
+               // try to dispatch to last loaded buffer first
+               bool dispatched = last_loaded->Dispatch(batch_command);
+
+               // if this was successful, return. 
+               // Maybe we could do something more clever than aborting...
+               if (dispatched) {
+                       lyxerr << "We are done!" << endl;
+                       return;
+               }
+
+               // otherwise, let the GUI handle the batch command
+               lyxGUI->regBuf(last_loaded);
+               lyxGUI->getLyXView()->getLyXFunc()->Dispatch(batch_command);
+
+               // fall through...
        }
        
        // Let the ball begin...
@@ -142,7 +162,7 @@ LyX::~LyX()
 
 extern "C" void error_handler(int err_sig);
 
-void LyX::init(int */*argc*/, char **argv)
+void LyX::init(int */*argc*/, char **argv, bool gui)
 {
        // Install the signal handlers
        signal(SIGHUP, error_handler);
@@ -228,7 +248,7 @@ void LyX::init(int */*argc*/, char **argv)
                lyxerr[Debug::INIT]
                        << "Checking whether LyX is run in place... no"
                        << endl;
-               build_lyxdir.clear();
+               build_lyxdir.erase();
        }
 
         bool FollowLink;
@@ -333,12 +353,18 @@ void LyX::init(int */*argc*/, char **argv)
                lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
        }
 
-       // Calculate screen dpi as average of x-DPI and y-DPI:
-       Screen * scr = DefaultScreenOfDisplay(fl_get_display());
-       lyxrc.dpi = ((HeightOfScreen(scr)* 25.4 / HeightMMOfScreen(scr)) +
-                     (WidthOfScreen(scr)* 25.4 / WidthMMOfScreen(scr))) / 2;
-       lyxerr[Debug::INFO] << "DPI setting detected to be "
-                      << lyxrc.dpi + 0.5 << endl;
+       // Disable gui when either lyxrc or easyparse says so
+       if (!gui)
+               lyxrc.use_gui = false;
+        // Calculate screen dpi as average of x-DPI and y-DPI:
+       if (lyxrc.use_gui) {
+               lyxrc.dpi = getScreenDPI();
+               lyxerr[Debug::INFO] << "DPI setting detected to be "
+                                                << lyxrc.dpi + 0.5 << endl;
+       } else {
+               lyxrc.dpi = 1; // I hope this is safe
+       }
 
        //
        // Read configuration files
@@ -490,7 +516,6 @@ bool LyX::easyParse(int * argc, char * argv[])
                                Debug::showTags(lyxerr);
                                exit(0);
                        }
-                       
                } 
                // Check for "-sysdir"
                else if (arg == "-sysdir") {
@@ -511,10 +536,11 @@ bool LyX::easyParse(int * argc, char * argv[])
                        commandLineHelp();
                        exit(0);
                } 
-               // Check for "-nw": No window
-               else if (arg == "-nw") {
-                       gui = false;
-               }
+               // 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") {
+               //      gui = false;
+               //}
 
                // Check for "-x": Execute commands
                else if (arg == "-x" || arg == "--execute") {
@@ -559,17 +585,38 @@ bool LyX::easyParse(int * argc, char * argv[])
                                        lyxerr << _("Unknown file type '")
                                               << type << _("' after ")
                                               << arg << _(" switch!") << endl;
-                       }
-                       else
+                       } else
                                lyxerr << _("Missing file type [eg latex, "
                                            "ps...] after ")
                                       << arg << _(" switch!") << endl;
                }
+
+               else if (arg == "--import") {
+                       if (i + 1 < *argc) {
+                               string type(argv[i+1]);
+                               string file(argv[i+2]);
+
+                               (*argc) -= 3;
+                               for (int j = i; j < (*argc); ++j)
+                                       argv[j] = argv[j + 3];
+                               --i; // After shift, check this number again.
+       
+                               batch_command = "buffer-import " + type + " " + file;
+                               lyxerr << "batch_command: "
+                                      << batch_command << endl;
+
+                       } else
+                               lyxerr << _("Missing type [eg latex, "
+                                           "ps...] after ")
+                                      << arg << _(" switch!") << endl;
+               }
        }
+
        return gui;
 }
 
 
+extern "C"
 void error_handler(int err_sig)
 {
        switch (err_sig) {