open with working properly in MacOS.

This commit is contained in:
Thomas Ferreira de Lima 2018-03-07 12:53:29 -05:00
parent c82bb445ac
commit 8ec78a99a9
5 changed files with 30 additions and 7 deletions

View File

@ -18,6 +18,8 @@
<string>APPL</string>
<key>CFBundleVersion</key>
<string>${VERSION}</string>
<key>CFBundleShortVersionString</key>
<string>${VERSION}</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>

BIN
macbuild/build4mac_env.pyc Normal file

Binary file not shown.

BIN
macbuild/build4mac_util.pyc Normal file

Binary file not shown.

View File

@ -75,11 +75,6 @@
# include <dlfcn.h>
#endif
#if defined(__APPLE__)
# include <QFileOpenEvent>
# include <QtDebug>
#endif
namespace gsi
{
void make_application_decl (bool non_gui_mode);
@ -1397,12 +1392,27 @@ GuiApplication::force_update_app_menu ()
}
#if defined(__APPLE__)
// By Thomas Lima (March 7, 2018)
//
// This event interceptor catches MacOS "Open With" event, and KLayout should respond
// similarly to the Drop event in MainWindow::dropEvent.
//
// This particular implementation always creates a new window.
//
// This was implemented with the inspiration of http://doc.qt.io/qt-5/qfileopenevent.html
bool
GuiApplication::event(QEvent *event)
GuiApplication::event (QEvent *event)
{
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
qDebug() << "Open file" << openEvent->file();
if (mp_mw)
{
const std::string tech = mp_mw->initial_technology();
const std::string file = tl::to_string (openEvent->file());
const int mode = 1; // open in new window
mp_mw->load_layout (file, tech, mode);
mp_mw->add_mru (file, tech);
}
}
return QApplication::event(event);

View File

@ -28,6 +28,9 @@
#include <QApplication>
#include <QEventLoop>
#ifdef __APPLE__
# include <QEvent>
#endif
#include "gsi.h"
@ -438,6 +441,14 @@ public:
*/
void force_update_app_menu ();
/**
* @brief Handles MacOS file open
* This function is used to process the "Open With" event sent by MacOS.
*/
#ifdef __APPLE__
bool event (QEvent *event);
#endif
protected:
virtual void setup ();
virtual void shutdown ();