mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-13 06:20:28 +00:00
* proper mechanism to dispatch FuncRequests delayed, i.e. when the event loop is idle again
* fixes http://bugzilla.lyx.org/show_bug.cgi?id=5447 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27459 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e4c9689906
commit
f9f5c3baa5
@ -62,6 +62,8 @@
|
|||||||
#include "support/linkback/LinkBackProxy.h"
|
#include "support/linkback/LinkBackProxy.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@ -178,16 +180,6 @@ vector<string> loadableImageFormats()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class FuncRequestEvent : public QEvent
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FuncRequestEvent(FuncRequest const & req)
|
|
||||||
: QEvent(QEvent::User), request(req) {}
|
|
||||||
|
|
||||||
FuncRequest const request;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Icon loading support code.
|
// Icon loading support code.
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
@ -631,6 +623,9 @@ struct GuiApplication::Private
|
|||||||
/// are done.
|
/// are done.
|
||||||
QTimer general_timer_;
|
QTimer general_timer_;
|
||||||
|
|
||||||
|
/// delayed FuncRequests
|
||||||
|
std::queue<FuncRequest> func_request_queue_;
|
||||||
|
|
||||||
/// Multiple views container.
|
/// Multiple views container.
|
||||||
/**
|
/**
|
||||||
* Warning: This must not be a smart pointer as the destruction of the
|
* Warning: This must not be a smart pointer as the destruction of the
|
||||||
@ -907,6 +902,13 @@ bool GuiApplication::dispatch(FuncRequest const & cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiApplication::dispatchDelayed(FuncRequest const & func)
|
||||||
|
{
|
||||||
|
d->func_request_queue_.push(func);
|
||||||
|
QTimer::singleShot(0, this, SLOT(processFuncRequestQueue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiApplication::resetGui()
|
void GuiApplication::resetGui()
|
||||||
{
|
{
|
||||||
// Set the language defined by the user.
|
// Set the language defined by the user.
|
||||||
@ -1088,6 +1090,15 @@ void GuiApplication::setGuiLanguage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiApplication::processFuncRequestQueue()
|
||||||
|
{
|
||||||
|
while (!d->func_request_queue_.empty()) {
|
||||||
|
lyx::dispatch(d->func_request_queue_.back());
|
||||||
|
d->func_request_queue_.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiApplication::execBatchCommands()
|
void GuiApplication::execBatchCommands()
|
||||||
{
|
{
|
||||||
setGuiLanguage();
|
setGuiLanguage();
|
||||||
@ -1192,13 +1203,6 @@ void GuiApplication::handleRegularEvents()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiApplication::customEvent(QEvent * event)
|
|
||||||
{
|
|
||||||
FuncRequestEvent * reqEv = static_cast<FuncRequestEvent *>(event);
|
|
||||||
lyx::dispatch(reqEv->request);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool GuiApplication::event(QEvent * e)
|
bool GuiApplication::event(QEvent * e)
|
||||||
{
|
{
|
||||||
switch(e->type()) {
|
switch(e->type()) {
|
||||||
@ -1209,8 +1213,7 @@ bool GuiApplication::event(QEvent * e)
|
|||||||
// commands are not executed here yet and the gui is not ready
|
// commands are not executed here yet and the gui is not ready
|
||||||
// therefore.
|
// therefore.
|
||||||
QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
|
QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
|
||||||
postEvent(this, new FuncRequestEvent(FuncRequest(LFUN_FILE_OPEN,
|
dispatchDelayed(FuncRequest(LFUN_FILE_OPEN, qstring_to_ucs4(foe->file())));
|
||||||
qstring_to_ucs4(foe->file()))));
|
|
||||||
e->accept();
|
e->accept();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ public:
|
|||||||
//@{
|
//@{
|
||||||
bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const;
|
bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const;
|
||||||
bool dispatch(FuncRequest const &);
|
bool dispatch(FuncRequest const &);
|
||||||
|
void dispatchDelayed(FuncRequest const &);
|
||||||
void resetGui();
|
void resetGui();
|
||||||
void restoreGuiSession();
|
void restoreGuiSession();
|
||||||
Clipboard & clipboard();
|
Clipboard & clipboard();
|
||||||
@ -66,7 +67,6 @@ public:
|
|||||||
FontLoader & fontLoader();
|
FontLoader & fontLoader();
|
||||||
int exec();
|
int exec();
|
||||||
void exit(int status);
|
void exit(int status);
|
||||||
void customEvent(QEvent * event);
|
|
||||||
bool event(QEvent * e);
|
bool event(QEvent * e);
|
||||||
bool getRgbColor(ColorCode col, RGBColor & rgbcol);
|
bool getRgbColor(ColorCode col, RGBColor & rgbcol);
|
||||||
std::string const hexName(ColorCode col);
|
std::string const hexName(ColorCode col);
|
||||||
@ -135,6 +135,9 @@ private Q_SLOTS:
|
|||||||
///
|
///
|
||||||
void onLastWindowClosed();
|
void onLastWindowClosed();
|
||||||
|
|
||||||
|
///
|
||||||
|
void processFuncRequestQueue();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
bool closeAllViews();
|
bool closeAllViews();
|
||||||
|
@ -142,6 +142,7 @@ private:
|
|||||||
QPixmap splash_;
|
QPixmap splash_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Toolbar store providing access to individual toolbars by name.
|
/// Toolbar store providing access to individual toolbars by name.
|
||||||
typedef std::map<std::string, GuiToolbar *> ToolbarMap;
|
typedef std::map<std::string, GuiToolbar *> ToolbarMap;
|
||||||
|
|
||||||
@ -597,7 +598,7 @@ void GuiView::dragEnterEvent(QDragEnterEvent * event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiView::dropEvent(QDropEvent* event)
|
void GuiView::dropEvent(QDropEvent * event)
|
||||||
{
|
{
|
||||||
QList<QUrl> files = event->mimeData()->urls();
|
QList<QUrl> files = event->mimeData()->urls();
|
||||||
if (files.isEmpty())
|
if (files.isEmpty())
|
||||||
@ -607,8 +608,13 @@ void GuiView::dropEvent(QDropEvent* event)
|
|||||||
for (int i = 0; i != files.size(); ++i) {
|
for (int i = 0; i != files.size(); ++i) {
|
||||||
string const file = os::internal_path(fromqstr(
|
string const file = os::internal_path(fromqstr(
|
||||||
files.at(i).toLocalFile()));
|
files.at(i).toLocalFile()));
|
||||||
if (!file.empty())
|
if (!file.empty()) {
|
||||||
lyx::dispatch(FuncRequest(LFUN_FILE_OPEN, file));
|
// 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user