Add support for nicely aligned description labels.

* libnautilus-extensions/nautilus-radio-button-group.c:
	(button_toggled), (nautilus_radio_button_group_insert),
	(nautilus_radio_button_group_get_active_index),
	(nautilus_radio_button_group_set_entry_pixbuf),
	(nautilus_radio_button_group_set_entry_description_text):
	* libnautilus-extensions/nautilus-radio-button-group.h:
	Add support for nicely aligned description labels.

	* src/nautilus-first-time-druid.c: (create_named_pixbuf),
	(set_up_user_level_page), (nautilus_first_time_druid_show):
	Add icons for each of the user levels.

	Use radio group description labels for the description blurb so
	that they align nicely.

	* test/test-nautilus-widgets.c: (test_radio_group):
	Update for description label support.
This commit is contained in:
Ramiro Estrugo 2000-07-18 09:04:23 +00:00
parent 1ba25ba014
commit b70e6e52b7
7 changed files with 239 additions and 69 deletions

View file

@ -1,3 +1,23 @@
2000-07-18 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus-extensions/nautilus-radio-button-group.c:
(button_toggled), (nautilus_radio_button_group_insert),
(nautilus_radio_button_group_get_active_index),
(nautilus_radio_button_group_set_entry_pixbuf),
(nautilus_radio_button_group_set_entry_description_text):
* libnautilus-extensions/nautilus-radio-button-group.h:
Add support for nicely aligned description labels.
* src/nautilus-first-time-druid.c: (create_named_pixbuf),
(set_up_user_level_page), (nautilus_first_time_druid_show):
Add icons for each of the user levels.
Use radio group description labels for the description blurb so
that they align nicely.
* test/test-nautilus-widgets.c: (test_radio_group):
Update for description label support.
2000-07-18 Andy Hertzfeld <andy@eazel.com>
* icons/eazel/i-directory.png

View file

