From 96d27a1a233aee3fced9a80c22a60dddc1248c58 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Mon, 19 Apr 2010 09:01:16 -0700 Subject: [PATCH] Added settor method for custom/non-model text --- src/ege-select-one-action.cpp | 27 ++++++++++++++++++++++++--- src/ege-select-one-action.h | 8 ++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/ege-select-one-action.cpp b/src/ege-select-one-action.cpp index 587555c8b..bfbd3736a 100644 --- a/src/ege-select-one-action.cpp +++ b/src/ege-select-one-action.cpp @@ -324,6 +324,22 @@ gchar *ege_select_one_action_get_active_text( EgeSelectOneAction* action ) return str; } +void ege_select_one_action_set_active_text( EgeSelectOneAction* action, gchar const *text ) +{ + g_return_if_fail( IS_EGE_SELECT_ONE_ACTION(action) ); + + if (action->private_data->activeText) { + g_free( action->private_data->activeText ); + } + action->private_data->activeText = g_strdup(text); + + if (action->private_data->active != -1) { + g_object_set( G_OBJECT(action), "active", -1, NULL ); + } else { + resync_active( action, -1, TRUE ); + } +} + void ege_select_one_action_set_active( EgeSelectOneAction* action, gint val ) { g_object_set( G_OBJECT(action), "active", val, NULL ); @@ -688,14 +704,16 @@ GtkWidget* create_tool_item( GtkAction* action ) gtk_container_add( GTK_CONTAINER(item), holder ); } else { GtkCellRenderer * renderer = 0; - GtkWidget* holder = gtk_hbox_new( FALSE, 4 ); - GtkWidget* normal = (act->private_data->selectionMode == SELECTION_OPEN) ? + GtkWidget *holder = gtk_hbox_new( FALSE, 4 ); + GtkEntry *entry = 0; + GtkWidget *normal = (act->private_data->selectionMode == SELECTION_OPEN) ? gtk_combo_box_entry_new_with_model( act->private_data->model, act->private_data->labelColumn ) : gtk_combo_box_new_with_model( act->private_data->model ); if ((act->private_data->selectionMode == SELECTION_OPEN)) { GtkWidget *child = gtk_bin_get_child( GTK_BIN(normal) ); if (GTK_IS_ENTRY(child)) { - gtk_entry_set_width_chars(GTK_ENTRY(child), 4); + entry = GTK_ENTRY(child); + gtk_entry_set_width_chars(entry, 4); g_signal_connect( G_OBJECT(child), "activate", G_CALLBACK(combo_entry_changed_cb), act ); g_signal_connect( G_OBJECT(child), "focus-out-event", G_CALLBACK(combo_entry_focus_lost_cb), act ); } @@ -714,6 +732,9 @@ GtkWidget* create_tool_item( GtkAction* action ) } gtk_combo_box_set_active( GTK_COMBO_BOX(normal), act->private_data->active ); + if ( entry && (act->private_data->active == -1) ) { + gtk_entry_set_text( entry, act->private_data->activeText ); + } g_signal_connect( G_OBJECT(normal), "changed", G_CALLBACK(combo_changed_cb), action ); diff --git a/src/ege-select-one-action.h b/src/ege-select-one-action.h index 16f924370..aa20d55a7 100644 --- a/src/ege-select-one-action.h +++ b/src/ege-select-one-action.h @@ -129,6 +129,14 @@ gint ege_select_one_action_get_active( EgeSelectOneAction* action ); */ gchar *ege_select_one_action_get_active_text( EgeSelectOneAction* action ); +/** + * Sets the text of the currently selected item. + * + * @param action The action to fetch the text for. + * @param text the text to set. + */ +void ege_select_one_action_set_active_text( EgeSelectOneAction* action, gchar const *text ); + /** * Sets the currently selected item. * -- 2.30.2