Revision: 3712 http://geany.svn.sourceforge.net/geany/?rev=3712&view=rev Author: eht16 Date: 2009-04-17 15:30:01 +0000 (Fri, 17 Apr 2009)
Log Message: ----------- Prevent double execution of radio menu item "activate" or "toggled" signal handlers. Move 'Set Encoding' callback function into encodings.c.
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/callbacks.h trunk/src/encodings.c trunk/src/filetypes.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-04-16 17:57:29 UTC (rev 3711) +++ trunk/ChangeLog 2009-04-17 15:30:01 UTC (rev 3712) @@ -1,3 +1,11 @@ +2009-04-17 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * src/callbacks.c, src/callbacks.h, src/encodings.c, src/filetypes.c: + Prevent double execution of radio menu item "activate" or "toggled" + signal handlers. + Move 'Set Encoding' callback function into encodings.c. + + 2009-04-16 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/project.c:
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2009-04-16 17:57:29 UTC (rev 3711) +++ trunk/src/callbacks.c 2009-04-17 15:30:01 UTC (rev 3712) @@ -479,10 +479,11 @@
void -on_images_and_text2_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_images_and_text2_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { - if (ignore_toolbar_toggle) return; + if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem)) + return;
gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), GTK_TOOLBAR_BOTH); toolbar_prefs.icon_style = GTK_TOOLBAR_BOTH; @@ -490,10 +491,11 @@
void -on_images_only2_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_images_only2_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { - if (ignore_toolbar_toggle) return; + if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem)) + return;
gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), GTK_TOOLBAR_ICONS); toolbar_prefs.icon_style = GTK_TOOLBAR_ICONS; @@ -501,10 +503,11 @@
void -on_text_only2_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_text_only2_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { - if (ignore_toolbar_toggle) return; + if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem)) + return;
gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), GTK_TOOLBAR_TEXT); toolbar_prefs.icon_style = GTK_TOOLBAR_TEXT; @@ -591,10 +594,11 @@
void -on_toolbar_large_icons1_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_toolbar_large_icons1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { - if (ignore_toolbar_toggle) return; + if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem)) + return;
toolbar_prefs.icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR; gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), toolbar_prefs.icon_size); @@ -602,10 +606,11 @@
void -on_toolbar_small_icons1_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_toolbar_small_icons1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { - if (ignore_toolbar_toggle) return; + if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem)) + return;
toolbar_prefs.icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR; gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), toolbar_prefs.icon_size); @@ -613,10 +618,11 @@
void -on_very_small_icons1_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_very_small_icons1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { - if (ignore_toolbar_toggle) return; + if (ignore_toolbar_toggle || ! gtk_check_menu_item_get_active(menuitem)) + return;
toolbar_prefs.icon_size = GTK_ICON_SIZE_MENU; gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), toolbar_prefs.icon_size); @@ -772,11 +778,11 @@
void -on_crlf_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_crlf_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { GeanyDocument *doc; - if (ignore_callback) + if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem)) return; doc = document_get_current(); g_return_if_fail(doc != NULL); @@ -787,13 +793,13 @@
void -on_lf_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_lf_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { GeanyDocument *doc; - if (ignore_callback) + if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem)) return; - doc = document_get_current(); + doc = document_get_current(); g_return_if_fail(doc != NULL);
sci_convert_eols(doc->editor->sci, SC_EOL_LF); @@ -802,11 +808,11 @@
void -on_cr_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_cr_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { GeanyDocument *doc; - if (ignore_callback) + if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem)) return; doc = document_get_current(); g_return_if_fail(doc != NULL); @@ -1592,28 +1598,6 @@
void -on_encoding_change (GtkMenuItem *menuitem, - gpointer user_data) -{ - GeanyDocument *doc = document_get_current(); - guint i = GPOINTER_TO_INT(user_data); - - if (ignore_callback || doc == NULL || encodings[i].charset == NULL || - utils_str_equal(encodings[i].charset, doc->encoding)) - return; - - if (doc->readonly) - { - utils_beep(); - return; - } - document_undo_add(doc, UNDO_ENCODING, g_strdup(doc->encoding)); - - document_set_encoding(doc, encodings[i].charset); -} - - -void on_print1_activate (GtkMenuItem *menuitem, gpointer user_data) { @@ -2085,11 +2069,11 @@ }
-static void set_indent_type(GeanyIndentType type) +static void set_indent_type(GtkCheckMenuItem *menuitem, GeanyIndentType type) { GeanyDocument *doc;
- if (ignore_callback) + if (ignore_callback || ! gtk_check_menu_item_get_active(menuitem)) return;
doc = document_get_current(); @@ -2101,26 +2085,26 @@
void -on_tabs1_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_tabs1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { - set_indent_type(GEANY_INDENT_TYPE_TABS); + set_indent_type(menuitem, GEANY_INDENT_TYPE_TABS); }
void -on_spaces1_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_spaces1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { - set_indent_type(GEANY_INDENT_TYPE_SPACES); + set_indent_type(menuitem, GEANY_INDENT_TYPE_SPACES); }
void -on_tabs_and_spaces1_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_tabs_and_spaces1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data) { - set_indent_type(GEANY_INDENT_TYPE_BOTH); + set_indent_type(menuitem, GEANY_INDENT_TYPE_BOTH); }
Modified: trunk/src/callbacks.h =================================================================== --- trunk/src/callbacks.h 2009-04-16 17:57:29 UTC (rev 3711) +++ trunk/src/callbacks.h 2009-04-17 15:30:01 UTC (rev 3712) @@ -74,19 +74,19 @@
void on_close_all1_activate (GtkMenuItem *menuitem, - gpointer user_data); + gpointer user_data);
void -on_crlf_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_crlf_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
void -on_lf_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_lf_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
void -on_cr_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_cr_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
void on_replace_tabs_activate (GtkMenuItem *menuitem, @@ -102,16 +102,16 @@ gpointer user_data);
void -on_images_and_text2_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_images_and_text2_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
void -on_images_only2_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_images_only2_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
void -on_text_only2_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_text_only2_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
void on_hide_toolbar1_activate (GtkMenuItem *menuitem, @@ -322,12 +322,12 @@ gpointer user_data);
void -on_toolbar_large_icons1_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_toolbar_large_icons1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
void -on_toolbar_small_icons1_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_toolbar_small_icons1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
void on_set_file_readonly1_toggled (GtkCheckMenuItem *checkmenuitem, @@ -388,10 +388,6 @@ gpointer user_data);
void -on_encoding_change (GtkMenuItem *menuitem, - gpointer user_data); - -void on_reload_as_activate (GtkMenuItem *menuitem, gpointer user_data);
@@ -529,12 +525,12 @@ gpointer user_data);
void -on_tabs1_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_tabs1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
void -on_spaces1_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_spaces1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
void @@ -580,8 +576,8 @@ gpointer user_data);
void -on_tabs_and_spaces1_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_tabs_and_spaces1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data); void on_debug_messages1_activate (GtkMenuItem *menuitem, gpointer user_data); @@ -604,5 +600,5 @@ gpointer user_data);
void -on_very_small_icons1_activate (GtkMenuItem *menuitem, - gpointer user_data); +on_very_small_icons1_activate (GtkCheckMenuItem *menuitem, + gpointer user_data);
Modified: trunk/src/encodings.c =================================================================== --- trunk/src/encodings.c 2009-04-16 17:57:29 UTC (rev 3711) +++ trunk/src/encodings.c 2009-04-17 15:30:01 UTC (rev 3712) @@ -38,6 +38,7 @@ #include "utils.h" #include "support.h" #include "document.h" +#include "documentprivate.h" #include "msgwindow.h" #include "encodings.h" #include "callbacks.h" @@ -301,6 +302,27 @@ #endif
+static void encodings_radio_item_change_cb(GtkCheckMenuItem *menuitem, gpointer user_data) +{ + GeanyDocument *doc = document_get_current(); + guint i = GPOINTER_TO_INT(user_data); + + if (ignore_callback || doc == NULL || encodings[i].charset == NULL || + ! gtk_check_menu_item_get_active(menuitem) || + utils_str_equal(encodings[i].charset, doc->encoding)) + return; + + if (doc->readonly) + { + utils_beep(); + return; + } + document_undo_add(doc, UNDO_ENCODING, g_strdup(doc->encoding)); + + document_set_encoding(doc, encodings[i].charset); +} + + void encodings_finalize(void) { #ifdef HAVE_REGCOMP @@ -342,7 +364,7 @@ /* create encodings submenu in document menu */ menu[0] = ui_lookup_widget(main_widgets.window, "set_encoding1_menu"); menu[1] = ui_lookup_widget(main_widgets.window, "menu_reload_as1_menu"); - cb_func[0] = G_CALLBACK(on_encoding_change); + cb_func[0] = G_CALLBACK(encodings_radio_item_change_cb); cb_func[1] = G_CALLBACK(on_reload_as_activate);
for (k = 0; k < 2; k++)
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2009-04-16 17:57:29 UTC (rev 3711) +++ trunk/src/filetypes.c 2009-04-17 15:30:01 UTC (rev 3712) @@ -970,11 +970,11 @@
static void -on_filetype_change (GtkMenuItem *menuitem, +on_filetype_change (GtkCheckMenuItem *menuitem, gpointer user_data) { GeanyDocument *doc = document_get_current(); - if (ignore_callback || doc == NULL) + if (ignore_callback || doc == NULL || ! gtk_check_menu_item_get_active(menuitem)) return;
document_set_filetype(doc, (GeanyFiletype*)user_data);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.