Mercurial > pidgin.yaz
comparison pidgin/gtkprefs.c @ 22772:7e28f2b64982
Add a tickybox to set the 'close conversation window' shortcut to Escape.
If you set a custom accelerator, then toggle this tickybox on and off again,
it'll be reset to ^W not your custom one. Do we care?
author | Will Thompson <will.thompson@collabora.co.uk> |
---|---|
date | Wed, 30 Apr 2008 22:52:16 +0000 |
parents | 36036b9489fe |
children | d2af1ee7448b 61a7929a97b5 |
comparison
equal
deleted
inserted
replaced
22771:5954c65ae4f4 | 22772:7e28f2b64982 |
---|---|
823 gtk_widget_set_sensitive(GTK_WIDGET(data), TRUE); | 823 gtk_widget_set_sensitive(GTK_WIDGET(data), TRUE); |
824 else | 824 else |
825 gtk_widget_set_sensitive(GTK_WIDGET(data), FALSE); | 825 gtk_widget_set_sensitive(GTK_WIDGET(data), FALSE); |
826 } | 826 } |
827 | 827 |
828 | |
829 #define CONVERSATION_CLOSE_ACCEL_PATH "<main>/Conversation/Close" | |
830 | |
831 /* Filled in in keyboard_shortcuts(). */ | |
832 static GtkAccelKey ctrl_w = { 0, 0, 0 }; | |
833 static GtkAccelKey escape = { 0, 0, 0 }; | |
834 | |
835 static guint escape_closes_conversation_cb_id = 0; | |
836 | |
837 static gboolean | |
838 accel_is_escape(GtkAccelKey *k) | |
839 { | |
840 return (k->accel_key == escape.accel_key | |
841 && k->accel_mods == escape.accel_mods); | |
842 } | |
843 | |
844 /* Update the tickybox in Preferences when the keybinding for Conversation -> | |
845 * Close is changed via Gtk. | |
846 */ | |
847 static void | |
848 conversation_close_accel_changed_cb (GtkAccelMap *object, | |
849 gchar *accel_path, | |
850 guint accel_key, | |
851 GdkModifierType accel_mods, | |
852 gpointer checkbox_) | |
853 { | |
854 GtkToggleButton *checkbox = GTK_TOGGLE_BUTTON(checkbox_); | |
855 GtkAccelKey new = { accel_key, accel_mods, 0 }; | |
856 | |
857 g_signal_handler_block(checkbox, escape_closes_conversation_cb_id); | |
858 gtk_toggle_button_set_active(checkbox, accel_is_escape(&new)); | |
859 g_signal_handler_unblock(checkbox, escape_closes_conversation_cb_id); | |
860 } | |
861 | |
862 | |
863 static void | |
864 escape_closes_conversation_cb(GtkWidget *w, | |
865 gpointer unused) | |
866 { | |
867 gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); | |
868 gboolean changed; | |
869 GtkAccelKey *new_key = active ? &escape : &ctrl_w; | |
870 | |
871 changed = gtk_accel_map_change_entry(CONVERSATION_CLOSE_ACCEL_PATH, | |
872 new_key->accel_key, new_key->accel_mods, TRUE); | |
873 | |
874 /* If another path is already bound to the new accelerator, | |
875 * _change_entry tries to delete that binding (because it was passed | |
876 * replace=TRUE). If that other path is locked, then _change_entry | |
877 * will fail. We don't ever lock any accelerator paths, so this case | |
878 * should never arise. | |
879 */ | |
880 if(!changed) | |
881 purple_notify_warning (NULL, NULL, | |
882 _("IT'S A LION! GET IN THE CAR!"), NULL); | |
883 | |
884 /* TODO: create pidgin_accels_schedule_save */ | |
885 pidgin_save_accels_cb(NULL, 0, 0, NULL, NULL); | |
886 } | |
887 | |
888 | |
889 /* Creates preferences for keyboard shortcuts that it's hard to change with the | |
890 * standard Gtk accelerator-changing mechanism. | |
891 */ | |
892 static void | |
893 keyboard_shortcuts(GtkWidget *page) | |
894 { | |
895 GtkWidget *vbox = pidgin_make_frame(page, _("Keyboard Shortcuts")); | |
896 GtkWidget *checkbox; | |
897 GtkAccelKey current = { 0, 0, 0 }; | |
898 GtkAccelMap *map = gtk_accel_map_get(); | |
899 | |
900 /* Maybe it would be better just to hardcode the values? | |
901 * -- resiak, 2007-04-30 | |
902 */ | |
903 if (ctrl_w.accel_key == 0) | |
904 { | |
905 gtk_accelerator_parse ("<Control>w", &(ctrl_w.accel_key), | |
906 &(ctrl_w.accel_mods)); | |
907 g_assert(ctrl_w.accel_key != 0); | |
908 | |
909 gtk_accelerator_parse ("Escape", &(escape.accel_key), | |
910 &(escape.accel_mods)); | |
911 g_assert(escape.accel_key != 0); | |
912 } | |
913 | |
914 checkbox = gtk_check_button_new_with_mnemonic( | |
915 _("Cl_ose conversations with the Escape key")); | |
916 gtk_accel_map_lookup_entry(CONVERSATION_CLOSE_ACCEL_PATH, ¤t); | |
917 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), | |
918 accel_is_escape(¤t)); | |
919 | |
920 escape_closes_conversation_cb_id = g_signal_connect(checkbox, | |
921 "clicked", G_CALLBACK(escape_closes_conversation_cb), NULL); | |
922 | |
923 g_signal_connect(map, "changed::" CONVERSATION_CLOSE_ACCEL_PATH, | |
924 G_CALLBACK(conversation_close_accel_changed_cb), checkbox); | |
925 | |
926 gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0); | |
927 } | |
928 | |
828 static GtkWidget * | 929 static GtkWidget * |
829 interface_page(void) | 930 interface_page(void) |
830 { | 931 { |
831 GtkWidget *ret; | 932 GtkWidget *ret; |
832 GtkWidget *vbox; | 933 GtkWidget *vbox; |
901 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | 1002 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); |
902 | 1003 |
903 gtk_size_group_add_widget(sg, label); | 1004 gtk_size_group_add_widget(sg, label); |
904 | 1005 |
905 g_list_free(names); | 1006 g_list_free(names); |
1007 | |
1008 | |
1009 keyboard_shortcuts(ret); | |
1010 | |
906 | 1011 |
907 gtk_widget_show_all(ret); | 1012 gtk_widget_show_all(ret); |
908 g_object_unref(sg); | 1013 g_object_unref(sg); |
909 return ret; | 1014 return ret; |
910 } | 1015 } |