From: Christoph Cullmann <cullmann@kde.org>
Date: Sat, 02 Jan 2016 18:51:33 +0000
Subject: handle mac like file open for kate, thanks to René J.V. Bertin for the hint with the plist file
X-Git-Url: http://quickgit.kde.org/?p=kate.git&a=commitdiff&h=cd6ec201725cf627a336015d472c39f5ff73b2a7
---
handle mac like file open for kate, thanks to René J.V. Bertin for the hint with the plist file
---

diff --git kate/data/MacOSXBundleInfo.plist.in kate/data/MacOSXBundleInfo.plist.in
--- kate/data/MacOSXBundleInfo.plist.in
+++ kate/data/MacOSXBundleInfo.plist.in
@@ -6,36 +6,51 @@
         <string>NSApplication</string>
         <key>NSHighResolutionCapable</key>
         <string>True</string>
-	<key>CFBundleDevelopmentRegion</key>
-	<string>English</string>
-	<key>CFBundleExecutable</key>
-	<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
-	<key>CFBundleGetInfoString</key>
-	<string>${MACOSX_BUNDLE_INFO_STRING}</string>
-	<key>CFBundleIconFile</key>
-	<string>${MACOSX_BUNDLE_ICON_FILE}</string>
-	<key>CFBundleIdentifier</key>
-	<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
-	<key>CFBundleInfoDictionaryVersion</key>
-	<string>6.0</string>
-	<key>CFBundleLongVersionString</key>
-	<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
-	<key>CFBundleName</key>
-	<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
-	<key>CFBundlePackageType</key>
-	<string>APPL</string>
-	<key>CFBundleShortVersionString</key>
-	<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
-	<key>CFBundleSignature</key>
-	<string>????</string>
-	<key>CFBundleVersion</key>
-	<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
-	<key>CSResourcesFileMapped</key>
-	<true/>
-	<key>LSRequiresCarbon</key>
-	<true/>
-	<key>NSHumanReadableCopyright</key>
-	<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
+        <key>CFBundleDevelopmentRegion</key>
+        <string>English</string>
+        <key>CFBundleExecutable</key>
+        <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
+        <key>CFBundleGetInfoString</key>
+        <string>${MACOSX_BUNDLE_INFO_STRING}</string>
+        <key>CFBundleIconFile</key>
+        <string>${MACOSX_BUNDLE_ICON_FILE}</string>
+        <key>CFBundleIdentifier</key>
+        <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
+        <key>CFBundleInfoDictionaryVersion</key>
+        <string>6.0</string>
+        <key>CFBundleLongVersionString</key>
+        <string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
+        <key>CFBundleName</key>
+        <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
+        <key>CFBundlePackageType</key>
+        <string>APPL</string>
+        <key>CFBundleShortVersionString</key>
+        <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
+        <key>CFBundleSignature</key>
+        <string>????</string>
+        <key>CFBundleVersion</key>
+        <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
+        <key>CSResourcesFileMapped</key>
+        <true/>
+        <key>LSRequiresCarbon</key>
+        <true/>
+        <key>NSHumanReadableCopyright</key>
+        <string>${MACOSX_BUNDLE_COPYRIGHT}</string>
+        <key>LSMultipleInstancesProhibited</key>
+        <true/>
+        <key>CFBundleDocumentTypes</key>
+        <array>
+            <dict>
+                <key>CFBundleTypeExtensions</key>
+                <array>
+                        <string>*</string>
+                </array>
+                <key>CFBundleTypeName</key>
+                <string>NSStringPboardType</string>
+                <key>CFBundleTypeRole</key>
+                <string>Editor</string>
+            </dict>
+        </array>
 </dict>
 </plist>
 

diff --git kate/kateapp.h kate/kateapp.h
--- kate/kateapp.h
+++ kate/kateapp.h
@@ -310,6 +310,12 @@
         shutdownKate(activeKateMainWindow());
         return true;
     }
+    
+protected:
+    /**
+     * Event filter for QApplication to handle mac os like file open
+     */
+    bool eventFilter(QObject *obj, QEvent *event);
 
 private:
     /**

diff --git kate/orig.kateapp.cpp kate/kateapp.cpp
--- kate/orig.kateapp.cpp	2015-12-14 01:02:12.000000000 +0100
+++ kate/kateapp.cpp	2016-01-02 22:36:48.000000000 +0100
@@ -34,6 +34,7 @@
 #include <QFileInfo>
 #include <QTextCodec>
 #include <QApplication>
+#include <QFileOpenEvent>
 
 #include "../../urlinfo.h"
 
@@ -60,6 +61,11 @@
     connect(&m_docManager, &KateDocManager::documentDeleted, &m_wrapper, &KTextEditor::Application::documentDeleted);
     connect(&m_docManager, &KateDocManager::aboutToCreateDocuments, &m_wrapper, &KTextEditor::Application::aboutToCreateDocuments);
     connect(&m_docManager, &KateDocManager::documentsCreated, &m_wrapper, &KTextEditor::Application::documentsCreated);
+    
+    /**
+     * handle mac os x like file open request via event filter
+     */
+    qApp->installEventFilter(this);
 }
 
 KateApp::~KateApp()
@@ -386,3 +392,26 @@
     return m_pluginManager.plugin(name);
 }
 
+bool KateApp::eventFilter(QObject *obj, QEvent *event)
+{
+    /**
+     * handle mac os like file open
+     */
+    if (event->type() == QEvent::FileOpen) {
+        /**
+         * try to open and activate the new document, like we would do for stuff
+         * opened via dbus
+         */
+        QFileOpenEvent *foe = static_cast<QFileOpenEvent*>(event);
+        KTextEditor::Document *doc = openDocUrl(foe->url(), QString(), false);
+        if (doc && activeKateMainWindow()) {
+            activeKateMainWindow()->viewManager()->activateView(doc);
+        }
+        return true;
+    }
+
+    /**
+     * else: pass over to default implementation
+     */
+    return QObject::eventFilter(obj, event);
+}
