[gedit/wip/3.14-osx: 69/69] [osx] Custom delegate to implement applicaitonShouldHandleReopen
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/3.14-osx: 69/69] [osx] Custom delegate to implement applicaitonShouldHandleReopen
- Date: Tue, 26 Aug 2014 16:53:30 +0000 (UTC)
commit 5c6ab339a146bc24858ffb9a5c32bbcdec4c0229
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Tue Aug 26 18:39:54 2014 +0200
[osx] Custom delegate to implement applicaitonShouldHandleReopen
gedit/gedit-app-osx.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 78 insertions(+), 2 deletions(-)
---
diff --git a/gedit/gedit-app-osx.c b/gedit/gedit-app-osx.c
index 6253edc..d634dd4 100644
--- a/gedit/gedit-app-osx.c
+++ b/gedit/gedit-app-osx.c
@@ -30,11 +30,80 @@
#include "gedit-commands.h"
#include "gedit-recent.h"
+ interface GeditAppOSXDelegate : NSObject
+{
+ GeditAppOSX *app;
+ id<NSApplicationDelegate> orig;
+}
+
+- (id)initWithApp:(GeditAppOSX *)theApp;
+- (void)release;
+
+- (id)forwardingTargetForSelector:(SEL)aSelector;
+- (BOOL)respondsToSelector:(SEL)aSelector;
+
+- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag;
+
+ end
+
+ implementation GeditAppOSXDelegate
+- (id)initWithApp:(GeditAppOSX *)theApp
+{
+ [super init];
+ app = theApp;
+
+ orig = [NSApp delegate];
+ [NSApp setDelegate:self];
+
+ return self;
+}
+
+- (void)release
+{
+ [NSApp setDelegate:orig];
+ [super release];
+}
+
+- (id)forwardingTargetForSelector:(SEL)aSelector
+{
+ return orig;
+}
+
+- (BOOL)respondsToSelector:(SEL)aSelector
+{
+ return [super respondsToSelector:aSelector] || [orig respondsToSelector:aSelector];
+}
+
+- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
+{
+ GeditWindow *window = NULL;
+
+ window = GEDIT_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (app)));
+
+ if (!flag || !window)
+ {
+ // Simply create a new window with an empty doc
+ window = gedit_app_create_window (GEDIT_APP (app), NULL);
+
+ gedit_debug_message (DEBUG_APP, "Show window");
+ gtk_widget_show (GTK_WIDGET (window));
+
+ gedit_window_create_tab (window, TRUE);
+ }
+
+ gtk_window_present (GTK_WINDOW (window));
+ return NO;
+}
+
+ end
+
struct _GeditAppOSXPrivate
{
GeditMenuExtension *recent_files_menu;
gulong recent_manager_changed_id;
+ GeditAppOSXDelegate *app_delegate;
+
GList *recent_actions;
GeditRecentConfiguration recent_config;
};
@@ -72,6 +141,8 @@ gedit_app_osx_finalize (GObject *object)
gedit_recent_configuration_destroy (&app_osx->priv->recent_config);
+ [app_osx->priv->app_delegate release];
+
G_OBJECT_CLASS (gedit_app_osx_parent_class)->finalize (object);
}
@@ -273,6 +344,7 @@ static void
gedit_app_osx_startup (GApplication *application)
{
GeditAppOSX *app_osx;
+ id delegate;
const gchar *replace_accels[] = {
"<Primary><Alt>F",
@@ -281,12 +353,14 @@ gedit_app_osx_startup (GApplication *application)
G_APPLICATION_CLASS (gedit_app_osx_parent_class)->startup (application);
+ app_osx = GEDIT_APP_OSX (application);
+
+ app_osx->priv->app_delegate = [[[GeditAppOSXDelegate alloc] initWithApp:app_osx] retain];
+
gtk_application_set_accels_for_action (GTK_APPLICATION (application),
"win.replace",
replace_accels);
- app_osx = GEDIT_APP_OSX (application);
-
gedit_recent_configuration_init_default (&app_osx->priv->recent_config);
app_osx->priv->recent_files_menu = _gedit_app_extend_menu (GEDIT_APP (application),
@@ -301,6 +375,8 @@ gedit_app_osx_startup (GApplication *application)
recent_files_menu_populate (app_osx);
g_application_hold (application);
+
+ delegate = [NSApp delegate];
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]