[geany/geany] 562885: React to various useful gtk-mac-integration signals

Jiří Techet git-noreply at xxxxx
Wed Mar 4 11:40:36 UTC 2015


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Wed, 04 Mar 2015 11:40:36 UTC
Commit:      562885765dbd600626558372a409832cb4cda77e
             https://github.com/geany/geany/commit/562885765dbd600626558372a409832cb4cda77e

Log Message:
-----------
React to various useful gtk-mac-integration signals

NSApplicationBlockTermination signal is emitted when clicking
the Quit menu to check whether the application permits
quitting - react accordingly.

---

NSApplicationOpenFile signal is emitted when

* file is dragged on the application icon
* application is selected from "Open with" menu after right-clicking
the file
* when double-clicking a file for which the application is default
editor/viewer
* when file is opened from command-line

When the application isn't running, it is first started and then this
signal is emitted.

Use the signal to open files. In addition, when the opened file
has the ".geany" suffix, open it (but only if the project isn't already
open). The project has to be opened in idle function because blocking
the signal handler for a long time by the project-close confirmation
dialog causes problems.


Modified Paths:
--------------
    src/osx.c

Modified: src/osx.c
61 lines changed, 60 insertions(+), 1 deletions(-)
===================================================================
@@ -23,6 +23,61 @@
 #include "osx.h"
 
 #include "ui_utils.h"
+#include "main.h"
+
+
+static gboolean app_block_termination_cb(GtkosxApplication *app, gpointer data)
+{
+	return !main_quit();
+}
+
+
+/* For some reason osx doesn't like when the NSApplicationOpenFile handler blocks for 
+ * a long time which may be caused by the project_ask_close() below. Finish the
+ * NSApplicationOpenFile handler immediately and perform the potentially blocking
+ * code on idle in this function. */
+static gboolean open_project_idle(gchar *locale_path)
+{
+	gchar *utf8_path;
+
+	utf8_path = utils_get_utf8_from_locale(locale_path);
+	if (app->project == NULL || 
+		(g_strcmp0(utf8_path, app->project->file_name) != 0 && project_ask_close()))
+		project_load_file_with_session(locale_path);
+	g_free(utf8_path);
+	g_free(locale_path);
+	return FALSE;
+}
+
+
+static gboolean app_open_file_cb(GtkosxApplication *osx_app, gchar *path, gpointer user_data)
+{
+	gchar opened = FALSE;
+	gchar *locale_path;
+
+	locale_path = utils_get_locale_from_utf8(path);
+
+	if (!g_path_is_absolute(locale_path))
+	{
+		gchar *cwd = g_get_current_dir();
+		SETPTR(locale_path, g_build_filename(cwd, locale_path, NULL));
+		g_free(cwd);
+	}
+
+	if (g_str_has_suffix(path, ".geany"))
+	{
+		g_idle_add((GSourceFunc)open_project_idle, locale_path);
+		opened = TRUE;
+	}
+	else
+	{
+		opened = document_open_file(locale_path, FALSE, NULL, NULL) != NULL;
+		g_free(locale_path);
+	}
+
+	return opened;
+}
+
 
 void osx_ui_init(void)
 {
@@ -43,7 +98,11 @@ void osx_ui_init(void)
 	gtkosx_application_set_help_menu(osx_app, GTK_MENU_ITEM(item));
 
 	gtkosx_application_set_use_quartz_accelerators(osx_app, FALSE);
+
+	g_signal_connect(osx_app, "NSApplicationBlockTermination",
+					G_CALLBACK(app_block_termination_cb), NULL);
+	g_signal_connect(osx_app, "NSApplicationOpenFile",
+					G_CALLBACK(app_open_file_cb), NULL);
 }
 
 #endif /* MAC_INTEGRATION */
-



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list