From 48fddc20b8d56a28c51e00fcb722b16001728ec4 Mon Sep 17 00:00:00 2001 From: tavmjong-free Date: Sat, 24 Apr 2010 11:13:24 +0200 Subject: [PATCH] Add alt-x shortcut to new text toolbar. --- src/ink-comboboxentry-action.cpp | 25 +++++++++++++++++++++---- src/ink-comboboxentry-action.h | 17 ++++++++++------- src/widgets/toolbox.cpp | 13 +++++++------ 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp index 68cbe37b0..85e9378c8 100644 --- a/src/ink-comboboxentry-action.cpp +++ b/src/ink-comboboxentry-action.cpp @@ -34,7 +34,7 @@ static GtkWidget* create_tool_item( GtkAction* action ); static GtkWidget* create_menu_item( GtkAction* action ); // Internal -static gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, gchar* target_text ); +static gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text ); // Callbacks static void combo_box_changed_cb( GtkComboBoxEntry* widget, gpointer data ); @@ -247,6 +247,7 @@ static void ink_comboboxentry_action_init (Ink_ComboBoxEntry_Action *action) action->entry_completion = NULL; action->popup = false; action->warning = NULL; + action->altx_name = NULL; } GType ink_comboboxentry_action_get_type () @@ -344,6 +345,11 @@ GtkWidget* create_tool_item( GtkAction* action ) ink_comboboxentry_action_popup_enable( ink_comboboxentry_action ); } + // Add altx_name if required + if( ink_comboboxentry_action->altx_name ) { + g_object_set_data( G_OBJECT( child ), ink_comboboxentry_action->altx_name, ink_comboboxentry_action->entry ); + } + // Add signal for GtkEntry to check if finished typing. g_signal_connect( G_OBJECT(child), "activate", G_CALLBACK(entry_activate_cb), action ); @@ -391,7 +397,7 @@ gchar* ink_comboboxentry_action_get_active_text( Ink_ComboBoxEntry_Action* actio return text; } -gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink_comboboxentry_action, gchar* text ) { +gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink_comboboxentry_action, const gchar* text ) { g_free( ink_comboboxentry_action->text ); ink_comboboxentry_action->text = g_strdup( text ); @@ -479,7 +485,7 @@ void ink_comboboxentry_action_popup_disable( Ink_ComboBoxEntry_Action* action ) } } -void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, gchar* warning ) { +void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, const gchar* warning ) { g_free( action->warning ); action->warning = g_strdup( warning ); @@ -494,10 +500,21 @@ void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, } } +void ink_comboboxentry_action_set_altx_name( Ink_ComboBoxEntry_Action* action, const gchar* altx_name ) { + + g_free( action->altx_name ); + action->altx_name = g_strdup( altx_name ); + + // Widget may not have been created.... + if( action->entry ) { + g_object_set_data( G_OBJECT(action->entry), action->altx_name, action->entry ); + } +} + // Internal --------------------------------------------------- // Return row of active text or -1 if not found. -gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, gchar* target_text ) { +gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text ) { // Check if text in list gint row = 0; diff --git a/src/ink-comboboxentry-action.h b/src/ink-comboboxentry-action.h index 433eb2fdc..b1228f749 100644 --- a/src/ink-comboboxentry-action.h +++ b/src/ink-comboboxentry-action.h @@ -49,11 +49,12 @@ struct _Ink_ComboBoxEntry_Action { gpointer cell_data_func; // drop-down menu format - gint active; // Index of active menu item (-1 if not in list). - gchar *text; // Text of active menu item or entry box. - gint width; // Width of GtkComboBoxEntry in characters. - gboolean popup; // Do we pop-up an entry-completion dialog? - gchar *warning; // Text for warning that entry isn't in list. + gint active; // Index of active menu item (-1 if not in list). + gchar *text; // Text of active menu item or entry box. + gint width; // Width of GtkComboBoxEntry in characters. + gboolean popup; // Do we pop-up an entry-completion dialog? + gchar *warning; // Text for warning that entry isn't in list. + gchar *altx_name; // Target for Alt-X keyboard shortcut. }; @@ -74,13 +75,15 @@ GtkTreeModel *ink_comboboxentry_action_get_model( Ink_ComboBoxEntry_Action* GtkComboBoxEntry *ink_comboboxentry_action_get_comboboxentry( Ink_ComboBoxEntry_Action* action ); gchar* ink_comboboxentry_action_get_active_text( Ink_ComboBoxEntry_Action* action ); -gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* action, gchar* text ); +gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* action, const gchar* text ); void ink_comboboxentry_action_set_width( Ink_ComboBoxEntry_Action* action, gint width ); void ink_comboboxentry_action_popup_enable( Ink_ComboBoxEntry_Action* action ); void ink_comboboxentry_action_popup_disable( Ink_ComboBoxEntry_Action* action ); -void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, gchar* warning ); +void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, const gchar* warning ); + +void ink_comboboxentry_action_set_altx_name( Ink_ComboBoxEntry_Action* action, const gchar* altx_name ); #endif /* SEEN_INK_COMBOBOXENTRY_ACTION */ diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 826fabb06..493d1ecd7 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -7179,6 +7179,7 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions ink_comboboxentry_action_popup_enable( act ); // Enable entry completion gchar *const warning = _("Font not found on system"); ink_comboboxentry_action_set_warning( act, warning ); // Show icon with tooltip if missing font + ink_comboboxentry_action_set_altx_name( act, "altx-text" ); // Set Alt-X keyboard shortcut g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontfamily_value_changed), holder ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); g_object_set_data( holder, "TextFontFamilyAction", act ); @@ -7349,8 +7350,8 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions GTK_WIDGET(desktop->canvas), /* focusTarget */ NULL, /* unit selector */ holder, /* dataKludge */ - FALSE, /* altx? */ - NULL, /* altx_mark? */ + FALSE, /* set alt-x keyboard shortcut? */ + NULL, /* altx_mark */ 0.0, 10.0, 0.01, 0.10, /* lower, upper, step (arrow up/down), page up/down */ labels, values, G_N_ELEMENTS(labels), /* drop down menu */ sp_text_lineheight_value_changed, /* callback */ @@ -7379,8 +7380,8 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions GTK_WIDGET(desktop->canvas), /* focusTarget */ NULL, /* unit selector */ holder, /* dataKludge */ - FALSE, /* altx? */ - NULL, /* altx_mark? */ + FALSE, /* set alt-x keyboard shortcut? */ + NULL, /* altx_mark */ -100.0, 100.0, 0.01, 0.10, /* lower, upper, step (arrow up/down), page up/down */ labels, values, G_N_ELEMENTS(labels), /* drop down menu */ sp_text_wordspacing_value_changed, /* callback */ @@ -7409,8 +7410,8 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions GTK_WIDGET(desktop->canvas), /* focusTarget */ NULL, /* unit selector */ holder, /* dataKludge */ - FALSE, /* altx? */ - NULL, /* altx_mark? */ + FALSE, /* set alt-x keyboard shortcut? */ + NULL, /* altx_mark */ -100.0, 100.0, 0.01, 0.10, /* lower, upper, step (arrow up/down), page up/down */ labels, values, G_N_ELEMENTS(labels), /* drop down menu */ sp_text_letterspacing_value_changed, /* callback */ -- 2.30.2