GtkDialog sensitivity/default



Hi,

This is for bug http://bugzilla.gnome.org/show_bug.cgi?id=40303, 
it's annoying to manage sensitivity/default for GtkDialog buttons.

Proposed solution appended. Comments welcome.

Havoc


/**
 * gtk_dialog_set_response_sensitive:
 * @dialog: a #GtkDialog
 * @response_id: a response ID
 * @setting: %TRUE for sensitive
 *
 * Calls gtk_widget_set_sensitive (widget, @setting) for each
 * widget in the dialog's action area with the given @response_id.
 * A convenient way to sensitize/desensitize dialog buttons.
 * 
 **/
void
gtk_dialog_set_response_sensitive (GtkDialog *dialog,
                                   gint       response_id,
                                   gboolean   setting)
{
  GList *children;
  GList *tmp_list;

  children = gtk_container_children (GTK_CONTAINER (dialog));

  tmp_list = children;
  while (tmp_list != NULL)
    {
      ResponseData *rd = g_object_get_data (G_OBJECT (widget),
                                            "gtk-dialog-response-data");

      if (rd && rd->response_id == response_id)
        gtk_widget_set_sensitive (widget, setting);

      tmp_list = g_list_next (tmp_list);
    }

  g_list_free (children);
}

/**
 * gtk_dialog_set_default_response:
 * @dialog: a #GtkDialog
 * @response_id: a response ID
 * 
 * Sets the last widget in the dialog's action area with the given @response_id
 * as the default widget for the dialog. Pressing "Enter" normally activates
 * the default widget.
 * 
 **/
void
gtk_dialog_set_default_response (GtkDialog *dialog,
                                 gint       response_id)
{
  GList *children;
  GList *tmp_list;

  children = gtk_container_children (GTK_CONTAINER (dialog));

  tmp_list = children;
  while (tmp_list != NULL)
    {
      ResponseData *rd = g_object_get_data (G_OBJECT (widget),
                                            "gtk-dialog-response-data");

      if (rd && rd->response_id == response_id)
        gtk_widget_grab_default (widget);

      tmp_list = g_list_next (tmp_list);
    }

  g_list_free (children);
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]