From: Abdelrazak Younes Date: Sun, 26 Nov 2006 02:18:32 +0000 (+0000) Subject: * lyx_main.[Ch] X-Git-Tag: 1.6.10~11760 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e6a6548712df8f72d15e0efc0266b97f0aeedc66;p=features.git * lyx_main.[Ch] - 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 --- diff --git a/src/frontends/Application.C b/src/frontends/Application.C index a4902161f2..98d357427b 100644 --- a/src/frontends/Application.C +++ b/src/frontends/Application.C @@ -86,13 +86,6 @@ void Application::setCurrentView(LyXView & current_view) current_view_ = ¤t_view; } - -int Application::start(std::string const & /*batch*/) -{ - return exec(); -} - - } // namespace frontend diff --git a/src/frontends/Application.h b/src/frontends/Application.h index f939b65ef8..8f977ab737 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -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. diff --git a/src/frontends/qt4/GuiApplication.C b/src/frontends/qt4/GuiApplication.C index 006b5b76b2..a805c18463 100644 --- a/src/frontends/qt4/GuiApplication.C +++ b/src/frontends/qt4/GuiApplication.C @@ -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; diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 851557d411..656d873003 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -83,6 +83,10 @@ public: /// GuiFontLoader & guiFontLoader() { return font_loader_; } +private Q_SLOTS: + /// + void execBatchCommands(); + private: /// GuiImplementation gui_; diff --git a/src/frontends/qt4/GuiWorkArea.C b/src/frontends/qt4/GuiWorkArea.C index 81edd42be5..97b60c2203 100644 --- a/src/frontends/qt4/GuiWorkArea.C +++ b/src/frontends/qt4/GuiWorkArea.C @@ -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); } diff --git a/src/lyx_main.C b/src/lyx_main.C index a5d29c76b4..ad50ee6b1c 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -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 & 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::const_iterator it = files.begin(); - vector::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::const_iterator it = files.begin(); + vector::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 const & files) { LyXView * view = newLyXView(); diff --git a/src/lyx_main.h b/src/lyx_main.h index ab1619f97e..a0b74578ac 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -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 & files); /// Create a View and restore GUI Session.