Commit aba119a2 authored by Paolo Borelli's avatar Paolo Borelli

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.
parent bf90a672
......@@ -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;
......
......@@ -77,8 +77,6 @@ struct _GeditAppPrivate
{
GeditPluginsEngine *engine;
GeditWindow *active_window;
GeditLockdownMask lockdown;
GtkPageSetup *page_setup;
......@@ -236,13 +234,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,
......@@ -432,7 +423,7 @@ gedit_app_activate (GApplication *application)
GeditWindow *window;
gboolean doc_created = FALSE;
window = app->priv->active_window;
window = GEDIT_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (application)));
if (window == NULL || new_window)
{
......@@ -442,10 +433,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)
{
......@@ -893,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,
......@@ -934,81 +901,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;
}
......@@ -1029,7 +936,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;
......@@ -1276,12 +1182,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 = GEDIT_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));
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment