file chooser: Set default widget in create folder popover

This is using the new default widget functionality for
popovers to make Enter in the entry activate the Create
button.

https://bugzilla.gnome.org/show_bug.cgi?id=747664
This commit is contained in:
Matthias Clasen 2015-04-17 00:14:28 -04:00
parent e1c1fc59e5
commit adb58b2c84
3 changed files with 8 additions and 0 deletions

View File

@ -82,6 +82,7 @@
#include "gtkmain.h" #include "gtkmain.h"
#include "gtkscrollable.h" #include "gtkscrollable.h"
#include "gtkadjustment.h" #include "gtkadjustment.h"
#include "gtkpopover.h"
#include <cairo-gobject.h> #include <cairo-gobject.h>
#include <errno.h> #include <errno.h>
@ -7588,6 +7589,8 @@ post_process_ui (GtkFileChooserWidget *impl)
* that priv->icon_size be already setup. * that priv->icon_size be already setup.
*/ */
set_icon_cell_renderer_fixed_size (impl); set_icon_cell_renderer_fixed_size (impl);
gtk_popover_set_default_widget (GTK_POPOVER (impl->priv->new_folder_popover), impl->priv->new_folder_create_button);
} }
static void static void

View File

@ -2650,6 +2650,7 @@ create_rename_popover (GtkPlacesSidebar *sidebar)
"column-spacing", 6, "column-spacing", 6,
NULL); NULL);
entry = gtk_entry_new (); entry = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
g_signal_connect (entry, "changed", G_CALLBACK (rename_entry_changed), sidebar); g_signal_connect (entry, "changed", G_CALLBACK (rename_entry_changed), sidebar);
str = g_strdup_printf ("<b>%s</b>", _("Name")); str = g_strdup_printf ("<b>%s</b>", _("Name"));
label = gtk_label_new (str); label = gtk_label_new (str);
@ -2658,6 +2659,7 @@ create_rename_popover (GtkPlacesSidebar *sidebar)
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
g_free (str); g_free (str);
button = gtk_button_new_with_mnemonic (_("_Rename")); button = gtk_button_new_with_mnemonic (_("_Rename"));
gtk_widget_set_can_default (button, TRUE);
gtk_style_context_add_class (gtk_widget_get_style_context (button), "suggested-action"); gtk_style_context_add_class (gtk_widget_get_style_context (button), "suggested-action");
g_signal_connect (button, "clicked", G_CALLBACK (do_rename), sidebar); g_signal_connect (button, "clicked", G_CALLBACK (do_rename), sidebar);
error = gtk_label_new (""); error = gtk_label_new ("");
@ -2667,6 +2669,7 @@ create_rename_popover (GtkPlacesSidebar *sidebar)
gtk_grid_attach (GTK_GRID (grid), button,1, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), button,1, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), error, 0, 2, 2, 1); gtk_grid_attach (GTK_GRID (grid), error, 0, 2, 2, 1);
gtk_widget_show_all (grid); gtk_widget_show_all (grid);
gtk_popover_set_default_widget (GTK_POPOVER (popover), button);
sidebar->rename_popover = popover; sidebar->rename_popover = popover;
sidebar->rename_entry = entry; sidebar->rename_entry = entry;

View File

@ -388,6 +388,7 @@
<object class="GtkEntry" id="new_folder_name_entry"> <object class="GtkEntry" id="new_folder_name_entry">
<property name="visible">True</property> <property name="visible">True</property>
<property name="width-chars">25</property> <property name="width-chars">25</property>
<property name="activates_default">True</property>
<signal name="changed" handler="new_folder_name_changed"/> <signal name="changed" handler="new_folder_name_changed"/>
</object> </object>
<packing> <packing>
@ -401,6 +402,7 @@
<property name="sensitive">False</property> <property name="sensitive">False</property>
<property name="label" translatable="yes">_Create</property> <property name="label" translatable="yes">_Create</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="can_default">True</property>
<signal name="clicked" handler="new_folder_create_clicked"/> <signal name="clicked" handler="new_folder_create_clicked"/>
<style> <style>
<class name="suggested-action"/> <class name="suggested-action"/>