[recipes] chef dialog: Manage save button sensitivity
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] chef dialog: Manage save button sensitivity
- Date: Tue, 7 Feb 2017 05:16:17 +0000 (UTC)
commit 229fa0f8ef574b613f329e05abef2228d326c8f0
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Feb 6 16:12:05 2017 +0100
chef dialog: Manage save button sensitivity
Only make the save button sensitive (and thus blue) when we
have reason to believe that some field has changed.
src/gr-chef-dialog.c | 16 ++++++++++++++++
src/gr-chef-dialog.ui | 7 +++++++
2 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-chef-dialog.c b/src/gr-chef-dialog.c
index d6349f9..af437db 100644
--- a/src/gr-chef-dialog.c
+++ b/src/gr-chef-dialog.c
@@ -82,6 +82,12 @@ update_image (GrChefDialog *self)
}
static void
+field_changed (GrChefDialog *self)
+{
+ gtk_widget_set_sensitive (self->save_button, TRUE);
+}
+
+static void
file_chooser_response (GtkNativeDialog *self,
gint response_id,
GrChefDialog *prefs)
@@ -90,6 +96,8 @@ file_chooser_response (GtkNativeDialog *self,
g_free (prefs->image_path);
prefs->image_path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self));
update_image (prefs);
+
+ field_changed (prefs);
}
}
@@ -226,6 +234,8 @@ static void
gr_chef_dialog_set_chef (GrChefDialog *self,
GrChef *chef)
{
+ g_autoptr(GrChef) old_chef = self->chef;
+
if (g_set_object (&self->chef, chef)) {
const char *fullname;
const char *name;
@@ -259,6 +269,11 @@ gr_chef_dialog_set_chef (GrChefDialog *self,
update_image (self);
}
+
+ if (old_chef != NULL && old_chef != chef)
+ gtk_widget_set_sensitive (self->save_button, TRUE);
+ else
+ gtk_widget_set_sensitive (self->save_button, FALSE);
}
static void
@@ -308,6 +323,7 @@ gr_chef_dialog_class_init (GrChefDialogClass *klass)
gtk_widget_class_bind_template_callback (widget_class, chef_selected);
gtk_widget_class_bind_template_callback (widget_class, save_chef);
gtk_widget_class_bind_template_callback (widget_class, close_dialog);
+ gtk_widget_class_bind_template_callback (widget_class, field_changed);
}
GrChefDialog *
diff --git a/src/gr-chef-dialog.ui b/src/gr-chef-dialog.ui
index 6a1a3cf..d7a3bc1 100644
--- a/src/gr-chef-dialog.ui
+++ b/src/gr-chef-dialog.ui
@@ -19,6 +19,7 @@
<child>
<object class="GtkButton" id="save_button">
<property name="visible">1</property>
+ <property name="sensitive">0</property>
<property name="label" translatable="yes">_Save</property>
<property name="use-underline">1</property>
<signal name="clicked" handler="save_chef" swapped="yes"/>
@@ -135,6 +136,7 @@
<object class="GtkEntry" id="fullname">
<property name="visible">1</property>
<property name="placeholder-text" translatable="yes">Name…</property>
+ <signal name="notify::text" handler="field_changed" swapped="yes"/>
</object>
<packing>
<property name="left-attach">1</property>
@@ -145,6 +147,7 @@
<object class="GtkEntry" id="name">
<property name="visible">1</property>
<property name="placeholder-text" translatable="yes">Short Name…</property>
+ <signal name="notify::text" handler="field_changed" swapped="yes"/>
</object>
<packing>
<property name="left-attach">1</property>
@@ -164,6 +167,7 @@
<property name="left-margin">10</property>
<property name="right-margin">10</property>
<property name="bottom-margin">10</property>
+ <property name="buffer">buffer</property>
</object>
</child>
</object>
@@ -219,4 +223,7 @@
</object>
</child>
</object>
+ <object class="GtkTextBuffer" id="buffer">
+ <signal name="changed" handler="field_changed" swapped="yes"/>
+ </object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]