Handling "Open With" from Finder in Mac OS X.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-11-19 17:17:25 +02:00
parent 5604f8eea3
commit 33bf03994e
5 changed files with 90 additions and 31 deletions

View file

@ -391,6 +391,51 @@ void MApplication::InitTrVars()
}
}
//---------------------------------------------------------------------------------------------------------------------
bool MApplication::event(QEvent *e)
{
switch(e->type())
{
// In Mac OS X the QFileOpenEvent event is generated when user perform "Open With" from Finder (this event is
// Mac specific).
case QEvent::FileOpen:
{
QFileOpenEvent *fileOpenEvent = static_cast<QFileOpenEvent *>(e);
if(fileOpenEvent)
{
const QString macFileOpen = fileOpenEvent->file();
if(not macFileOpen.isEmpty())
{
TMainWindow *mw = MainWindow();
if (mw)
{
mw->LoadFile(macFileOpen); // open file in existing window
}
return true;
}
}
}
#if defined(Q_OS_MAC)
case QEvent::ApplicationActivate:
{
Clean();
if (!mainWindows.isEmpty())
{
TMainWindow *mw = MainWindow();
if (mw && not mw->isMinimized())
{
mw->show();
}
return true;
}
}
#endif //defined(Q_OS_MAC)
default:
return VAbstractApplication::event(e);
}
return VAbstractApplication::event(e);
}
//---------------------------------------------------------------------------------------------------------------------
void MApplication::OpenSettings()
{
@ -668,32 +713,6 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
}
}
//---------------------------------------------------------------------------------------------------------------------
#if defined(Q_WS_MAC)
bool MApplication::event(QEvent* event)
{
switch (event->type())
{
case QEvent::ApplicationActivate:
{
Clean();
if (!mainWindows.isEmpty())
{
TMainWindow *mw = MainWindow();
if (mw && !mw->isMinimized())
{
MainWindow()->show();
}
return true;
}
}
default:
break;
}
return QApplication::event(event);
}
#endif
//---------------------------------------------------------------------------------------------------------------------
TMainWindow *MApplication::NewMainWindow()
{

View file

@ -60,10 +60,6 @@ public:
TMainWindow *MainWindow();
QList<TMainWindow*> MainWindows();
#if defined(Q_WS_MAC)
bool event(QEvent *event);
#endif
void InitOptions();
virtual const VTranslateVars *TrVars() Q_DECL_OVERRIDE;
@ -85,6 +81,7 @@ public slots:
protected:
virtual void InitTrVars() Q_DECL_OVERRIDE;
virtual bool event(QEvent *e) Q_DECL_OVERRIDE;
private slots:
void OpenFile(const QString &path);

View file

@ -36,6 +36,7 @@
#include "../version.h"
#include "../vmisc/logging.h"
#include "../qmuparser/qmuparsererror.h"
#include "../mainwindow.h"
#include <QDebug>
#include <QDir>
@ -601,6 +602,46 @@ void VApplication::InitTrVars()
trVars = new VTranslateVars(ValentinaSettings()->GetOsSeparator());
}
//---------------------------------------------------------------------------------------------------------------------
bool VApplication::event(QEvent *e)
{
switch(e->type())
{
// In Mac OS X the QFileOpenEvent event is generated when user perform "Open With" from Finder (this event is
// Mac specific).
case QEvent::FileOpen:
{
QFileOpenEvent *fileOpenEvent = static_cast<QFileOpenEvent *>(e);
if(fileOpenEvent)
{
const QString macFileOpen = fileOpenEvent->file();
if(not macFileOpen.isEmpty())
{
MainWindow *window = qobject_cast<MainWindow*>(mainWindow);
if (window)
{
window->LoadPattern(macFileOpen); // open file in existing window
}
return true;
}
}
}
#if defined(Q_OS_MAC)
case QEvent::ApplicationActivate:
{
if (mainWindow && not mainWindow->isMinimized())
{
mainWindow->show();
}
return true;
}
#endif //defined(Q_OS_MAC)
default:
return VAbstractApplication::event(e);
}
return VAbstractApplication::event(e);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief OpenSettings get acsses to application settings.

View file

@ -84,6 +84,7 @@ public:
protected:
virtual void InitTrVars() Q_DECL_OVERRIDE;
virtual bool event(QEvent *e) Q_DECL_OVERRIDE;
private slots:
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)

View file

@ -60,6 +60,8 @@ public:
explicit MainWindow(QWidget *parent = nullptr);
virtual ~MainWindow() Q_DECL_OVERRIDE;
bool LoadPattern(const QString &curFile, const QString &customMeasureFile = QString());
public slots:
void ProcessCMD();
@ -305,7 +307,6 @@ private:
void ToggleMSync(bool toggle);
bool LoadPattern(const QString &curFile, const QString &customMeasureFile = QString());
void ReopenFilesAfterCrash(QStringList &args);
void DoExport(const VCommandLinePtr& expParams);