New function to insert a string without having to access the string list

* libnautilus-extensions/nautilus-string-picker.c:
	(nautilus_string_picker_initialize),
	(nautilus_string_picker_destroy),
	(nautilus_string_picker_set_string_list),
	(nautilus_string_picker_get_string_list),
	(nautilus_string_picker_get_selected_string),
	(nautilus_string_picker_set_selected_string),
	(nautilus_string_picker_insert_string):
	* libnautilus-extensions/nautilus-string-picker.h:
	New function to insert a string without having to access the
	string list first.  Also renamed some poorly named functions.

	* libnautilus-extensions/nautilus-preferences-item.c:
	(preferences_item_create_font_family),
	(preferences_item_create_theme), (text_item_changed_callback):
	Update for string picker api changes.

	* test/test-nautilus-widgets.c: (test_string_picker),
	(string_picker_changed_callback):
	Update for string picker api changes.
This commit is contained in:
Ramiro Estrugo 2000-08-18 06:52:56 +00:00
parent 76dc02b090
commit f5f7af7389
8 changed files with 173 additions and 114 deletions

View file

@ -1,3 +1,26 @@
2000-08-17 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus-extensions/nautilus-string-picker.c:
(nautilus_string_picker_initialize),
(nautilus_string_picker_destroy),
(nautilus_string_picker_set_string_list),
(nautilus_string_picker_get_string_list),
(nautilus_string_picker_get_selected_string),
(nautilus_string_picker_set_selected_string),
(nautilus_string_picker_insert_string):
* libnautilus-extensions/nautilus-string-picker.h:
New function to insert a string without having to access the
string list first. Also renamed some poorly named functions.
* libnautilus-extensions/nautilus-preferences-item.c:
(preferences_item_create_font_family),
(preferences_item_create_theme), (text_item_changed_callback):
Update for string picker api changes.
* test/test-nautilus-widgets.c: (test_string_picker),
(string_picker_changed_callback):
Update for string picker api changes.
2000-08-17 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus-extensions/nautilus-string-list.c:

View file

