Vincent van Ravesteijn wrote:
> I think you can. However, I can't judge right now whether it's better
> to do it asynchronously or not. So, it might be that we should still
> do it asynchronously, but the reasoning stated in the comment is not
> valid anymore.

I propose the following patch (diff against trunk). I moved the comment to the 
actual function, so we know at least why the asynchronous call was introduced.

I propose to commit this to trunk and later, if no problems arise, to branch.

OK?

Jürgen
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp	(Revision 35775)
+++ src/frontends/qt4/GuiView.cpp	(Arbeitskopie)
@@ -794,13 +794,10 @@
 				"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);
+		guiApp->addtoFuncRequestQueue(cmd);
 		event->accept();
 	}
+	guiApp->performFuncRequests();
 }
 
 
Index: src/frontends/qt4/GuiApplication.cpp
===================================================================
--- src/frontends/qt4/GuiApplication.cpp	(Revision 35775)
+++ src/frontends/qt4/GuiApplication.cpp	(Arbeitskopie)
@@ -1788,6 +1788,20 @@
 void GuiApplication::dispatchDelayed(FuncRequest const & func)
 {
 	d->func_request_queue_.push(func);
+	performFuncRequests();
+}
+
+
+void GuiApplication::addtoFuncRequestQueue(FuncRequest const & func)
+{
+	d->func_request_queue_.push(func);
+}
+
+
+void GuiApplication::performFuncRequests()
+{
+	// 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::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();
 	}
 }
Index: src/frontends/qt4/GuiApplication.h
===================================================================
--- src/frontends/qt4/GuiApplication.h	(Revision 35775)
+++ src/frontends/qt4/GuiApplication.h	(Arbeitskopie)
@@ -61,6 +61,8 @@
 	void dispatch(FuncRequest const &, DispatchResult & dr);
 	FuncStatus getStatus(FuncRequest const & cmd) const;
 	void dispatchDelayed(FuncRequest const &);
+	void addtoFuncRequestQueue(FuncRequest const &);
+	void performFuncRequests();
 	void restoreGuiSession();
 	Clipboard & clipboard();
 	Selection & selection();

Reply via email to