From a94fe452ff3cdebf2d2f695001de20af5cde15eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Fri, 22 Oct 2010 15:46:46 +0000 Subject: [PATCH] Fix bug 6944: crash on drag and drop multiple files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35779 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiApplication.cpp | 16 +++++++++++++++- src/frontends/qt4/GuiApplication.h | 8 +++++++- src/frontends/qt4/GuiView.cpp | 9 ++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 571e30c9d6..dcce91565b 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -1786,8 +1786,22 @@ void GuiApplication::processKeySym(KeySymbol const & keysym, KeyModifier state) void GuiApplication::dispatchDelayed(FuncRequest const & func) +{ + addtoFuncRequestQueue(func); + processFuncRequestQueueAsync(); +} + + +void GuiApplication::addtoFuncRequestQueue(FuncRequest const & func) { d->func_request_queue_.push(func); +} + + +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())); } @@ -1976,7 +1990,7 @@ void GuiApplication::setGuiLanguage() void GuiApplication::processFuncRequestQueue() { while (!d->func_request_queue_.empty()) { - lyx::dispatch(d->func_request_queue_.back()); + lyx::dispatch(d->func_request_queue_.front()); d->func_request_queue_.pop(); } } diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 386b270027..813d1caf83 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -60,7 +60,6 @@ public: void dispatch(FuncRequest const &); void dispatch(FuncRequest const &, DispatchResult & dr); FuncStatus getStatus(FuncRequest const & cmd) const; - void dispatchDelayed(FuncRequest const &); void restoreGuiSession(); Clipboard & clipboard(); Selection & selection(); @@ -136,6 +135,11 @@ 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 + void processFuncRequestQueueAsync(); + /// goto a bookmark /// openFile: whether or not open a file if the file is not opened /// switchToBuffer: whether or not switch to buffer if the buffer is @@ -164,6 +168,8 @@ 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 e24ec9703e..10e461a4b7 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -794,13 +794,12 @@ void GuiView::dropEvent(QDropEvent * event) "No formats found, trying to open it as a lyx file"); cmd = FuncRequest(LFUN_FILE_OPEN, file); } - - // Asynchronously post the event. DropEvent usually comes - // from the BufferView. But reloading a file might close - // the BufferView from within its own event handler. - guiApp->dispatchDelayed(cmd); + // add the functions to the queue + guiApp->addtoFuncRequestQueue(cmd); event->accept(); } + // now process the collected functions + guiApp->processFuncRequestQueueAsync(); } -- 2.39.2