@ -45,12 +45,6 @@ enum
ARG_TITLE_STRING
};
enum
{
ACTIVATE,
LAST_SIGNAL
};
static const guint PREFERENCES_ITEM_TITLE_SPACING = 4;
static const guint PREFERENCES_ITEM_FRAME_BORDER_WIDTH = 6;
static const gint PREFERENCES_ITEM_UNDEFINED_ITEM = -1;
@ -488,7 +482,7 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
g_assert (current_value != NULL);
g_assert (nautilus_string_list_contains (font_list, current_value));
nautilus_string_picker_set_text (NAUTILUS_STRING_PICKER (item->details->child), current_value);
nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (item->details->child), current_value);
g_free (current_value);
@ -612,7 +606,7 @@ preferences_item_create_theme (NautilusPreferencesItem *item,
g_assert (current_value != NULL);
g_assert (nautilus_string_list_contains (theme_list, current_value));
nautilus_string_picker_set_text (NAUTILUS_STRING_PICKER (item->details->child), current_value);
nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (item->details->child), current_value);
g_free (current_value);
@ -694,7 +688,7 @@ text_item_changed_callback (GtkWidget *button, gpointer user_data)
g_assert (item->details->child != NULL);
g_assert (NAUTILUS_IS_STRING_PICKER (item->details->child));
text = nautilus_string_picker_get_text (NAUTILUS_STRING_PICKER (item->details->child));
text = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (item->details->child));
if (text != NULL)
{

View file

@ -103,7 +103,7 @@ nautilus_string_picker_initialize (NautilusStringPicker *string_picker)
gtk_box_set_homogeneous (GTK_BOX (string_picker), FALSE);
gtk_box_set_spacing (GTK_BOX (string_picker), STRING_PICKER_SPACING);
string_picker->detail->string_list = NULL;
string_picker->detail->string_list = nautilus_string_list_new ();
string_picker->detail->menu = NULL;
string_picker->detail->option_menu = gtk_option_menu_new ();
@ -127,9 +127,7 @@ nautilus_string_picker_destroy (GtkObject* object)
string_picker = NAUTILUS_STRING_PICKER (object);
if (string_picker->detail->string_list != NULL) {
nautilus_string_list_free (string_picker->detail->string_list);
}
nautilus_string_list_free (string_picker->detail->string_list);
g_free (string_picker->detail);
@ -183,40 +181,52 @@ nautilus_string_picker_set_string_list (NautilusStringPicker *string_picker,
g_return_if_fail (string_picker != NULL);
g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
string_picker->detail->string_list = nautilus_string_list_new_from_string_list (string_list);
nautilus_string_list_assign_from_string_list (string_picker->detail->string_list, string_list);
/* Kill the old menu if alive */
if (string_picker->detail->menu != NULL) {
gtk_option_menu_remove_menu (GTK_OPTION_MENU (string_picker->detail->option_menu));
gtk_widget_destroy (string_picker->detail->menu);
/* The widget gets unrefed in the above call */
string_picker->detail->menu = NULL;
}
/* Make a new menu */
string_picker->detail->menu = gtk_menu_new ();
if (nautilus_string_list_get_length (string_picker->detail->string_list) > 0) {
for (i = 0; i < nautilus_string_list_get_length (string_picker->detail->string_list); i++) {
GtkWidget *menu_item;
char *item_label = nautilus_string_list_nth (string_picker->detail->string_list, i);
g_assert (item_label != NULL);
menu_item = gtk_menu_item_new_with_label (item_label);
g_free (item_label);
for (i = 0; i < nautilus_string_list_get_length (string_picker->detail->string_list); i++) {
GtkWidget *menu_item;
char *item_label = nautilus_string_list_nth (string_picker->detail->string_list, i);
g_assert (item_label != NULL);
/* Save the index so we can later use it to retrieve the nth label from the list */
gtk_object_set_data (GTK_OBJECT (menu_item), "index", GINT_TO_POINTER (i));
gtk_signal_connect (GTK_OBJECT (menu_item),
"activate",
GTK_SIGNAL_FUNC (option_menu_activate_callback),
string_picker);
gtk_widget_show (menu_item);
gtk_menu_append (GTK_MENU (string_picker->detail->menu), menu_item);
}
menu_item = gtk_menu_item_new_with_label (item_label);
g_free (item_label);
/* Save the index so we can later use it to retrieve the nth label from the list */
gtk_object_set_data (GTK_OBJECT (menu_item), "index", GINT_TO_POINTER (i));
gtk_signal_connect (GTK_OBJECT (menu_item),
"activate",
GTK_SIGNAL_FUNC (option_menu_activate_callback),
string_picker);
gtk_widget_show (menu_item);
gtk_menu_append (GTK_MENU (string_picker->detail->menu), menu_item);
}
/* Allow the string picker to be sensitive only if there is a choice */
if (nautilus_string_list_get_length (string_picker->detail->string_list) > 1) {
gtk_widget_set_sensitive (GTK_WIDGET (string_picker), TRUE);
}
else {
gtk_widget_set_sensitive (GTK_WIDGET (string_picker), FALSE);
}
/* Attatch the menu to the option button */
gtk_option_menu_set_menu (GTK_OPTION_MENU (string_picker->detail->option_menu), string_picker->detail->menu);
}
@ -233,9 +243,7 @@ nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picke
g_return_val_if_fail (string_picker != NULL, NULL);
g_return_val_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker), NULL);
return (string_picker->detail->string_list != NULL) ?
nautilus_string_list_new_from_string_list (string_picker->detail->string_list) :
NULL;
return nautilus_string_list_new_from_string_list (string_picker->detail->string_list);
}
/* FIXME bugzilla.eazel.com 1556:
@ -243,13 +251,13 @@ nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picke
*/
/**
* nautilus_string_picker_get_text
* nautilus_string_picker_get_selected_string
* @string_picker: A NautilusStringPicker
*
* Returns: A copy of the currently selected text. Need to g_free() it.
*/
char *
nautilus_string_picker_get_text (NautilusStringPicker *string_picker)
nautilus_string_picker_get_selected_string (NautilusStringPicker *string_picker)
{
gint item_index;
GtkWidget *option_menu;
@ -268,21 +276,18 @@ nautilus_string_picker_get_text (NautilusStringPicker *string_picker)
}
/**
* nautilus_string_picker_set_text
* nautilus_string_picker_set_selected_string
* @string_picker: A NautilusStringPicker
*
* Set the active item corresponding to the given text.
*/
void
nautilus_string_picker_set_text (NautilusStringPicker *string_picker,
const char *text)
nautilus_string_picker_set_selected_string (NautilusStringPicker *string_picker,
const char *text)
{
gint item_index;
g_return_if_fail (string_picker != NULL);
g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
g_return_if_fail (string_picker->detail->string_list != NULL);
g_return_if_fail (nautilus_string_list_contains (string_picker->detail->string_list, text));
item_index = nautilus_string_list_get_index_for_string (string_picker->detail->string_list, text);
@ -290,3 +295,19 @@ nautilus_string_picker_set_text (NautilusStringPicker *string_picker,
gtk_option_menu_set_history (GTK_OPTION_MENU (string_picker->detail->option_menu), item_index);
}
/* Add a new string to the picker. */
void
nautilus_string_picker_insert_string (NautilusStringPicker *string_picker,
const char *string)
{
NautilusStringList *new_string_list;
g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
new_string_list = nautilus_string_list_new_from_string_list (string_picker->detail->string_list);
nautilus_string_list_insert (new_string_list, string);
nautilus_string_picker_set_string_list (string_picker, new_string_list);
nautilus_string_list_free (new_string_list);
}

View file

@ -60,22 +60,25 @@ struct _NautilusStringPickerClass
NautilusCaptionClass parent_class;
};
GtkType nautilus_string_picker_get_type (void);
GtkWidget* nautilus_string_picker_new (void);
GtkType nautilus_string_picker_get_type (void);
GtkWidget* nautilus_string_picker_new (void);
/* Set the list of strings. */
void nautilus_string_picker_set_string_list (NautilusStringPicker *string_picker,
const NautilusStringList *string_list);
void nautilus_string_picker_set_string_list (NautilusStringPicker *string_picker,
const NautilusStringList *string_list);
/* Access a copy of the list of strings. */
NautilusStringList *nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picker);
NautilusStringList *nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picker);
/* Entry text accesor. */
char * nautilus_string_picker_get_text (NautilusStringPicker *string_picker);
/* Get the selected string. Resulting string needs to be freed with g_free(). */
char * nautilus_string_picker_get_selected_string (NautilusStringPicker *string_picker);
/* Entry text mutator. */
void nautilus_string_picker_set_text (NautilusStringPicker *string_picker,
const char *text);
/* Set the selected string. The internal string list needs to contain the 'string'. */
void nautilus_string_picker_set_selected_string (NautilusStringPicker *string_picker,
const char *string);
/* Add a new string to the picker. */
void nautilus_string_picker_insert_string (NautilusStringPicker *string_picker,
const char *string);
BEGIN_GNOME_DECLS

