From: tavmjong-free Date: Thu, 13 May 2010 08:37:58 +0000 (+0200) Subject: Add ability to set icons to insensitive. Used to disable "Justify" X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=dfa8cef26133b0e0e3170caa5d93c21d80cf4580;p=inkscape.git Add ability to set icons to insensitive. Used to disable "Justify" button for non-flowed text in text-tool toolbar. --- diff --git a/src/ege-select-one-action.cpp b/src/ege-select-one-action.cpp index ebc7ea26d..32c1ef9b4 100644 --- a/src/ege-select-one-action.cpp +++ b/src/ege-select-one-action.cpp @@ -67,6 +67,7 @@ static void ege_select_one_action_set_property( GObject* obj, guint propId, cons static gint find_text_index(EgeSelectOneAction *act, gchar const* text); static void commit_pending_change(EgeSelectOneAction *act); static void resync_active( EgeSelectOneAction* act, gint active, gboolean override ); +static void resync_sensitive( EgeSelectOneAction* act ); static void combo_entry_changed_cb( GtkEntry* widget, gpointer user_data ); static gboolean combo_entry_focus_lost_cb( GtkWidget *widget, GdkEventFocus *event, gpointer data ); static void combo_changed_cb( GtkComboBox* widget, gpointer user_data ); @@ -105,6 +106,7 @@ struct _EgeSelectOneActionPrivate gint labelColumn; gint iconColumn; gint tooltipColumn; + gint sensitiveColumn; gint appearanceMode; gint selectionMode; gint iconSize; @@ -125,6 +127,7 @@ enum { PROP_LABEL_COLUMN, PROP_ICON_COLUMN, PROP_TOOLTIP_COLUMN, + PROP_SENSITIVE_COLUMN, PROP_ICON_PROP, PROP_ICON_SIZE, PROP_APPEARANCE, @@ -213,6 +216,14 @@ void ege_select_one_action_class_init( EgeSelectOneActionClass* klass ) -1, G_MAXINT, -1, (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + g_object_class_install_property( objClass, + PROP_SENSITIVE_COLUMN, + g_param_spec_int( "sensitive-column", + "Sensitive Column", + "The column of the model that holds sensitive state", + -1, G_MAXINT, -1, + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + g_object_class_install_property( objClass, PROP_ICON_PROP, g_param_spec_string( "icon-property", @@ -265,6 +276,7 @@ void ege_select_one_action_init( EgeSelectOneAction* action ) action->private_data->labelColumn = 0; action->private_data->iconColumn = -1; action->private_data->tooltipColumn = -1; + action->private_data->sensitiveColumn = -1; action->private_data->appearanceMode = APPEARANCE_NONE; action->private_data->selectionMode = SELECTION_CLOSED; action->private_data->radioActionType = 0; @@ -347,6 +359,15 @@ void ege_select_one_action_set_active( EgeSelectOneAction* action, gint val ) g_object_set( G_OBJECT(action), "active", val, NULL ); } +void ege_select_one_action_update_sensitive( EgeSelectOneAction* action ) +{ + if( action->private_data->sensitiveColumn < 0 ) { + g_warning( "ege_select_one_action: Attempt to update sensitivity of item without sensitive column\n" ); + return; + } + resync_sensitive( action ); +} + gint ege_select_one_action_get_label_column( EgeSelectOneAction* action ) { g_return_val_if_fail( IS_EGE_SELECT_ONE_ACTION(action), 0 ); @@ -391,6 +412,17 @@ void ege_select_one_action_set_tooltip_column( EgeSelectOneAction* action, gint g_object_set( G_OBJECT(action), "tooltip-column", col, NULL ); } +gint ege_select_one_action_get_sensitive_column( EgeSelectOneAction* action ) +{ + g_return_val_if_fail( IS_EGE_SELECT_ONE_ACTION(action), 0 ); + return action->private_data->sensitiveColumn; +} + +void ege_select_one_action_set_sensitive_column( EgeSelectOneAction* action, gint col ) +{ + g_object_set( G_OBJECT(action), "sensitive-column", col, NULL ); +} + void ege_select_one_action_set_appearance( EgeSelectOneAction* action, gchar const* val ) { g_object_set( G_OBJECT(action), "appearance", val, NULL ); @@ -425,6 +457,10 @@ void ege_select_one_action_get_property( GObject* obj, guint propId, GValue* val g_value_set_int( value, action->private_data->tooltipColumn ); break; + case PROP_SENSITIVE_COLUMN: + g_value_set_int( value, action->private_data->sensitiveColumn ); + break; + case PROP_ICON_PROP: g_value_set_string( value, action->private_data->iconProperty ); break; @@ -480,6 +516,12 @@ void ege_select_one_action_set_property( GObject* obj, guint propId, const GValu } break; + case PROP_SENSITIVE_COLUMN: + { + action->private_data->sensitiveColumn = g_value_get_int( value ); + } + break; + case PROP_ICON_PROP: { gchar* tmp = action->private_data->iconProperty; @@ -634,6 +676,7 @@ GtkWidget* create_tool_item( GtkAction* action ) gchar* str = 0; gchar* tip = 0; gchar* iconId = 0; + gboolean sens = true; /* gint size = 0; */ @@ -650,6 +693,11 @@ GtkWidget* create_tool_item( GtkAction* action ) act->private_data->tooltipColumn, &tip, -1 ); } + if ( act->private_data->sensitiveColumn >= 0 ) { + gtk_tree_model_get( act->private_data->model, &iter, + act->private_data->sensitiveColumn, &sens, + -1 ); + } if ( act->private_data->radioActionType ) { void* obj = g_object_new( act->private_data->radioActionType, @@ -678,6 +726,10 @@ GtkWidget* create_tool_item( GtkAction* action ) ract = gtk_radio_action_new( "Name 1", str, tip, iconId, index ); } + if ( act->private_data->sensitiveColumn >= 0 ) { + gtk_action_set_sensitive( GTK_ACTION(ract), sens ); + } + gtk_radio_action_set_group( ract, group ); group = gtk_radio_action_get_group( ract ); @@ -855,6 +907,71 @@ void resync_active( EgeSelectOneAction* act, gint active, gboolean override ) } } +void resync_sensitive( EgeSelectOneAction* act ) +{ + GSList* proxies = gtk_action_get_proxies( GTK_ACTION(act) ); + while ( proxies ) { + if ( GTK_IS_TOOL_ITEM(proxies->data) ) { + /* Search for the things we built up in create_tool_item() */ + GList* children = gtk_container_get_children( GTK_CONTAINER(proxies->data) ); + if ( children && children->data ) { + gpointer combodata = g_object_get_data( G_OBJECT(children->data), "ege-combo-box" ); + if (!combodata && GTK_IS_ALIGNMENT(children->data)) { + GList *other = gtk_container_get_children( GTK_CONTAINER(children->data) ); + combodata = g_object_get_data( G_OBJECT(other->data), "ege-combo-box" ); + } + if ( GTK_IS_COMBO_BOX(combodata) ) { + /* Not implemented */ + } else if ( GTK_IS_HBOX(children->data) ) { + gpointer data = g_object_get_data( G_OBJECT(children->data), "ege-proxy_action-group" ); + if ( data ) { + GSList* group = (GSList*)data; + // List is backwards in group as compared to GtkTreeModel, we better do matching. + while ( group ) { + GtkRadioAction* ract = GTK_RADIO_ACTION(group->data); + const gchar* label = gtk_action_get_label( GTK_ACTION( ract ) ); + + // Search for matching GtkTreeModel entry + GtkTreeIter iter; + gboolean valid; + valid = gtk_tree_model_get_iter_first( act->private_data->model, &iter ); + gboolean sens = true; + + while( valid ) { + + gchar* str = 0; + gtk_tree_model_get( act->private_data->model, &iter, + act->private_data->labelColumn, &str, + -1 ); + + if( strcmp( label, str ) == 0 ) { + gtk_tree_model_get( act->private_data->model, &iter, + act->private_data->sensitiveColumn, &sens, + -1 ); + break; + } + g_free( str ); + + valid = gtk_tree_model_iter_next( act->private_data->model, &iter ); + } + + gtk_action_set_sensitive( GTK_ACTION(ract), sens ); + + group = g_slist_next(group); + } + } + } + } + } else if ( GTK_IS_MENU_ITEM(proxies->data) ) { + /* Not implemented */ + } + + proxies = g_slist_next( proxies ); + } + + g_signal_emit( G_OBJECT(act), signals[CHANGED], 0); +} + void combo_changed_cb( GtkComboBox* widget, gpointer user_data ) { EgeSelectOneAction* act = EGE_SELECT_ONE_ACTION(user_data); diff --git a/src/ege-select-one-action.h b/src/ege-select-one-action.h index aa20d55a7..36943b978 100644 --- a/src/ege-select-one-action.h +++ b/src/ege-select-one-action.h @@ -145,6 +145,13 @@ void ege_select_one_action_set_active_text( EgeSelectOneAction* action, gchar co */ void ege_select_one_action_set_active( EgeSelectOneAction* action, gint val ); +//void ege_select_one_action_set_sensitive( EgeSelectOneAction *action, gint val, gboolean sensitive ); + +/** + * Update sensitive parameters. + * @param action The action to update. + */ +void ege_select_one_action_update_sensitive( EgeSelectOneAction *action ); /** * Returns the column used for the display label. @@ -198,6 +205,22 @@ gint ege_select_one_action_get_tooltip_column( EgeSelectOneAction* action ); void ege_select_one_action_set_tooltip_column( EgeSelectOneAction* action, gint col ); +/** + * Returns the column used for tracking sensitivity. + * + * @param action The action to fetch the sensitive column for. + */ +gint ege_select_one_action_get_sensitive_column( EgeSelectOneAction* action ); + +/** + * Sets the column used for sensitivity (if any). + * + * @param action The action to set the sensitive column for. + * @param col column to use. + */ +void ege_select_one_action_set_sensitive_column( EgeSelectOneAction* action, gint col ); + + /** * Sets a hint to be used in determining the display form. * This is the XForms style 'appearance' hint: "full", "compact", "minimal". diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index de97e9ea4..8aed18d7b 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -7033,31 +7033,37 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(textItalicAction), italicSet ); + + EgeSelectOneAction* textAlignAction = EGE_SELECT_ONE_ACTION( g_object_get_data( tbl, "TextAlignAction" ) ); // Alignment // Note: SVG 1.1 doesn't include text-align, SVG 1.2 Tiny doesn't include text-align="justify" // text-align="justify" was a draft SVG 1.2 item (along with flowed text). // Only flowed text can be left and right justified at the same time. // Check if we have flowed text and disable botton. - // NEED: ege_select_one_action_set_sensitve( ) - /* gboolean isFlow = false; for (GSList const *items = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); items != NULL; items = items->next) { - const gchar* id = SP_OBJECT_ID((SPItem *) items->data); - std::cout << " " << id << std::endl; + // const gchar* id = SP_OBJECT_ID((SPItem *) items->data); + // std::cout << " " << id << std::endl; if( SP_IS_FLOWTEXT(( SPItem *) items->data )) { isFlow = true; - std::cout << " Found flowed text" << std::endl; + // std::cout << " Found flowed text" << std::endl; break; } } - if( isFlow ) { - // enable justify button - } else { - // disable justify button - } - */ + + // The GtkTreeModel class doesn't have a set function so we can't + // simply add an ege_select_one_action_set_sensitive method! + // We must set values directly with the GtkListStore and then + // ask that the GtkAction update the sensitive parameters. + GtkListStore * model = GTK_LIST_STORE( ege_select_one_action_get_model( textAlignAction ) ); + GtkTreePath * path = gtk_tree_path_new_from_string("3"); // Justify entry + GtkTreeIter iter; + gtk_tree_model_get_iter( GTK_TREE_MODEL (model), &iter, path ); + gtk_list_store_set( model, &iter, /* column */ 3, isFlow, -1 ); + ege_select_one_action_update_sensitive( textAlignAction ); + // ege_select_one_action_set_sensitive( textAlignAction, 3, isFlow ); int activeButton = 0; if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) @@ -7068,7 +7074,6 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) activeButton = 1; if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) activeButton = 2; } - EgeSelectOneAction* textAlignAction = EGE_SELECT_ONE_ACTION( g_object_get_data( tbl, "TextAlignAction" ) ); ege_select_one_action_set_active( textAlignAction, activeButton ); @@ -7258,7 +7263,7 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions /* Alignment */ { - GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); + GtkListStore* model = gtk_list_store_new( 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN ); GtkTreeIter iter; @@ -7267,6 +7272,7 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions 0, _("Align left"), 1, _("Align left"), 2, GTK_STOCK_JUSTIFY_LEFT, + 3, true, -1 ); gtk_list_store_append( model, &iter ); @@ -7274,6 +7280,7 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions 0, _("Align center"), 1, _("Align center"), 2, GTK_STOCK_JUSTIFY_CENTER, + 3, true, -1 ); gtk_list_store_append( model, &iter ); @@ -7281,6 +7288,7 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions 0, _("Align right"), 1, _("Align right"), 2, GTK_STOCK_JUSTIFY_RIGHT, + 3, true, -1 ); gtk_list_store_append( model, &iter ); @@ -7288,6 +7296,7 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions 0, _("Justify"), 1, _("Justify - Only flowed text"), 2, GTK_STOCK_JUSTIFY_FILL, + 3, false, -1 ); EgeSelectOneAction* act = ege_select_one_action_new( "TextAlignAction", // Name @@ -7305,7 +7314,7 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions ege_select_one_action_set_icon_column( act, 2 ); ege_select_one_action_set_icon_size( act, secondarySize ); ege_select_one_action_set_tooltip_column( act, 1 ); - + ege_select_one_action_set_sensitive_column( act, 3 ); gint mode = prefs->getInt("/tools/text/align_mode", 0); ege_select_one_action_set_active( act, mode ); g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_text_align_mode_changed), holder );