]> git.lyx.org Git - features.git/commitdiff
* lyx_main.[Ch]
authorAbdelrazak Younes <younes@lyx.org>
Sun, 26 Nov 2006 02:18:32 +0000 (02:18 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 26 Nov 2006 02:18:32 +0000 (02:18 +0000)
  - execBatchCommands(): split in loadFiles() and execBatchCommands().
  - exec(): enable batch command to be processed from GUI.

* Application:
  - start(): deleted.

* GuiApplication:
  - execBatchCommands(): new method

* GuiWorkArea::update(): call viewport()->repaint() instead of viewport()->update(), this enable to update the screen immediately when asked by a batch command.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16051 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/Application.C
src/frontends/Application.h
src/frontends/qt4/GuiApplication.C
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/GuiWorkArea.C
src/lyx_main.C
src/lyx_main.h

index a4902161f27a7356fc0e241cff924cb70d61c7b6..98d357427bd443f204a61b39a3543088f2e27e49 100644 (file)
@@ -86,13 +86,6 @@ void Application::setCurrentView(LyXView & current_view)
        current_view_ = &current_view;
 }
 
-
-int Application::start(std::string const & /*batch*/)
-{
-       return exec();
-}
-
-
 } // namespace frontend
 
 
index f939b65ef8f233bc7d614ed063741060bc70addf..8f977ab737736ca29b92e4a92cf1b1215b38db7f 100644 (file)
@@ -105,12 +105,12 @@ public:
        ///
        virtual ~Application() {}
 
-       /// Start the main event loop, after executing the given batch
-       /// commands.
-       int start(std::string const & batch);
        ///
        virtual Gui & gui() = 0;
-       ///
+
+       /// Start the main event loop.
+       /// The batch command is programmed to be execute once
+       /// the event loop is started.
        virtual int const exec() = 0;
 
        /// Quit running LyX.
index 006b5b76b239cfff885c82a4847fb8c4f8c15fa1..a805c18463831208ea37ae11399319d3cea39437 100644 (file)
@@ -169,6 +169,7 @@ Selection& GuiApplication::selection()
 
 int const GuiApplication::exec()
 {
+       QTimer::singleShot(1, this, SLOT(execBatchCommands()));
        return QApplication::exec();
 }
 
@@ -179,6 +180,12 @@ void GuiApplication::exit(int status)
 }
 
 
+void GuiApplication::execBatchCommands()
+{
+       LyX::ref().execBatchCommands();
+}
+
+
 string const GuiApplication::romanFontName()
 {
        QFont font;
index 851557d4114ff0c2bdfde48938a0bc2ac0e40157..656d87300324270dd5b2d83ae58a3db3064bd58f 100644 (file)
@@ -83,6 +83,10 @@ public:
        ///
        GuiFontLoader & guiFontLoader() { return font_loader_; }
 
+private Q_SLOTS:
+       ///
+       void execBatchCommands();
+
 private:
        ///
        GuiImplementation gui_;
index 81edd42be5eb9c3ad77369554e1ba9db5ba59d5f..97b60c2203eafd6245eefc1054bdf528d43c5b8f 100644 (file)
@@ -454,7 +454,7 @@ void GuiWorkArea::resizeEvent(QResizeEvent * ev)
 
 void GuiWorkArea::update(int x, int y, int w, int h)
 {
-       viewport()->update(x, y, w, h);
+       viewport()->repaint(x, y, w, h);
 }
 
 
index a5d29c76b484d58c76ffb728d68ff3e7140de456..ad50ee6b1ce06db542ebe26b961e393a021a4b24 100644 (file)
@@ -331,7 +331,11 @@ 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)
+                       return exit_status;
+               execBatchCommands();
+               return EXIT_SUCCESS;
        }
 
        // Force adding of font path _before_ Application is initialized
@@ -339,10 +343,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 +359,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 +373,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 +431,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
@@ -464,54 +464,52 @@ int LyX::execBatchCommands(int & argc, char * argv[],
        if (first_start)
                files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
 
-       // 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;
 
-               // try to dispatch to last loaded buffer first
-               if (last_loaded) {
-                       success = false;
-                       if (last_loaded->dispatch(batch_command, &success)) {
-                               prepareExit();
-                               return !success;
+       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);
                }
-               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();
index ab1619f97e7372a30b189ec50a4817141ad1ee43..a0b74578ace3540040035786ac6c08f2e9d94b60 100644 (file)
@@ -105,6 +105,9 @@ public:
         */
        Buffer const * const updateInset(InsetBase const *) const;
 
+       /// Execute batch commands if available.
+       void execBatchCommands();
+
 private:
        /// Do some cleanup in preparation of an exit.
        void prepareExit();
@@ -112,12 +115,12 @@ private:
        /// Early exit during the initialisation process.
        void earlyExit(int status);
 
-       /// Initialise LyX and execute batch commands if available.
+       /// Initialise LyX and load files if asked.
        /**
        \param files is filled in with the command-line file names.
        \return exit code failure if any.
        */
-       int execBatchCommands(int & argc, char * argv[],
+       int loadFiles(int & argc, char * argv[],
                std::vector<std::string> & files);
 
        /// Create a View and restore GUI Session.