View file

@ -45,12 +45,6 @@ enum
ARG_TITLE_STRING
};
enum
{
ACTIVATE,
LAST_SIGNAL
};
static const guint PREFERENCES_ITEM_TITLE_SPACING = 4;
static const guint PREFERENCES_ITEM_FRAME_BORDER_WIDTH = 6;
static const gint PREFERENCES_ITEM_UNDEFINED_ITEM = -1;
@ -488,7 +482,7 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
g_assert (current_value != NULL);
g_assert (nautilus_string_list_contains (font_list, current_value));
nautilus_string_picker_set_text (NAUTILUS_STRING_PICKER (item->details->child), current_value);
nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (item->details->child), current_value);
g_free (current_value);
@ -612,7 +606,7 @@ preferences_item_create_theme (NautilusPreferencesItem *item,
g_assert (current_value != NULL);
g_assert (nautilus_string_list_contains (theme_list, current_value));
nautilus_string_picker_set_text (NAUTILUS_STRING_PICKER (item->details->child), current_value);
nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (item->details->child), current_value);
g_free (current_value);
@ -694,7 +688,7 @@ text_item_changed_callback (GtkWidget *button, gpointer user_data)
g_assert (item->details->child != NULL);
g_assert (NAUTILUS_IS_STRING_PICKER (item->details->child));
text = nautilus_string_picker_get_text (NAUTILUS_STRING_PICKER (item->details->child));
text = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (item->details->child));
if (text != NULL)
{

View file

@ -103,7 +103,7 @@ nautilus_string_picker_initialize (NautilusStringPicker *string_picker)
gtk_box_set_homogeneous (GTK_BOX (string_picker), FALSE);
gtk_box_set_spacing (GTK_BOX (string_picker), STRING_PICKER_SPACING);
string_picker->detail->string_list = NULL;
string_picker->detail->string_list = nautilus_string_list_new ();
string_picker->detail->menu = NULL;
string_picker->detail->option_menu = gtk_option_menu_new ();
@ -127,9 +127,7 @@ nautilus_string_picker_destroy (GtkObject* object)
string_picker = NAUTILUS_STRING_PICKER (object);
if (string_picker->detail->string_list != NULL) {
nautilus_string_list_free (string_picker->detail->string_list);
}
nautilus_string_list_free (string_picker->detail->string_list);
g_free (string_picker->detail);
@ -183,40 +181,52 @@ nautilus_string_picker_set_string_list (NautilusStringPicker *string_picker,
g_return_if_fail (string_picker != NULL);
g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
string_picker->detail->string_list = nautilus_string_list_new_from_string_list (string_list);
nautilus_string_list_assign_from_string_list (string_picker->detail->string_list, string_list);
/* Kill the old menu if alive */
if (string_picker->detail->menu != NULL) {
gtk_option_menu_remove_menu (GTK_OPTION_MENU (string_picker->detail->option_menu));
gtk_widget_destroy (string_picker->detail->menu);
/* The widget gets unrefed in the above call */
string_picker->detail->menu = NULL;
}
/* Make a new menu */
string_picker->detail->menu = gtk_menu_new ();
if (nautilus_string_list_get_length (string_picker->detail->string_list) > 0) {
for (i = 0; i < nautilus_string_list_get_length (string_picker->detail->string_list); i++) {
GtkWidget *menu_item;
char *item_label = nautilus_string_list_nth (string_picker->detail->string_list, i);
g_assert (item_label != NULL);
menu_item = gtk_menu_item_new_with_label (item_label);
g_free (item_label);
for (i = 0; i < nautilus_string_list_get_length (string_picker->detail->string_list); i++) {
GtkWidget *menu_item;
char *item_label = nautilus_string_list_nth (string_picker->detail->string_list, i);
g_assert (item_label != NULL);
/* Save the index so we can later use it to retrieve the nth label from the list */
gtk_object_set_data (GTK_OBJECT (menu_item), "index", GINT_TO_POINTER (i));
gtk_signal_connect (GTK_OBJECT (menu_item),
"activate",
GTK_SIGNAL_FUNC (option_menu_activate_callback),
string_picker);
gtk_widget_show (menu_item);
gtk_menu_append (GTK_MENU (string_picker->detail->menu), menu_item);
}
menu_item = gtk_menu_item_new_with_label (item_label);
g_free (item_label);
/* Save the index so we can later use it to retrieve the nth label from the list */
gtk_object_set_data (GTK_OBJECT (menu_item), "index", GINT_TO_POINTER (i));
gtk_signal_connect (GTK_OBJECT (menu_item),
"activate",
GTK_SIGNAL_FUNC (option_menu_activate_callback),
string_picker);
gtk_widget_show (menu_item);
gtk_menu_append (GTK_MENU (string_picker->detail->menu), menu_item);
}
/* Allow the string picker to be sensitive only if there is a choice */
if (nautilus_string_list_get_length (string_picker->detail->string_list) > 1) {
gtk_widget_set_sensitive (GTK_WIDGET (string_picker), TRUE);
}
else {
gtk_widget_set_sensitive (GTK_WIDGET (string_picker), FALSE);
}
/* Attatch the menu to the option button */
gtk_option_menu_set_menu (GTK_OPTION_MENU (string_picker->detail->option_menu), string_picker->detail->menu);
}
@ -233,9 +243,7 @@ nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picke
g_return_val_if_fail (string_picker != NULL, NULL);
g_return_val_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker), NULL);
return (string_picker->detail->string_list != NULL) ?
nautilus_string_list_new_from_string_list (string_picker->detail->string_list) :
NULL;
return nautilus_string_list_new_from_string_list (string_picker->detail->string_list);
}
/* FIXME bugzilla.eazel.com 1556:
@ -243,13 +251,13 @@ nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picke
*/
/**
* nautilus_string_picker_get_text
* nautilus_string_picker_get_selected_string
* @string_picker: A NautilusStringPicker
*
* Returns: A copy of the currently selected text. Need to g_free() it.
*/
char *
nautilus_string_picker_get_text (NautilusStringPicker *string_picker)
nautilus_string_picker_get_selected_string (NautilusStringPicker *string_picker)
{
gint item_index;
GtkWidget *option_menu;
@ -268,21 +276,18 @@ nautilus_string_picker_get_text (NautilusStringPicker *string_picker)
}
/**
* nautilus_string_picker_set_text
* nautilus_string_picker_set_selected_string
* @string_picker: A NautilusStringPicker
*
* Set the active item corresponding to the given text.
*/
void
nautilus_string_picker_set_text (NautilusStringPicker *string_picker,
const char *text)
nautilus_string_picker_set_selected_string (NautilusStringPicker *string_picker,
const char *text)
{
gint item_index;
g_return_if_fail (string_picker != NULL);
g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
g_return_if_fail (string_picker->detail->string_list != NULL);
g_return_if_fail (nautilus_string_list_contains (string_picker->detail->string_list, text));
item_index = nautilus_string_list_get_index_for_string (string_picker->detail->string_list, text);
@ -290,3 +295,19 @@ nautilus_string_picker_set_text (NautilusStringPicker *string_picker,
gtk_option_menu_set_history (GTK_OPTION_MENU (string_picker->detail->option_menu), item_index);
}
/* Add a new string to the picker. */
void
nautilus_string_picker_insert_string (NautilusStringPicker *string_picker,
const char *string)
{
NautilusStringList *new_string_list;
g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
new_string_list = nautilus_string_list_new_from_string_list (string_picker->detail->string_list);
nautilus_string_list_insert (new_string_list, string);
nautilus_string_picker_set_string_list (string_picker, new_string_list);
nautilus_string_list_free (new_string_list);
}

View file

@ -60,22 +60,25 @@ struct _NautilusStringPickerClass
NautilusCaptionClass parent_class;
};
GtkType nautilus_string_picker_get_type (void);
GtkWidget* nautilus_string_picker_new (void);
GtkType nautilus_string_picker_get_type (void);
GtkWidget* nautilus_string_picker_new (void);
/* Set the list of strings. */
void nautilus_string_picker_set_string_list (NautilusStringPicker *string_picker,
const NautilusStringList *string_list);
void nautilus_string_picker_set_string_list (NautilusStringPicker *string_picker,
const NautilusStringList *string_list);
/* Access a copy of the list of strings. */
NautilusStringList *nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picker);
NautilusStringList *nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picker);
/* Entry text accesor. */
char * nautilus_string_picker_get_text (NautilusStringPicker *string_picker);
/* Get the selected string. Resulting string needs to be freed with g_free(). */
char * nautilus_string_picker_get_selected_string (NautilusStringPicker *string_picker);
/* Entry text mutator. */
void nautilus_string_picker_set_text (NautilusStringPicker *string_picker,
const char *text);
/* Set the selected string. The internal string list needs to contain the 'string'. */
void nautilus_string_picker_set_selected_string (NautilusStringPicker *string_picker,
const char *string);
/* Add a new string to the picker. */
void nautilus_string_picker_insert_string (NautilusStringPicker *string_picker,
const char *string);
BEGIN_GNOME_DECLS

View file

@ -225,7 +225,7 @@ test_string_picker (void)
GTK_SIGNAL_FUNC (string_picker_changed_callback),
(gpointer) NULL);
nautilus_string_picker_set_text (NAUTILUS_STRING_PICKER (picker), "Fixed");
nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (picker), "Fixed");
gtk_widget_show_all (window);
}
@ -262,7 +262,7 @@ string_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
g_assert (string_picker != NULL);
g_assert (NAUTILUS_IS_STRING_PICKER (string_picker));
text = nautilus_string_picker_get_text (NAUTILUS_STRING_PICKER (string_picker));
text = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (string_picker));
g_print ("string_picker_changed_callback(%s)\n", text);