Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
(James Vega)
diff --git a/src/gui_gtk.c b/src/gui_gtk.c
index 52d75e4..1533c64 100644
--- a/src/gui_gtk.c
+++ b/src/gui_gtk.c
@@ -420,10 +420,6 @@
 menu_item_activate(GtkWidget *widget UNUSED, gpointer data)
 {
     gui_menu_cb((vimmenu_T *)data);
-
-    /* make sure the menu action is taken immediately */
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
 }
 
     void
@@ -731,9 +727,6 @@
     }
 
     gui_drag_scrollbar(sb, value, dragging);
-
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
 }
 
 /* SBAR_VERT or SBAR_HORIZ */
@@ -780,10 +773,7 @@
  * Implementation of the file selector related stuff
  */
 #if GTK_CHECK_VERSION(2,4,0)
-/* This has been disabled, because the GTK library rewrites
- * ~/.recently-used.xbel every time the main loop is quit.  For Vim that means
- * on just about any event. */
-/* # define USE_FILE_CHOOSER */
+# define USE_FILE_CHOOSER
 #endif
 
 #ifndef USE_FILE_CHOOSER
@@ -798,8 +788,6 @@
     vw->browse_fname = (char_u *)g_strdup(gtk_file_selection_get_filename(
 					GTK_FILE_SELECTION(vw->filedlg)));
     gtk_widget_hide(vw->filedlg);
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
 }
 
     static void
@@ -813,8 +801,6 @@
 	vw->browse_fname = NULL;
     }
     gtk_widget_hide(vw->filedlg);
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
 }
 
     static gboolean
@@ -826,10 +812,7 @@
 	gui.browse_fname = NULL;
     }
     gui.filedlg = NULL;
-
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
-
+    gtk_main_quit();
     return FALSE;
 }
 #endif
@@ -882,6 +865,8 @@
 	    NULL);
     gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc),
 						       (const gchar *)dirbuf);
+    if (saving && dflt != NULL && *dflt != NUL)
+	gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), (char *)dflt);
 
     gui.browse_fname = NULL;
     if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT)
@@ -929,8 +914,7 @@
 						      (const gchar *)dirbuf);
 
     gtk_widget_show(gui.filedlg);
-    while (gui.filedlg && GTK_WIDGET_DRAWABLE(gui.filedlg))
-	gtk_main_iteration_do(TRUE);
+    gtk_main();
 #endif
 
     CONVERT_TO_UTF8_FREE(title);
@@ -1840,9 +1824,6 @@
     rc = gui_do_findrepl(flags, find_text, repl_text, direction_down);
     CONVERT_FROM_UTF8_FREE(repl_text);
     CONVERT_FROM_UTF8_FREE(find_text);
-
-    if (rc && gtk_main_level() > 0)
-	gtk_main_quit(); /* make sure cmd will be handled immediately */
 }
 
 /* our usual callback function */
diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c
index 84aa710..05cbe0b 100644
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -652,9 +652,6 @@
 	xev.xproperty.window = commWindow;
 	xev.xproperty.state = PropertyNewValue;
 	serverEventProc(GDK_WINDOW_XDISPLAY(widget->window), &xev);
-
-	if (gtk_main_level() > 0)
-	    gtk_main_quit();
     }
     return FALSE;
 }
@@ -788,10 +785,6 @@
     if (widget != gui.drawarea)
 	gtk_widget_grab_focus(gui.drawarea);
 
-    /* make sure the input buffer is read */
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
-
     return TRUE;
 }
 
@@ -805,10 +798,6 @@
     if (blink_state != BLINK_NONE)
 	gui_mch_stop_blink();
 
-    /* make sure the input buffer is read */
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
-
     return TRUE;
 }
 
@@ -1130,9 +1119,6 @@
     if (p_mh)
 	gui_mch_mousehide(TRUE);
 
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
-
     return TRUE;
 }
 
@@ -1167,9 +1153,6 @@
     else
 	clip_lose_selection(&clip_star);
 
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
-
     return TRUE;
 }
 
@@ -1205,9 +1188,6 @@
 	received_selection = RS_FAIL;
 	/* clip_free_selection(cbd); ??? */
 
