# HG changeset patch
# Node ID 695c3c2b1a4f
# Parent  ecd86ad9f8dc
diff --git a/talkatu/talkatuactiongroup.c b/talkatu/talkatuactiongroup.c
--- a/talkatu/talkatuactiongroup.c
+++ b/talkatu/talkatuactiongroup.c
@@ -347,7 +347,7 @@ talkatu_action_attach_file_attach_respon
 		/* we call this separately for GTK_RESPONSE_CANCEL because
 		 * GTK_RESPONSE_DELETE_EVENT already destroys the dialog.
 		 */
-		gtk_widget_destroy(GTK_WIDGET(dialog));
+		gtk_window_destroy(GTK_WINDOW(dialog));
 	} else if(response == GTK_RESPONSE_ACCEPT) {
 		TalkatuActionGroup *ag = TALKATU_ACTION_GROUP(data);
 		TalkatuActionGroupPrivate *priv = NULL;
@@ -369,29 +369,28 @@ talkatu_action_attach_file_attach_respon
 		/* Send the message! */
 		talkatu_input_send_message(priv->input);
 
-		gtk_widget_destroy(GTK_WIDGET(dialog));
+		gtk_window_destroy(GTK_WINDOW(dialog));
 	}
+
+	g_object_unref(dialog);
 }
 
 static void
 talkatu_action_attach_file_response_cb(GtkDialog *dialog, gint response,
                                        gpointer data)
 {
-	if(response == GTK_RESPONSE_CANCEL) {
-		/* we call this separately for GTK_RESPONSE_CANCEL because
-		 * GTK_RESPONSE_DELETE_EVENT already destroys the dialog.
-		 */
-		gtk_widget_destroy(GTK_WIDGET(dialog));
-	} else if(response == GTK_RESPONSE_ACCEPT) {
+	if(response == GTK_RESPONSE_ACCEPT) {
 		TalkatuActionGroup *ag = TALKATU_ACTION_GROUP(data);
 		TalkatuActionGroupPrivate *priv = NULL;
 		TalkatuAttachment *attachment = NULL;
 		GtkWidget *attach_dialog = NULL;
+		GFile *file = NULL;
 		gchar *filename = NULL, *content_type = NULL, *comment = NULL;
 
 		priv = talkatu_action_group_get_instance_private(ag);
 
-		filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+		file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog));
+		filename = g_file_get_path(file);
 		content_type = g_content_type_guess(filename, NULL, 0, NULL);
 
 		attachment = talkatu_simple_attachment_new(G_GUINT64_CONSTANT(0),
@@ -400,8 +399,7 @@ talkatu_action_attach_file_response_cb(G
 
 		talkatu_attachment_set_local_uri(attachment, filename);
 		g_free(filename);
-
-		gtk_widget_destroy(GTK_WIDGET(dialog));
+		g_object_unref(file);
 
 		comment = talkatu_markup_get_html(priv->buffer, NULL);
 		attach_dialog = talkatu_attachment_dialog_new(attachment, comment);
@@ -410,8 +408,11 @@ talkatu_action_attach_file_response_cb(G
 		g_signal_connect(G_OBJECT(attach_dialog), "response",
 		                 G_CALLBACK(talkatu_action_attach_file_attach_response_cb),
 		                 data);
-		gtk_widget_show_all(attach_dialog);
+		gtk_widget_show(attach_dialog);
 	}
+
+	gtk_native_dialog_destroy(GTK_NATIVE_DIALOG(dialog));
+	g_object_unref(dialog);
 }
 
 static void
@@ -420,34 +421,32 @@ talkatu_action_attach_file(GSimpleAction
 {
 	TalkatuActionGroup *ag = TALKATU_ACTION_GROUP(data);
 	TalkatuActionGroupPrivate *priv = NULL;
-	GtkWidget *dialog = NULL;
+	GtkFileChooserNative *dialog = NULL;
 
 	priv = talkatu_action_group_get_instance_private(ag);
 	g_return_if_fail(TALKATU_IS_INPUT(priv->input));
 
-	dialog = gtk_file_chooser_dialog_new(_("Attach file..."),
+	dialog = gtk_file_chooser_native_new(_("Attach file..."),
 	                                     NULL,
 	                                     GTK_FILE_CHOOSER_ACTION_OPEN,
-	                                     _("Cancel"), GTK_RESPONSE_CANCEL,
-	                                     _("Open"), GTK_RESPONSE_ACCEPT,
-	                                     NULL);
+	                                     _("Open"),
+	                                     _("Cancel"));
 	g_signal_connect(G_OBJECT(dialog), "response",
 	                 G_CALLBACK(talkatu_action_attach_file_response_cb),
 	                 ag);
-	gtk_widget_show_all(dialog);
+	gtk_native_dialog_show(GTK_NATIVE_DIALOG(dialog));
 }
 
 static void
-talkatu_action_insert_link(GSimpleAction *action, GVariant *parameter,
-                           gpointer data)
+talkatu_action_insert_link_response_cb(GtkDialog *dialog, gint response,
+                                       gpointer data)
 {
 	TalkatuActionGroup *ag = TALKATU_ACTION_GROUP(data);
 	TalkatuActionGroupPrivate *priv = NULL;
-	GtkWidget *link_dialog = talkatu_link_dialog_new();
 
 	priv = talkatu_action_group_get_instance_private(ag);
 
-	if(gtk_dialog_run(GTK_DIALOG(link_dialog)) == GTK_RESPONSE_ACCEPT) {
+	if(response == GTK_RESPONSE_ACCEPT) {
 		GtkTextTagTable *table = gtk_text_buffer_get_tag_table(priv->buffer);
 		GtkTextTag *anchor, *anchor_data;
 		GtkTextMark *insert_mark = NULL;
@@ -460,8 +459,8 @@ talkatu_action_insert_link(GSimpleAction
 		}
 
 		/* grab our inputs from the dialog */
-		url = talkatu_link_dialog_get_url(TALKATU_LINK_DIALOG(link_dialog));
-		label = talkatu_link_dialog_get_display_text(TALKATU_LINK_DIALOG(link_dialog));
+		url = talkatu_link_dialog_get_url(TALKATU_LINK_DIALOG(dialog));
+		label = talkatu_link_dialog_get_display_text(TALKATU_LINK_DIALOG(dialog));
 
 		/* find the anchor tag from the table */
 		anchor = gtk_text_tag_table_lookup(table, TALKATU_TAG_ANCHOR);
@@ -472,7 +471,8 @@ talkatu_action_insert_link(GSimpleAction
 		 * bother with that.
 		 */
 		anchor_data = gtk_text_tag_new(NULL);
-		g_object_set_data_full(G_OBJECT(anchor_data), "talkatu-anchor-url", url, g_free);
+		g_object_set_data_full(G_OBJECT(anchor_data), "talkatu-anchor-url",
+		                       url, g_free);
 		gtk_text_tag_table_add(table, anchor_data);
 
 		insert_mark = gtk_text_buffer_get_insert(priv->buffer);
@@ -491,7 +491,21 @@ talkatu_action_insert_link(GSimpleAction
 		g_free(label);
 	}
 
-	gtk_widget_destroy(link_dialog);
+	gtk_window_destroy(GTK_WINDOW(dialog));
+	g_object_unref(dialog);
+}
+
+static void
+talkatu_action_insert_link(GSimpleAction *action, GVariant *parameter,
+                           gpointer data)
+{
+	GtkWidget *link_dialog = talkatu_link_dialog_new();
+
+	g_signal_connect(G_OBJECT(link_dialog), "response",
+			 G_CALLBACK(talkatu_action_insert_link_response_cb),
+			 data);
+	gtk_window_set_modal(GTK_WINDOW(link_dialog), TRUE);
+	gtk_widget_show(link_dialog);
 }
 
 /******************************************************************************
