From 8dd15c65e8a97f8dc48c31fa374f3f1356e03b17 Mon Sep 17 00:00:00 2001 From: blacksun Date: Thu, 4 Apr 2019 19:27:24 +0000 Subject: [PATCH] Try to open a .qet file when double click on it or drop it in the qet icons of the dock in mac osx. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5826 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/main.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sources/main.cpp b/sources/main.cpp index 814b49032..bf8363857 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -18,6 +18,32 @@ #include "qetapp.h" #include "singleapplication.h" #include "qet.h" +#include + +class MacOSXOpenEvent : public QObject +{ + Q_OBJECT + + public: + MacOSXOpenEvent(QObject *parent = nullptr) : + QObject(parent) + {} + + ~MacOSXOpenEvent(){} + + bool eventFilter(QObject *obj, QEvent *event) + { + if (event->type() == QEvent::FileOpen) + { + SingleApplication *app = dynamic_cast(obj); + QFileOpenEvent *open_event = static_cast(event); + QString message = "launched-with-args: " + open_event->file(); + app->sendMessage(message.toUtf8()); + return true; + } + return false; + } +}; /** * @brief main @@ -41,6 +67,12 @@ int main(int argc, char **argv) #endif SingleApplication app(argc, argv, true); +#ifdef Q_OS_MACOS + //Handle the opening of QET when user double click on a .qet .elmt .tbt file + //or drop these same files to the QET icon of the dock + MacOSXOpenEvent open_event; + app.installEventFilter(open_event); +#endif if (app.isSecondary()) { @@ -59,3 +91,4 @@ int main(int argc, char **argv) return app.exec(); } +