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() 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() TMainWindow *MApplication::NewMainWindow()
{ {

View File

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

View File

@ -36,6 +36,7 @@
#include "../version.h" #include "../version.h"
#include "../vmisc/logging.h" #include "../vmisc/logging.h"
#include "../qmuparser/qmuparsererror.h" #include "../qmuparser/qmuparsererror.h"
#include "../mainwindow.h"
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
@ -601,6 +602,46 @@ void VApplication::InitTrVars()
trVars = new VTranslateVars(ValentinaSettings()->GetOsSeparator()); 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. * @brief OpenSettings get acsses to application settings.

View File

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

View File

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