[gedit/wip/gtkapp: 8/8] Remove custom handling of the last active window



commit d3eb6d24cce7d80d5434a85051f3afc9be8a84c1
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Nov 24 14:25:16 2012 +0100

    Remove custom handling of the last active window
    
    We let GtkApplication do it for us.
    Note: the OSX App had some code that kept gedit alive even with all the
    windows removed and this commits breaks that: we will have to use
    g_application_hold if we need to reimplement that.

 gedit/gedit-app-osx.c |   15 -------
 gedit/gedit-app.c     |  109 ++++---------------------------------------------
 gedit/gedit-app.h     |    3 -
 3 files changed, 8 insertions(+), 119 deletions(-)
---
diff --git a/gedit/gedit-app-osx.c b/gedit/gedit-app-osx.c
index 466db13..826f55a 100644
--- a/gedit/gedit-app-osx.c
+++ b/gedit/gedit-app-osx.c
@@ -39,20 +39,6 @@ gedit_app_osx_finalize (GObject *object)
 	G_OBJECT_CLASS (gedit_app_osx_parent_class)->finalize (object);
 }
 
-static gboolean
-gedit_app_osx_last_window_destroyed_impl (GeditApp *app,
-                                          GeditWindow *window)
-{
-	if (!GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "gedit-is-quitting-all")))
-	{
-		/* Create hidden proxy window on OS X to handle the menu */
-		gedit_app_create_window (app, NULL);
-		return FALSE;
-	}
-
-	return GEDIT_APP_CLASS (gedit_app_osx_parent_class)->last_window_destroyed (app, window);
-}
-
 gboolean
 gedit_app_osx_show_url (GeditAppOSX *app,
                         const gchar *url)
@@ -356,7 +342,6 @@ gedit_app_osx_class_init (GeditAppOSXClass *klass)
 	object_class->finalize = gedit_app_osx_finalize;
 	object_class->constructed = gedit_app_osx_constructed;
 
-	app_class->last_window_destroyed = gedit_app_osx_last_window_destroyed_impl;
 	app_class->show_help = gedit_app_osx_show_help_impl;
 	app_class->set_window_title = gedit_app_osx_set_window_title_impl;
 	app_class->quit = gedit_app_osx_quit_impl;
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index f8e6e07..3903721 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -77,8 +77,6 @@ struct _GeditAppPrivate
 {
 	GeditPluginsEngine *engine;
 
-	GeditWindow       *active_window;
-
 	GeditLockdownMask  lockdown;
 
 	GtkPageSetup      *page_setup;
@@ -242,13 +240,6 @@ gedit_app_get_property (GObject    *object,
 	}
 }
 
