]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_main.C
Updates from Bennett and myself.
[lyx.git] / src / lyx_main.C
index a5d29c76b484d58c76ffb728d68ff3e7140de456..6833bc16c0c1a3e43853416510868c1b07cea200 100644 (file)
@@ -74,6 +74,7 @@ using support::bformat;
 using support::createDirectory;
 using support::createLyXTmpDir;
 using support::destroyDir;
+using support::FileName;
 using support::fileSearch;
 using support::getEnv;
 using support::i18nLibFileSearch;
@@ -331,7 +332,29 @@ int LyX::exec(int & argc, char * argv[])
        
        if (!use_gui) {
                // FIXME: create a ConsoleApplication
-               return execBatchCommands(argc, argv, files);
+               int exit_status = loadFiles(argc, argv, files);
+               if (exit_status) {
+                       prepareExit();
+                       return exit_status;
+               }
+
+               if (batch_command.empty() || pimpl_->buffer_list_.empty()) {
+                       prepareExit();
+                       return EXIT_SUCCESS;
+               }
+
+               BufferList::iterator begin = pimpl_->buffer_list_.begin();
+               BufferList::iterator end = pimpl_->buffer_list_.end();
+
+               bool final_success = false;
+               for (BufferList::iterator I = begin; I != end; ++I) {
+                       Buffer * buf = *I;
+                       bool success = false;
+                       buf->dispatch(batch_command, &success);
+                       final_success |= success;                       
+               }
+               prepareExit();
+               return !final_success;
        }
 
        // Force adding of font path _before_ Application is initialized
@@ -339,10 +362,14 @@ int LyX::exec(int & argc, char * argv[])
 
        // Let the frontend parse and remove all arguments that it knows
        pimpl_->application_.reset(createApplication(argc, argv));
+       // FIXME: this global pointer should probably go.
+       theApp = pimpl_->application_.get();
+
+       initGuiFont();
 
        // Parse and remove all known arguments in the LyX singleton
        // Give an error for all remaining ones.
-       int exit_status = execBatchCommands(argc, argv, files);
+       int exit_status = loadFiles(argc, argv, files);
        if (exit_status) {
                // Kill the application object before exiting.
                pimpl_->application_.reset();
@@ -351,9 +378,6 @@ int LyX::exec(int & argc, char * argv[])
                return exit_status;
        }
 
-       initGuiFont();
-       // FIXME: this global pointer should probably go.
-       theApp = pimpl_->application_.get();
        restoreGuiSession(files);
        // Start the real execution loop.
 
@@ -368,12 +392,7 @@ int LyX::exec(int & argc, char * argv[])
        pimpl_->lyx_socket_.reset(new LyXServerSocket(&pimpl_->lyxfunc_, 
                support::os::internal_path(package().temp_dir() + "/lyxsocket")));
 
-       // handle the batch commands the user asked for
-       if (!batch_command.empty()) {
-               pimpl_->lyxfunc_.dispatch(lyxaction.lookupFunc(batch_command));
-       }
-
-       exit_status = pimpl_->application_->start(batch_command);
+       exit_status = pimpl_->application_->exec();
        // Kill the application object before exiting. This avoid crash
        // on exit on Linux.
        pimpl_->application_.reset();
@@ -431,7 +450,7 @@ void LyX::quit()
 }
 
 
