From: Vincent van Ravesteijn Date: Fri, 22 Oct 2010 18:08:21 +0000 (+0000) Subject: Restructure processFuncRequest* function family: X-Git-Tag: 2.0.0~2293 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=56bce65dd0501897c54488327d6b66c0077270ab;p=lyx.git Restructure processFuncRequest* function family: - move a comment back from to GuiApplication to GuiView.cpp, so we have the comment in the place where we decide to process the func request asynchronously; - rename dispatchDelayed to processFuncRequestAsync to have the same terminology as in the other processFuncRequest* methods; - introduce a new function processFuncRequest to complete the set of processFuncRequest* methods. It is strange that for the normal processFuncRequest one should suddenly use lyx::dispatch. Besides, I think it is good that the whole GUI will dispatch funcRequests through GuiApplication::processFuncRequest from now on; - use the slotProcessFuncRequestQueue to relay to processFuncRequestQueue; - properly camelBump addToFuncRequestQueue; - group the implementation of the processFuncRequest* functions; - document the side-effect of processFuncRequestAsync. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35784 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index dcce91565b..539169ba35 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -1428,7 +1428,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr) GuiView * gv = currentView(); if (gv && gv->currentBufferView()) // cancel any selection - lyx::dispatch(FuncRequest(LFUN_MARK_OFF)); + processFuncRequest(FuncRequest(LFUN_MARK_OFF)); dr.setMessage(from_ascii(N_("Cancel"))); break; } @@ -1776,33 +1776,46 @@ void GuiApplication::processKeySym(KeySymbol const & keysym, KeyModifier state) if (func.action() == LFUN_SELF_INSERT) { if (encoded_last_key != 0) { docstring const arg(1, encoded_last_key); - lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, arg, + processFuncRequest(FuncRequest(LFUN_SELF_INSERT, arg, FuncRequest::KEYBOARD)); LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']"); } } else - lyx::dispatch(func); + processFuncRequest(func); } -void GuiApplication::dispatchDelayed(FuncRequest const & func) +void GuiApplication::processFuncRequest(FuncRequest const & func) { - addtoFuncRequestQueue(func); + lyx::dispatch(func); +} + + +void GuiApplication::processFuncRequestAsync(FuncRequest const & func) +{ + addToFuncRequestQueue(func); processFuncRequestQueueAsync(); } -void GuiApplication::addtoFuncRequestQueue(FuncRequest const & func) +void GuiApplication::processFuncRequestQueue() { - d->func_request_queue_.push(func); + while (!d->func_request_queue_.empty()) { + processFuncRequest(d->func_request_queue_.front()); + d->func_request_queue_.pop(); + } } void GuiApplication::processFuncRequestQueueAsync() { - // We perform the events asynchronously. This prevents potential - // problems in case the BufferView is closed within an event. - QTimer::singleShot(0, this, SLOT(processFuncRequestQueue())); + QTimer::singleShot(0, this, SLOT(slotProcessFuncRequestQueue())); +} + + +void GuiApplication::addToFuncRequestQueue(FuncRequest const & func) +{ + d->func_request_queue_.push(func); } @@ -1827,7 +1840,7 @@ void GuiApplication::resetGui() gv->resetDialogs(); } - lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE)); + processFuncRequest(FuncRequest(LFUN_SCREEN_FONT_UPDATE)); } @@ -1987,15 +2000,6 @@ void GuiApplication::setGuiLanguage() } -void GuiApplication::processFuncRequestQueue() -{ - while (!d->func_request_queue_.empty()) { - lyx::dispatch(d->func_request_queue_.front()); - d->func_request_queue_.pop(); - } -} - - void GuiApplication::execBatchCommands() { setGuiLanguage(); @@ -2145,7 +2149,8 @@ bool GuiApplication::event(QEvent * e) // commands are not executed here yet and the gui is not ready // therefore. QFileOpenEvent * foe = static_cast(e); - dispatchDelayed(FuncRequest(LFUN_FILE_OPEN, qstring_to_ucs4(foe->file()))); + FuncRequest const fr(LFUN_FILE_OPEN, qstring_to_ucs4(foe->file())); + processFuncRequestAsync(fr); e->accept(); return true; } diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index cd4f1caa79..c580f4a3eb 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -144,10 +144,21 @@ public: /// return the status bar state string docstring viewStatusMessage(); - /// add a func request to the queue for later procession - void addtoFuncRequestQueue(FuncRequest const &); - /// process the func request in the queue asynchronously + /// \name Methods to process FuncRequests + //@{ + /// process the func request + void processFuncRequest(FuncRequest const &); + /// add a func request to the queue and process it asynchronously + /// \note As a side-effect this will also process the + /// func requests that were added to the queue before. + void processFuncRequestAsync(FuncRequest const &); + /// process the func requests in the queue + void processFuncRequestQueue(); + /// process the func requests in the queue asynchronously void processFuncRequestQueueAsync(); + /// add a func request to the queue for later processing + void addToFuncRequestQueue(FuncRequest const &); + //@} /// goto a bookmark /// openFile: whether or not open a file if the file is not opened @@ -165,7 +176,7 @@ private Q_SLOTS: /// void onLastWindowClosed(); /// - void processFuncRequestQueue(); + void slotProcessFuncRequestQueue() { processFuncRequestQueue(); } private: /// @@ -176,8 +187,6 @@ private: void setGuiLanguage(); /// void reconfigure(std::string const & option); - /// add a func request to the queue and process it asynchronously - void dispatchDelayed(FuncRequest const &); /// This GuiView is the one receiving Clipboard and Selection /// events diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 10e461a4b7..efcbdd86b0 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -795,10 +795,12 @@ void GuiView::dropEvent(QDropEvent * event) cmd = FuncRequest(LFUN_FILE_OPEN, file); } // add the functions to the queue - guiApp->addtoFuncRequestQueue(cmd); + guiApp->addToFuncRequestQueue(cmd); event->accept(); } - // now process the collected functions + // now process the collected functions. We perform the events + // asynchronously. This prevents potential problems in case the + // BufferView is closed within an event. guiApp->processFuncRequestQueueAsync(); }