-static gboolean
-gedit_app_last_window_destroyed_impl (GeditApp    *app,
-                                      GeditWindow *window)
-{
-	return TRUE;
-}
-
 static gchar *
 gedit_app_help_link_id_impl (GeditApp    *app,
                              const gchar *name,
@@ -451,9 +442,8 @@ get_line_column_position (const gchar      *arg,
 }
 
 static void
-gedit_app_activate (GApplication *application)
+gedit_app_activate (GeditApp *app)
 {
-	GeditApp *app = GEDIT_APP (application);
 	GSList *file_list = NULL;
 	gint line_position = 0;
 	gint column_position = 0;
@@ -494,7 +484,9 @@ gedit_app_activate (GApplication *application)
 		file_list = g_slist_reverse (file_list);
 	}
 
-	if (app->priv->active_window == NULL || new_window)
+	window = gtk_application_get_active_window (GTK_APPLICATION (app));
+
+	if (window == NULL || new_window)
 	{
 		gedit_debug_message (DEBUG_APP, "Create main window");
 		window = gedit_app_create_window (app, NULL);
@@ -502,10 +494,6 @@ gedit_app_activate (GApplication *application)
 		gedit_debug_message (DEBUG_APP, "Show window");
 		gtk_widget_show (GTK_WIDGET (window));
 	}
-	else
-	{
-		window = app->priv->active_window;
-	}
 
 	if (geometry)
 	{
@@ -892,26 +880,6 @@ gedit_app_constructed (GObject *object)
 	load_accels ();
 }
 
-static void
-set_active_window (GeditApp    *app,
-                   GeditWindow *window)
-{
-	app->priv->active_window = window;
-}
-
-static gboolean
-window_focus_in_event (GeditWindow   *window, 
-		       GdkEventFocus *event, 
-		       GeditApp      *app)
-{
-	/* updates active_view and active_child when a new toplevel receives focus */
-	g_return_val_if_fail (GEDIT_IS_WINDOW (window), FALSE);
-
-	set_active_window (app, window);
-
-	return FALSE;
-}
-
 static gboolean 
 window_delete_event (GeditWindow *window,
                      GdkEvent    *event,
@@ -935,81 +903,21 @@ window_delete_event (GeditWindow *window,
 	return TRUE;
 }
 
-static void
-window_destroy (GeditWindow *window,
-		GeditApp    *app)
-{
-	GList *windows;
-
-	gtk_application_remove_window (GTK_APPLICATION (app), GTK_WINDOW (window));
-	windows = gtk_application_get_windows (GTK_APPLICATION (app));
-
-	if (window == app->priv->active_window)
-	{
-		set_active_window (app, windows != NULL ? windows->data : NULL);
-	}
-
-/* CHECK: I don't think we have to disconnect this function, since windows
-   is being destroyed */
-/*					     
-	g_signal_handlers_disconnect_by_func (window, 
-					      G_CALLBACK (window_focus_in_event),
-					      app);
-	g_signal_handlers_disconnect_by_func (window, 
-					      G_CALLBACK (window_destroy),
-					      app);
-*/
-	if (windows == NULL)
-	{
-		if (!GEDIT_APP_GET_CLASS (app)->last_window_destroyed (app, window))
-		{
-			return;
-		}
-
-		g_application_quit (G_APPLICATION (app));
-	}
-}
-
 static GeditWindow *
 gedit_app_create_window_impl (GeditApp *app)
 {
 	GeditWindow *window;
-	GList *windows;
-	gboolean is_first;
-	
-	/*
-	 * We need to be careful here, there is a race condition:
-	 * when another gedit is launched it checks active_window,
-	 * so we must do our best to ensure that active_window
-	 * is never NULL when at least a window exists.
-	 */
-
-	windows = gtk_application_get_windows (GTK_APPLICATION (app));
-	is_first = (windows == NULL);
 	
 	window = g_object_new (GEDIT_TYPE_WINDOW, "application", app, NULL);
 
-	if (is_first)
-	{
-		set_active_window (app, window);
-	}
-
 	gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (window));
 
 	gedit_debug_message (DEBUG_APP, "Window created");
 
 	g_signal_connect (window,
-			  "focus_in_event",
-			  G_CALLBACK (window_focus_in_event),
-			  app);
-	g_signal_connect (window,
 			  "delete_event",
 			  G_CALLBACK (window_delete_event),
 			  app);
-	g_signal_connect (window,
-			  "destroy",
-			  G_CALLBACK (window_destroy),
-			  app);
 
 	return window;
 }
@@ -1031,7 +939,6 @@ gedit_app_class_init (GeditAppClass *klass)
 	app_class->local_command_line = gedit_app_local_command_line;
 	app_class->shutdown = gedit_app_shutdown;
 
-	klass->last_window_destroyed = gedit_app_last_window_destroyed_impl;
 	klass->show_help = gedit_app_show_help_impl;
 	klass->help_link_id = gedit_app_help_link_id_impl;
 	klass->set_window_title = gedit_app_set_window_title_impl;
@@ -1285,12 +1192,12 @@ _gedit_app_get_window_in_viewport (GeditApp  *app,
 	g_return_val_if_fail (GEDIT_IS_APP (app), NULL);
 
 	/* first try if the active window */
-	window = app->priv->active_window;
+	window = gtk_application_get_active_window (GTK_APPLICATION (app));
 
-	g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
-
-	if (is_in_viewport (window, screen, workspace, viewport_x, viewport_y))
+	if (window != NULL && is_in_viewport (window, screen, workspace, viewport_x, viewport_y))
+	{
 		return window;
+	}
 
 	/* otherwise try to see if there is a window on this workspace */
 	windows = gtk_application_get_windows (GTK_APPLICATION (app));
diff --git a/gedit/gedit-app.h b/gedit/gedit-app.h
index 58f65d1..b6df192 100644
--- a/gedit/gedit-app.h
+++ b/gedit/gedit-app.h
@@ -60,9 +60,6 @@ struct _GeditAppClass
 {
 	GtkApplicationClass parent_class;
 
-	gboolean (*last_window_destroyed)	(GeditApp    *app,
-	                                         GeditWindow *window);
-
 	gboolean (*show_help)			(GeditApp    *app,
 	                                         GtkWindow   *parent,
 	                                         const gchar *name,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]