]> git.lyx.org Git - features.git/commitdiff
* Fix for http://bugzilla.lyx.org/show_bug.cgi?id=5387
authorStefan Schimanski <sts@lyx.org>
Wed, 5 Nov 2008 14:04:37 +0000 (14:04 +0000)
committerStefan Schimanski <sts@lyx.org>
Wed, 5 Nov 2008 14:04:37 +0000 (14:04 +0000)
  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
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/GuiView.cpp

index f79f25e17825b7bad676a86556eae983f59e3405..bd3e418e92ea455023917aed1e3a0a43f81739e9 100644 (file)
@@ -176,7 +176,18 @@ vector<string> 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<FuncRequestEvent *>(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<QFileOpenEvent *>(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;
        }
index 379b8be68ef82e4e7e085c6146091ccafbf95e29..63bc179f602d936f96bbe0fdc2641e57b2da529f 100644 (file)
@@ -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);
index 222f67bdaccb637b42217046a619152b7caf2607..d615149dbf8092db9640b753fcb14b55ddd1b306 100644 (file)
@@ -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");
 }