-int LyX::execBatchCommands(int & argc, char * argv[],
+int LyX::loadFiles(int & argc, char * argv[],
        vector<string> & files)
 {
        // check for any spurious extra arguments
@@ -462,56 +481,54 @@ int LyX::execBatchCommands(int & argc, char * argv[],
        }
 
        if (first_start)
-               files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
+               files.push_back(i18nLibFileSearch("examples", "splash.lyx").absFilename());
 
-       // Execute batch commands if available
-       if (!batch_command.empty()) {
-
-               lyxerr[Debug::INIT] << "About to handle -x '"
-                      << batch_command << '\'' << endl;
-
-               Buffer * last_loaded = 0;
-
-               vector<string>::const_iterator it = files.begin();
-               vector<string>::const_iterator end = files.end();
-
-               for (; it != end; ++it) {
-                       // get absolute path of file and add ".lyx" to
-                       // the filename if necessary
-                       string s = fileSearch(string(), *it, "lyx");
-                       if (s.empty()) {
-                               Buffer * const b = newFile(*it, string(), true);
-                               if (b)
-                                       last_loaded = b;
-                       } else {
-                               Buffer * buf = pimpl_->buffer_list_.newBuffer(s, false);
-                               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
-                                       pimpl_->buffer_list_.release(buf);
-                       }
-               }
+       Buffer * last_loaded = 0;
+
+       vector<string>::const_iterator it = files.begin();
+       vector<string>::const_iterator end = files.end();
 
-               // try to dispatch to last loaded buffer first
-               if (last_loaded) {
-                       success = false;
-                       if (last_loaded->dispatch(batch_command, &success)) {
-                               prepareExit();
-                               return !success;
+       for (; it != end; ++it) {
+               // get absolute path of file and add ".lyx" to
+               // the filename if necessary
+               string s = fileSearch(string(), *it, "lyx").absFilename();
+               if (s.empty()) {
+                       Buffer * const b = newFile(*it, string(), true);
+                       if (b)
+                               last_loaded = b;
+               } else {
+                       Buffer * buf = pimpl_->buffer_list_.newBuffer(s, false);
+                       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
+                               pimpl_->buffer_list_.release(buf);
                }
-               files.clear(); // the files are already loaded
        }
 
+       files.clear(); // the files are already loaded
+
        return EXIT_SUCCESS;
 }
 
 
+void LyX::execBatchCommands()
+{
+       // Execute batch commands if available
+       if (batch_command.empty())
+               return;
+
+       lyxerr[Debug::INIT] << "About to handle -x '"
+               << batch_command << '\'' << endl;
+
+       pimpl_->lyxfunc_.dispatch(lyxaction.lookupFunc(batch_command));
+}
+
+
 void LyX::restoreGuiSession(vector<string> const & files)
 {
        LyXView * view = newLyXView();
@@ -543,6 +560,8 @@ LyXView * LyX::newLyXView()
        // initial geometry
        unsigned int width = 690;
        unsigned int height = 510;
+       // default icon size, will be overwritten by  stored session value
+       unsigned int iconSizeXY = 26;
        bool maximize = false;
        // first try lyxrc
        if (lyxrc.geometry_width != 0 && lyxrc.geometry_height != 0 ) {
@@ -559,6 +578,9 @@ LyXView * LyX::newLyXView()
                        height = convert<unsigned int>(val);
                if (session().sessionInfo().load("WindowIsMaximized") == "yes")
                        maximize = true;
+               val = session().sessionInfo().load("IconSizeXY");
+               if (!val.empty())
+                       iconSizeXY = convert<unsigned int>(val);
        }
 
        // if user wants to restore window position
@@ -578,7 +600,7 @@ LyXView * LyX::newLyXView()
                height = 0;
        }
        // create the main window
-       LyXView * view = &pimpl_->application_->createView(width, height, posx, posy, maximize);
+       LyXView * view = &pimpl_->application_->createView(width, height, posx, posy, maximize, iconSizeXY);
 
        return view;
 }
@@ -804,7 +826,7 @@ bool LyX::init()
            fs::is_directory(lyxrc.document_path))
                package().document_dir() = lyxrc.document_path;
 
-       package().temp_dir() = createLyXTmpDir(lyxrc.tempdir_path);
+       package().temp_dir() = createLyXTmpDir(FileName(lyxrc.tempdir_path)).absFilename();
        if (package().temp_dir().empty()) {
                Alert::error(_("Could not create temporary directory"),
                             bformat(_("Could not create a temporary directory in\n"
@@ -995,7 +1017,7 @@ bool LyX::readRcFile(string const & name)
 {
        lyxerr[Debug::INIT] << "About to read " << name << "... ";
 
-       string const lyxrc_path = libFileSearch(string(), name);
+       FileName const lyxrc_path = libFileSearch(string(), name);
        if (!lyxrc_path.empty()) {
 
                lyxerr[Debug::INIT] << "Found in " << lyxrc_path << endl;
@@ -1044,7 +1066,7 @@ bool LyX::readUIFile(string const & name)
 
        lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
 
-       string const ui_path = libFileSearch("ui", name, "ui");
+       FileName const ui_path = libFileSearch("ui", name, "ui");
 
        if (ui_path.empty()) {
                lyxerr[Debug::INIT] << "Could not find " << name << endl;
@@ -1102,7 +1124,7 @@ bool LyX::readLanguagesFile(string const & name)
 {
        lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
 
-       string const lang_path = libFileSearch(string(), name);
+       FileName const lang_path = libFileSearch(string(), name);
        if (lang_path.empty()) {
                showFileError(name);
                return false;
@@ -1117,7 +1139,7 @@ bool LyX::readEncodingsFile(string const & name)
 {
        lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
 
-       string const enc_path = libFileSearch(string(), name);
+       FileName const enc_path = libFileSearch(string(), name);
        if (enc_path.empty()) {
                showFileError(name);
                return false;