mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
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
This commit is contained in:
@@ -18,6 +18,32 @@
|
||||
#include "qetapp.h"
|
||||
#include "singleapplication.h"
|
||||
#include "qet.h"
|
||||
#include <QFileOpenEvent>
|
||||
|
||||
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<SingleApplication *>(obj);
|
||||
QFileOpenEvent *open_event = static_cast<QFileOpenEvent*>(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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user