-	if (gtk_main_level() > 0)
-	    gtk_main_quit();
-
 	return;
     }
 
@@ -1287,9 +1267,6 @@
     received_selection = RS_OK;
     vim_free(tmpbuf);
     g_free(tmpbuf_utf8);
-
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
 }
 
 /*
@@ -1515,9 +1492,6 @@
     /* inform the editor engine about the occurrence of this event */
     gui_send_mouse_event(button, x, y, FALSE, vim_modifiers);
 
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
-
     /*
      * Auto repeat timer handling.
      */
@@ -1700,8 +1674,6 @@
     vim_modifiers = modifiers_gdk2mouse(event->state);
 
     gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers);
-    if (gtk_main_level() > 0)
-	gtk_main_quit(); /* make sure the above will be handled immediately */
 
     return TRUE;
 }
@@ -1743,9 +1715,6 @@
     gui_send_mouse_event(button, (int)event->x, (int)event->y,
 							FALSE, vim_modifiers);
 
-    if (gtk_main_level() > 0)
-	gtk_main_quit(); /* make sure the above will be handled immediately */
-
     return TRUE;
 }
 
@@ -1775,8 +1744,6 @@
     vim_modifiers = modifiers_gdk2mouse(event->state);
 
     gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, vim_modifiers);
-    if (gtk_main_level() > 0)
-	gtk_main_quit();	/* make sure it will be handled immediately */
 
     return TRUE;
 }
@@ -1930,9 +1897,6 @@
 	add_to_input_buf(dropkey, (int)sizeof(dropkey));
     else
 	add_to_input_buf(dropkey + 3, (int)(sizeof(dropkey) - 3));
-
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
 }
 
 /*
@@ -2846,9 +2810,6 @@
 {
     /* Add the string cmd into input buffer */
     send_tabline_menu_event(clicked_page, (int)(long)user_data);
-
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
 }
 
     static void
@@ -2924,8 +2885,7 @@
 	    {
 		/* Click after all tabs moves to next tab page.  When "x" is
 		 * small guess it's the left button. */
-		if (send_tabline_event(x < 50 ? -1 : 0) && gtk_main_level() > 0)
-		    gtk_main_quit();
+		send_tabline_event(x < 50 ? -1 : 0);
 	    }
 	}
     }
@@ -2946,8 +2906,7 @@
 {
     if (!ignore_tabline_evt)
     {
-	if (send_tabline_event(idx + 1) && gtk_main_level() > 0)
-	    gtk_main_quit();
+	send_tabline_event(idx + 1);
     }
 }
 
@@ -3855,9 +3814,6 @@
 {
     if (gui.mainwin != NULL)
 	gtk_widget_destroy(gui.mainwin);
-
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
 }
 
 /*
@@ -5407,8 +5363,8 @@
     void
 gui_mch_update(void)
 {
-    while (gtk_events_pending() && !vim_is_input_buf_full())
-	gtk_main_iteration_do(FALSE);
+    while (g_main_context_pending(NULL) && !vim_is_input_buf_full())
+	g_main_context_iteration(NULL, TRUE);
 }
 
     static gint
@@ -5419,9 +5375,6 @@
     /* Just inform the caller about the occurrence of it */
     *timed_out = TRUE;
 
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
-
     return FALSE;		/* don't happen again */
 }
 
@@ -5438,9 +5391,6 @@
     static char_u bytes[3] = {CSI, (int)KS_EXTRA, (int)KE_SNIFF};
 
     add_to_input_buf(bytes, 3);
-
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
 }
 #endif
 
@@ -5515,7 +5465,7 @@
 	 * situations, sort of race condition).
 	 */
 	if (!input_available())
-	    gtk_main();
+	    g_main_context_iteration(NULL, TRUE);
 
 	/* Got char, return immediately */
 	if (input_available())
@@ -5707,7 +5657,7 @@
 	 * during the FocusGained event. */
 	start = time(NULL);
 	while (received_selection == RS_NONE && time(NULL) < start + 3)
-	    gtk_main();	/* wait for selection_received_cb */
+	    g_main_context_iteration(NULL, TRUE);	/* wait for selection_received_cb */
 
 	if (received_selection != RS_FAIL)
 	    return;