From 5d9b126c9653c185f5aa03b74e1affe81848a44b Mon Sep 17 00:00:00 2001 From: Stefan Schimanski Date: Wed, 5 Nov 2008 14:04:37 +0000 Subject: [PATCH] * Fix for http://bugzilla.lyx.org/show_bug.cgi?id=5387 Gui is not setup yet when the file is opened from clicking on it in Finder with a closed LyX. We have to wait until the batch commands are executed. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27264 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiApplication.cpp | 36 ++++++++++++++++++++++++---- src/frontends/qt4/GuiApplication.h | 1 + src/frontends/qt4/GuiView.cpp | 5 ++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index f79f25e178..bd3e418e92 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -176,7 +176,18 @@ vector loadableImageFormats() return fmts; } - + + +class FuncRequestEvent : public QEvent +{ +public: + FuncRequestEvent(FuncRequest const & req) + : QEvent(QEvent::User), request(req) {} + + FuncRequest const request; +}; + + //////////////////////////////////////////////////////////////////////// // Icon loading support code. //////////////////////////////////////////////////////////////////////// @@ -1023,7 +1034,11 @@ ColorCache & GuiApplication::colorCache() int GuiApplication::exec() { - QTimer::singleShot(1, this, SLOT(execBatchCommands())); + // asynchronously handle batch commands. This event will be in + // the event queue in front of other asynchronous events. Hence, + // we can assume in the latter that the gui is setup already. + QTimer::singleShot(0, this, SLOT(execBatchCommands())); + return QApplication::exec(); } @@ -1177,14 +1192,25 @@ void GuiApplication::handleRegularEvents() } +void GuiApplication::customEvent(QEvent * event) +{ + FuncRequestEvent * reqEv = static_cast(event); + lyx::dispatch(reqEv->request); +} + + bool GuiApplication::event(QEvent * e) { switch(e->type()) { case QEvent::FileOpen: { - // Open a file; this happens only on Mac OS X for now + // Open a file; this happens only on Mac OS X for now. + // + // We do this asynchronously because on startup the batch + // commands are not executed here yet and the gui is not ready + // therefore. QFileOpenEvent * foe = static_cast(e); - lyx::dispatch(FuncRequest(LFUN_FILE_OPEN, - qstring_to_ucs4(foe->file()))); + postEvent(this, new FuncRequestEvent(FuncRequest(LFUN_FILE_OPEN, + qstring_to_ucs4(foe->file())))); e->accept(); return true; } diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 379b8be68e..63bc179f60 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -66,6 +66,7 @@ public: 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); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 222f67bdac..d615149dbf 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -330,10 +330,11 @@ GuiView::GuiView(int id) return; } - // No session handling, default to a sane size. + // no session handling, default to a sane size. setGeometry(50, 50, 690, 510); initToolbars(); - // This enables to clear session data if any. + + // clear session data if any. QSettings settings; settings.remove("views"); } -- 2.39.2