pidgin: c42bc466: Automatically enable and disable the Add...
qulogic at pidgin.im
qulogic at pidgin.im
Thu Jul 2 23:41:19 EDT 2009
-----------------------------------------------------------------
Revision: c42bc466fe87fe88f10ea89dc23afe70d342f89c
Ancestor: a062c3ab68e8a6201d3375d98dedb80503136bfb
Author: qulogic at pidgin.im
Date: 2009-07-03T01:18:02
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/c42bc466fe87fe88f10ea89dc23afe70d342f89c
Modified files:
pidgin/gtksmiley.c
ChangeLog:
Automatically enable and disable the Add/Save button in the PidginSmiley
edit window. That should take care of that TODO comment and "provide a
better user experience".
-------------- next part --------------
============================================================
--- pidgin/gtksmiley.c 615f98ea6e40fa5facb3d9143fb601f73822ca73
+++ pidgin/gtksmiley.c 036a23869cf31eb99f6fa14e598311440d166d95
@@ -49,6 +49,7 @@ struct _PidginSmiley
GdkPixbuf *custom_pixbuf;
gpointer data; /** @since 2.6.0 */
gsize datasize; /** @since 2.6.0 */
+ gint entry_len; /** @since 2.6.0 */
};
typedef struct
@@ -226,18 +227,6 @@ static void do_add(GtkWidget *widget, Pi
PurpleSmiley *emoticon;
entry = gtk_entry_get_text(GTK_ENTRY(s->smile));
- if (!entry || !*entry) {
- /*
- * TODO: We should enable/disable the add button based on
- * whether the user has entered all required data. That
- * would eliminate the need for this check and provide a
- * better user experience.
- */
- purple_notify_error(s->parent, _("Custom Smiley"),
- _("More Data needed"),
- _("Please provide a shortcut to associate with the smiley."));
- return;
- }
emoticon = purple_smileys_find_by_shortcut(entry);
if (emoticon && emoticon != s->smiley) {
@@ -267,15 +256,6 @@ static void do_add(GtkWidget *widget, Pi
}
purple_smiley_set_shortcut(s->smiley, entry);
} else {
- if ((s->filename == NULL && s->custom_pixbuf == NULL)
- || *entry == 0) {
- purple_notify_error(s->parent, _("Custom Smiley"),
- _("More Data needed"),
- s->filename ? _("Please provide a shortcut to associate with the smiley.")
- : _("Please select an image for the smiley."));
- return;
- }
-
purple_debug_info("gtksmiley", "adding a new smiley\n");
if (s->filename == NULL) {
@@ -355,6 +335,9 @@ static void do_add_file_cb(const char *f
if (pixbuf)
g_object_unref(G_OBJECT(pixbuf));
gtk_widget_grab_focus(s->smile);
+
+ if (s->entry_len > 0)
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(s->parent), GTK_RESPONSE_ACCEPT, TRUE);
}
static void
@@ -368,6 +351,36 @@ open_image_selector(GtkWidget *widget, P
gtk_widget_show_all(file_chooser);
}
+static void
+smiley_name_insert_cb(GtkEditable *editable,
+ gchar *new_text,
+ gint new_text_length,
+ gint *position,
+ gpointer user_data)
+{
+ PidginSmiley *s = user_data;
+ if (new_text_length != -1)
+ s->entry_len += new_text_length;
+ else
+ s->entry_len += strlen(new_text);
+
+ if (s->filename != NULL || s->custom_pixbuf != NULL || s->smiley != NULL)
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(s->parent), GTK_RESPONSE_ACCEPT, TRUE);
+}
+
+static void
+smiley_name_delete_cb(GtkEditable *editable,
+ gint start_pos,
+ gint end_pos,
+ gpointer user_data)
+{
+ PidginSmiley *s = user_data;
+ s->entry_len -= end_pos - start_pos;
+
+ if (s->entry_len <= 0)
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(s->parent), GTK_RESPONSE_ACCEPT, FALSE);
+}
+
PidginSmiley *
pidgin_smiley_edit(GtkWidget *widget, PurpleSmiley *smiley)
{
@@ -441,10 +454,18 @@ pidgin_smiley_edit(GtkWidget *widget, Pu
s->smile = gtk_entry_new();
gtk_entry_set_activates_default(GTK_ENTRY(s->smile), TRUE);
pidgin_set_accessible_label(s->smile, label);
- if (smiley)
- gtk_entry_set_text(GTK_ENTRY(s->smile), purple_smiley_get_shortcut(smiley));
+ if (smiley) {
+ const char *shortcut = purple_smiley_get_shortcut(smiley);
+ gtk_entry_set_text(GTK_ENTRY(s->smile), shortcut);
+ s->entry_len = strlen(shortcut);
+ }
+ else
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(window), GTK_RESPONSE_ACCEPT, FALSE);
g_signal_connect(s->smile, "activate", G_CALLBACK(do_add), s);
+ /* gtk_entry_get_text_length is 2.14+, so we'll just keep track ourselves */
+ g_signal_connect(G_OBJECT(s->smile), "insert-text", G_CALLBACK(smiley_name_insert_cb), s);
+ g_signal_connect(G_OBJECT(s->smile), "delete-text", G_CALLBACK(smiley_name_delete_cb), s);
gtk_box_pack_end(GTK_BOX(hbox), s->smile, FALSE, FALSE, 0);
gtk_widget_show(s->smile);
More information about the Commits
mailing list