@ -27,7 +27,9 @@
#include "nautilus-image.h"
#include <gtk/gtkradiobutton.h>
#include <gtk/gtklabel.h>
#include <gtk/gtksignal.h>
#include "nautilus-gtk-macros.h"
#include "nautilus-glib-extensions.h"
@ -51,6 +53,7 @@ typedef struct
{
GtkWidget *button;
GtkWidget *image;
GtkWidget *description;
} TableRow;
/* NautilusRadioButtonGroupClass methods */
@ -183,8 +186,7 @@ button_toggled (GtkWidget *button, gpointer user_data)
g_assert (button_group != NULL);
g_assert (button_group->details != NULL);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
radio_button_group_emit_changed_signal (button_group, button);
}
}
@ -228,6 +230,7 @@ nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
row->button = gtk_radio_button_new_with_label (button_group->details->group, label);
row->image = NULL;
row->description = NULL;
/*
* For some crazy reason I dont grok, the group has to be fetched each
@ -241,10 +244,10 @@ nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
(gpointer) button_group);
button_group->details->num_rows++;
gtk_table_resize (table, button_group->details->num_rows, 3);
gtk_table_resize (table, button_group->details->num_rows, 2);
/* Column 2 */
/* Place the radio button in column 2 */
gtk_table_attach (table,
row->button, /* child */
1, /* left_attatch */
@ -282,8 +285,7 @@ nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_g
button_iterator = button_group->details->rows;
while (button_iterator)
{
while (button_iterator) {
TableRow *row;
row = button_iterator->data;
@ -291,8 +293,7 @@ nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_g
g_assert (row->button != NULL);
g_assert (GTK_TOGGLE_BUTTON (row->button));
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (row->button)))
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (row->button))) {
return i;
}
@ -325,32 +326,31 @@ nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_g
/* Set an item's pixbuf. */
void
nautilus_radio_button_group_set_pixbuf (NautilusRadioButtonGroup *button_group,
guint index,
GdkPixbuf *pixbuf)
nautilus_radio_button_group_set_entry_pixbuf (NautilusRadioButtonGroup *button_group,
guint entry_index,
GdkPixbuf *pixbuf)
{
GtkTable *table;
TableRow *row;
g_return_if_fail (button_group != NULL);
g_return_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (button_group));
g_return_if_fail (index < g_list_length (button_group->details->rows));
g_return_if_fail (entry_index < g_list_length (button_group->details->rows));
table = GTK_TABLE (button_group);
row = g_list_nth_data (button_group->details->rows, index);
row = g_list_nth_data (button_group->details->rows, entry_index);
g_assert (row != NULL);
if (row->image == NULL)
{
if (row->image == NULL) {
row->image = nautilus_image_new ();
gtk_table_attach (table,
row->image, /* child */
0, /* left_attatch */
1, /* right_attatch */
index, /* top_attatch */
index + 1, /* bottom_attatch */
entry_index, /* top_attatch */
entry_index + 1, /* bottom_attatch */
GTK_FILL, /* xoptions */
(GTK_FILL|GTK_EXPAND), /* yoptions */
0, /* xpadding */
@ -364,3 +364,44 @@ nautilus_radio_button_group_set_pixbuf (NautilusRadioButtonGroup *button_group,
nautilus_image_set_pixbuf (NAUTILUS_IMAGE (row->image), pixbuf);
}
/* Set an item's description. */
void
nautilus_radio_button_group_set_entry_description_text (NautilusRadioButtonGroup *button_group,
guint entry_index,
const char *description_text)
{
GtkTable *table;
TableRow *row;
g_return_if_fail (button_group != NULL);
g_return_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (button_group));
g_return_if_fail (entry_index < g_list_length (button_group->details->rows));
table = GTK_TABLE (button_group);
row = g_list_nth_data (button_group->details->rows, entry_index);
g_assert (row != NULL);
if (row->description == NULL) {
row->description = gtk_label_new (description_text);
gtk_misc_set_alignment (GTK_MISC (row->description), 0, 0.5);
gtk_table_attach (table,
row->description, /* child */
2, /* left_attatch */
3, /* right_attatch */
entry_index, /* top_attatch */
entry_index + 1, /* bottom_attatch */
(GTK_FILL|GTK_EXPAND), /* xoptions */
(GTK_FILL|GTK_EXPAND), /* yoptions */
0, /* xpadding */
0); /* ypadding */
gtk_widget_show (row->description);
}
else {
gtk_label_set_text (GTK_LABEL (row->description), description_text);
}
}

View file

@ -31,8 +31,14 @@
/*
* NautilusRadioButtonGroup is a collection of radio buttons
* arranged into rows. An optional icon can be displayed
* with each radio button entry.
* arranged into rows. An optional icon and description can
* can be displayed with each radio button entry:
*
* Icon1 < > Item one Item 1 description
* Icon2 < > Item two Item 2 description
* Icon3 <x> Item three Item 3 description
* Icon4 < > Item four Item 4 description
*
*/
BEGIN_GNOME_DECLS
@ -64,26 +70,30 @@ typedef struct
guint active_button_index;
} NautilusRadioButtonGroupSignalData;
GtkType nautilus_radio_button_group_get_type (void);
GtkWidget* nautilus_radio_button_group_new (void);
GtkType nautilus_radio_button_group_get_type (void);
GtkWidget* nautilus_radio_button_group_new (void);
/* Insert a new item to the group. Returns the new item's index */
guint nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
const gchar *label);
guint nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
const gchar *label);
/* Get the active item index. By law there always is an active item */
guint nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_group);
guint nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_group);
/* Set the active item index. */
void nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_group,
guint active_index);
void nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_group,
guint active_index);
/* Set an item's pixbuf. */
void nautilus_radio_button_group_set_pixbuf (NautilusRadioButtonGroup *button_group,
guint index,
GdkPixbuf *pixbuf);
void nautilus_radio_button_group_set_entry_pixbuf (NautilusRadioButtonGroup *button_group,
guint entry_index,
GdkPixbuf *pixbuf);
/* Set an item's description. */
void nautilus_radio_button_group_set_entry_description_text (NautilusRadioButtonGroup *button_group,
guint entry_index,
const char *description);
BEGIN_GNOME_DECLS

View file

