#include "support/linkback/LinkBackProxy.h"
#endif
+#include <queue>
+
#include <QByteArray>
#include <QClipboard>
#include <QDateTime>
}
-class FuncRequestEvent : public QEvent
-{
-public:
- FuncRequestEvent(FuncRequest const & req)
- : QEvent(QEvent::User), request(req) {}
-
- FuncRequest const request;
-};
-
-
////////////////////////////////////////////////////////////////////////
// Icon loading support code.
////////////////////////////////////////////////////////////////////////
/// are done.
QTimer general_timer_;
+ /// delayed FuncRequests
+ std::queue<FuncRequest> func_request_queue_;
+
/// Multiple views container.
/**
* Warning: This must not be a smart pointer as the destruction of the
}
+void GuiApplication::dispatchDelayed(FuncRequest const & func)
+{
+ d->func_request_queue_.push(func);
+ QTimer::singleShot(0, this, SLOT(processFuncRequestQueue()));
+}
+
+
void GuiApplication::resetGui()
{
// Set the language defined by the user.
}
+void GuiApplication::processFuncRequestQueue()
+{
+ while (!d->func_request_queue_.empty()) {
+ lyx::dispatch(d->func_request_queue_.back());
+ d->func_request_queue_.pop();
+ }
+}
+
+
void GuiApplication::execBatchCommands()
{
setGuiLanguage();
}
-void GuiApplication::customEvent(QEvent * event)
-{
- FuncRequestEvent * reqEv = static_cast<FuncRequestEvent *>(event);
- lyx::dispatch(reqEv->request);
-}
-
-
bool GuiApplication::event(QEvent * e)
{
switch(e->type()) {
// commands are not executed here yet and the gui is not ready
// therefore.
QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
- postEvent(this, new FuncRequestEvent(FuncRequest(LFUN_FILE_OPEN,
- qstring_to_ucs4(foe->file()))));
+ dispatchDelayed(FuncRequest(LFUN_FILE_OPEN, qstring_to_ucs4(foe->file())));
e->accept();
return true;
}
//@{
bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const;
bool dispatch(FuncRequest const &);
+ void dispatchDelayed(FuncRequest const &);
void resetGui();
void restoreGuiSession();
Clipboard & clipboard();
FontLoader & fontLoader();
int exec();
void exit(int status);
- void customEvent(QEvent * event);
bool event(QEvent * e);
bool getRgbColor(ColorCode col, RGBColor & rgbcol);
std::string const hexName(ColorCode col);
///
void onLastWindowClosed();
+ ///
+ void processFuncRequestQueue();
+
private:
///
bool closeAllViews();
QPixmap splash_;
};
+
/// Toolbar store providing access to individual toolbars by name.
typedef std::map<std::string, GuiToolbar *> ToolbarMap;
}
-void GuiView::dropEvent(QDropEvent* event)
+void GuiView::dropEvent(QDropEvent * event)
{
QList<QUrl> files = event->mimeData()->urls();
if (files.isEmpty())
for (int i = 0; i != files.size(); ++i) {
string const file = os::internal_path(fromqstr(
files.at(i).toLocalFile()));
- if (!file.empty())
- lyx::dispatch(FuncRequest(LFUN_FILE_OPEN, file));
+ if (!file.empty()) {
+ // Asynchronously post the event. DropEvent usually come
+ // from the BufferView. But reloading a file might close
+ // the BufferView from within its own event handler.
+ guiApp->dispatchDelayed(FuncRequest(LFUN_FILE_OPEN, file));
+ event->accept();
+ }
}
}