Add gtk_native_dialog_destroy()

Its very easy to get extra references to the NativeDialog so that
when you release your last reference any visible dialog is not
hidden. We handle this by adding a destroy method similar to how
you destroy regular toplevels.
This commit is contained in:
Alexander Larsson 2015-11-11 16:06:44 +01:00
parent 402225a8e2
commit 51dc4873fd
6 changed files with 41 additions and 2 deletions

View File

@ -113,6 +113,7 @@ open_response_cb (GtkNativeDialog *dialog,
}
}
gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
g_object_unref (native);
}

View File

@ -2520,6 +2520,7 @@ GTK_TYPE_NATIVE_DIALOG
GtkNativeDialogClass
gtk_native_dialog_show
gtk_native_dialog_hide
gtk_native_dialog_destroy
gtk_native_dialog_get_visible
gtk_native_dialog_set_modal
gtk_native_dialog_get_modal

View File

@ -1008,7 +1008,11 @@ gtk_file_chooser_button_destroy (GtkWidget *widget)
priv->dialog = NULL;
}
g_clear_object (&priv->native);
if (priv->native)
{
gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (priv->native));
g_clear_object (&priv->native);
}
priv->chooser = NULL;

View File

@ -361,6 +361,30 @@ gtk_native_dialog_hide (GtkNativeDialog *self)
g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_VISIBLE]);
}
/**
* gtk_native_dialog_destroy:
* @self: a #GtkNativeDialog
*
* Destroys a dialog.
*
* When a dialog is destroyed, it will break any references it holds
* to other objects. If it is visible it will be hidden and any underlying
* window system resources will be destroyed.
*
* Note that this does not release any reference to the object (as opposed to
* destroying a GtkWindow) because there is no reference from the windowing
* system to the #GtkNativeDialog.
*
* Since: 3.20
**/
void
gtk_native_dialog_destroy (GtkNativeDialog *self)
{
g_return_if_fail (GTK_IS_NATIVE_DIALOG (self));
g_object_run_dispose (G_OBJECT (self));
}
void
_gtk_native_dialog_emit_response (GtkNativeDialog *self,
int response_id)

View File

@ -54,6 +54,8 @@ void gtk_native_dialog_show (GtkNativeDialog *self);
GDK_AVAILABLE_IN_3_20
void gtk_native_dialog_hide (GtkNativeDialog *self);
GDK_AVAILABLE_IN_3_20
void gtk_native_dialog_destroy (GtkNativeDialog *self);
GDK_AVAILABLE_IN_3_20
gboolean gtk_native_dialog_get_visible (GtkNativeDialog *self);
GDK_AVAILABLE_IN_3_20
void gtk_native_dialog_set_modal (GtkNativeDialog *self,

View File

@ -9660,6 +9660,13 @@ native_filter_changed (GtkWidget *combo,
}
}
static void
destroy_native (GtkFileChooserNative *native)
{
gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
g_object_unref (native);
}
void
create_native_dialogs (GtkWidget *widget)
{
@ -9681,7 +9688,7 @@ create_native_dialogs (GtkWidget *widget)
"_accept&native",
"_cancel__native");
g_signal_connect_swapped (G_OBJECT (window), "destroy", G_CALLBACK (g_object_unref), native);
g_signal_connect_swapped (G_OBJECT (window), "destroy", G_CALLBACK (destroy_native), native);
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (native),
g_get_current_dir (),