@ -27,7 +27,9 @@
#include "nautilus-image.h"
#include <gtk/gtkradiobutton.h>
#include <gtk/gtklabel.h>
#include <gtk/gtksignal.h>
#include "nautilus-gtk-macros.h"
#include "nautilus-glib-extensions.h"
@ -51,6 +53,7 @@ typedef struct
{
GtkWidget *button;
GtkWidget *image;
GtkWidget *description;
} TableRow;
/* NautilusRadioButtonGroupClass methods */
@ -183,8 +186,7 @@ button_toggled (GtkWidget *button, gpointer user_data)
g_assert (button_group != NULL);
g_assert (button_group->details != NULL);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
radio_button_group_emit_changed_signal (button_group, button);
}
}
@ -228,6 +230,7 @@ nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
row->button = gtk_radio_button_new_with_label (button_group->details->group, label);
row->image = NULL;
row->description = NULL;
/*
* For some crazy reason I dont grok, the group has to be fetched each
@ -241,10 +244,10 @@ nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
(gpointer) button_group);
button_group->details->num_rows++;
gtk_table_resize (table, button_group->details->num_rows, 3);
gtk_table_resize (table, button_group->details->num_rows, 2);
/* Column 2 */
/* Place the radio button in column 2 */
gtk_table_attach (table,
row->button, /* child */
1, /* left_attatch */
@ -282,8 +285,7 @@ nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_g
button_iterator = button_group->details->rows;
while (button_iterator)
{
while (button_iterator) {
TableRow *row;
row = button_iterator->data;
@ -291,8 +293,7 @@ nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_g
g_assert (row->button != NULL);
g_assert (GTK_TOGGLE_BUTTON (row->button));
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (row->button)))
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (row->button))) {
return i;
}
@ -325,32 +326,31 @@ nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_g
/* Set an item's pixbuf. */
void
nautilus_radio_button_group_set_pixbuf (NautilusRadioButtonGroup *button_group,
guint index,
GdkPixbuf *pixbuf)
nautilus_radio_button_group_set_entry_pixbuf (NautilusRadioButtonGroup *button_group,
guint entry_index,
GdkPixbuf *pixbuf)
{
GtkTable *table;
TableRow *row;
g_return_if_fail (button_group != NULL);
g_return_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (button_group));
g_return_if_fail (index < g_list_length (button_group->details->rows));
g_return_if_fail (entry_index < g_list_length (button_group->details->rows));
table = GTK_TABLE (button_group);
row = g_list_nth_data (button_group->details->rows, index);
row = g_list_nth_data (button_group->details->rows, entry_index);
g_assert (row != NULL);
if (row->image == NULL)
{
if (row->image == NULL) {
row->image = nautilus_image_new ();
gtk_table_attach (table,
row->image, /* child */
0, /* left_attatch */
1, /* right_attatch */
index, /* top_attatch */
index + 1, /* bottom_attatch */
entry_index, /* top_attatch */
entry_index + 1, /* bottom_attatch */
GTK_FILL, /* xoptions */
(GTK_FILL|GTK_EXPAND), /* yoptions */
0, /* xpadding */
@ -364,3 +364,44 @@ nautilus_radio_button_group_set_pixbuf (NautilusRadioButtonGroup *button_group,
nautilus_image_set_pixbuf (NAUTILUS_IMAGE (row->image), pixbuf);
}
/* Set an item's description. */
void
nautilus_radio_button_group_set_entry_description_text (NautilusRadioButtonGroup *button_group,
guint entry_index,
const char *description_text)
{
GtkTable *table;
TableRow *row;
g_return_if_fail (button_group != NULL);
g_return_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (button_group));
g_return_if_fail (entry_index < g_list_length (button_group->details->rows));
table = GTK_TABLE (button_group);
row = g_list_nth_data (button_group->details->rows, entry_index);
g_assert (row != NULL);
if (row->description == NULL) {
row->description = gtk_label_new (description_text);
gtk_misc_set_alignment (GTK_MISC (row->description), 0, 0.5);
gtk_table_attach (table,
row->description, /* child */
2, /* left_attatch */
3, /* right_attatch */
entry_index, /* top_attatch */
entry_index + 1, /* bottom_attatch */
(GTK_FILL|GTK_EXPAND), /* xoptions */
(GTK_FILL|GTK_EXPAND), /* yoptions */
0, /* xpadding */
0); /* ypadding */
gtk_widget_show (row->description);
}
else {
gtk_label_set_text (GTK_LABEL (row->description), description_text);
}
}

View file

@ -31,8 +31,14 @@
/*
* NautilusRadioButtonGroup is a collection of radio buttons
* arranged into rows. An optional icon can be displayed
* with each radio button entry.
* arranged into rows. An optional icon and description can
* can be displayed with each radio button entry:
*
* Icon1 < > Item one Item 1 description
* Icon2 < > Item two Item 2 description
* Icon3 <x> Item three Item 3 description
* Icon4 < > Item four Item 4 description
*
*/
BEGIN_GNOME_DECLS
@ -64,26 +70,30 @@ typedef struct
guint active_button_index;
} NautilusRadioButtonGroupSignalData;
GtkType nautilus_radio_button_group_get_type (void);
GtkWidget* nautilus_radio_button_group_new (void);
GtkType nautilus_radio_button_group_get_type (void);
GtkWidget* nautilus_radio_button_group_new (void);
/* Insert a new item to the group. Returns the new item's index */
guint nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
const gchar *label);
guint nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
const gchar *label);
/* Get the active item index. By law there always is an active item */
guint nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_group);
guint nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_group);
/* Set the active item index. */
void nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_group,
guint active_index);
void nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_group,
guint active_index);
/* Set an item's pixbuf. */
void nautilus_radio_button_group_set_pixbuf (NautilusRadioButtonGroup *button_group,
guint index,
GdkPixbuf *pixbuf);
void nautilus_radio_button_group_set_entry_pixbuf (NautilusRadioButtonGroup *button_group,
guint entry_index,
GdkPixbuf *pixbuf);
/* Set an item's description. */
void nautilus_radio_button_group_set_entry_description_text (NautilusRadioButtonGroup *button_group,
guint entry_index,
const char *description);
BEGIN_GNOME_DECLS

View file

@ -121,12 +121,31 @@ signup_selection_changed (GtkWidget *radio_buttons, gpointer user_data)
last_signup_choice = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons));
}
static GdkPixbuf*
create_named_pixbuf (const char *name)
{
GdkPixbuf *pixbuf;
char *path;
g_return_val_if_fail (name != NULL, NULL);
path = nautilus_pixmap_file (name);
pixbuf = gdk_pixbuf_new_from_file (path);
g_free (path);
g_assert (pixbuf != NULL);
return pixbuf;
}
/* set up the user level page */
static void
set_up_user_level_page (NautilusDruidPageStandard *page)
{
GtkWidget *radio_buttons, *frame, *label;
GtkWidget *container, *main_box;
GdkPixbuf *user_level_icons[3];
container = set_up_background (page, "rgb:bbbb/bbbb/eeee-rgb:ffff/ffff/ffff:h");
@ -150,9 +169,27 @@ set_up_user_level_page (NautilusDruidPageStandard *page)
gtk_container_add (GTK_CONTAINER (frame),
radio_buttons);
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), _("Novice - for beginning users"));
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), _("Intermediate - for non-technical users"));
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), _("Hacker - for expert users"));
user_level_icons[0] = create_named_pixbuf ("novice.png");
g_assert (user_level_icons[0] != NULL);
user_level_icons[1] = create_named_pixbuf ("intermediate.png");
g_assert (user_level_icons[1] != NULL);
user_level_icons[2] = create_named_pixbuf ("expert.png");
g_assert (user_level_icons[3] != NULL);
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), _("Novice"));
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), _("Intermediate"));
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), _("Hacker"));
nautilus_radio_button_group_set_entry_pixbuf (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), 0, user_level_icons[0]);
nautilus_radio_button_group_set_entry_pixbuf (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), 1, user_level_icons[1]);
nautilus_radio_button_group_set_entry_pixbuf (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), 2, user_level_icons[2]);
nautilus_radio_button_group_set_entry_description_text (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), 0, _("For beginning users"));
nautilus_radio_button_group_set_entry_description_text (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), 1, _("For non-technical users"));
nautilus_radio_button_group_set_entry_description_text (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons), 2, _("For expert users"));
nautilus_radio_button_group_set_active_index (NAUTILUS_RADIO_BUTTON_GROUP (radio_buttons),
nautilus_user_level_manager_get_user_level ());
@ -295,7 +332,14 @@ GtkWidget *nautilus_first_time_druid_show (NautilusApplication *application, gbo
NULL);
gtk_widget_show_all (druid);
gtk_widget_set_usize (druid, 400, 320);
/* Im commenting out this call cause it makes the druid unusable for me and
* thus any new users of nautilus that use large fonts as i do.
* Perhaps we need a better way to control the druid geometry. We can
* file specific bugs for that --ramiro
*/
/* gtk_widget_set_usize (druid, 400, 320); */
gtk_widget_show (GTK_WIDGET (dialog));
return druid;

View file

@ -77,9 +77,13 @@ test_radio_group (void)
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Oranges");
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Strawberries");
nautilus_radio_button_group_set_pixbuf (NAUTILUS_RADIO_BUTTON_GROUP (buttons), 0, pixbufs[0]);
nautilus_radio_button_group_set_pixbuf (NAUTILUS_RADIO_BUTTON_GROUP (buttons), 1, pixbufs[1]);
nautilus_radio_button_group_set_pixbuf (NAUTILUS_RADIO_BUTTON_GROUP (buttons), 2, pixbufs[2]);
nautilus_radio_button_group_set_entry_pixbuf (NAUTILUS_RADIO_BUTTON_GROUP (buttons), 0, pixbufs[0]);
nautilus_radio_button_group_set_entry_pixbuf (NAUTILUS_RADIO_BUTTON_GROUP (buttons), 1, pixbufs[1]);
nautilus_radio_button_group_set_entry_pixbuf (NAUTILUS_RADIO_BUTTON_GROUP (buttons), 2, pixbufs[2]);
nautilus_radio_button_group_set_entry_description_text (NAUTILUS_RADIO_BUTTON_GROUP (buttons), 0, _("Apple description"));
nautilus_radio_button_group_set_entry_description_text (NAUTILUS_RADIO_BUTTON_GROUP (buttons), 1, _("Oranges description"));
nautilus_radio_button_group_set_entry_description_text (NAUTILUS_RADIO_BUTTON_GROUP (buttons), 2, _("Strawberries description"));
gdk_pixbuf_unref (pixbufs[0]);
gdk_pixbuf_unref (pixbufs[1]);