the default keybindings



Here is a little curiosity I wasted a few hours on last night.

I added some documentation to text view signals, and thought
it would be nice to show the default key bindings in the signal docs.
After doing it manually for some signals, it occurred to me that
it might be possible to introspect this information, and I wrote
a little app that dumps out an rc file containing all the default keybindings.

Maybe this is useful for something, so I'll send it here.

Matthias
#include <gtk/gtk.h>
#include <gtk/gtkprintunixdialog.h>
#include <gtk/gtkpagesetupunixdialog.h>
#include <gtk/gtkprinter.h>
#include <gtk/gtkprintjob.h>

GType object_types[185];

static GType *
get_object_types (void)
{
    gint i = 0;
    object_types[i++] = gtk_about_dialog_get_type ();
    object_types[i++] = gtk_accel_group_get_type ();
    object_types[i++] = gtk_accel_label_get_type ();
    object_types[i++] = gtk_accel_map_get_type ();
    object_types[i++] = gtk_accessible_get_type ();
    object_types[i++] = gtk_action_get_type ();
    object_types[i++] = gtk_action_group_get_type ();
    object_types[i++] = gtk_adjustment_get_type ();
    object_types[i++] = gtk_alignment_get_type ();
    object_types[i++] = gtk_arrow_get_type ();
    object_types[i++] = gtk_aspect_frame_get_type ();
    object_types[i++] = gtk_assistant_get_type ();
    object_types[i++] = gtk_bin_get_type ();
    object_types[i++] = gtk_box_get_type ();
    object_types[i++] = gtk_builder_get_type ();
    object_types[i++] = gtk_buildable_get_type ();
    object_types[i++] = gtk_button_box_get_type ();
    object_types[i++] = gtk_button_get_type ();
    object_types[i++] = gtk_calendar_get_type ();
    object_types[i++] = gtk_cell_editable_get_type ();
    object_types[i++] = gtk_cell_layout_get_type ();
    object_types[i++] = gtk_cell_renderer_accel_get_type ();
    object_types[i++] = gtk_cell_renderer_combo_get_type ();
    object_types[i++] = gtk_cell_renderer_get_type ();
    object_types[i++] = gtk_cell_renderer_pixbuf_get_type ();
    object_types[i++] = gtk_cell_renderer_progress_get_type ();
    object_types[i++] = gtk_cell_renderer_spin_get_type ();
    object_types[i++] = gtk_cell_renderer_text_get_type ();
    object_types[i++] = gtk_cell_renderer_toggle_get_type ();
    object_types[i++] = gtk_cell_view_get_type ();
    object_types[i++] = gtk_check_button_get_type ();
    object_types[i++] = gtk_check_menu_item_get_type ();
    object_types[i++] = gtk_clipboard_get_type ();
    object_types[i++] = gtk_clist_get_type ();
    object_types[i++] = gtk_color_button_get_type ();
    object_types[i++] = gtk_color_selection_dialog_get_type ();
    object_types[i++] = gtk_color_selection_get_type ();
    object_types[i++] = gtk_combo_box_entry_get_type ();
    object_types[i++] = gtk_combo_box_get_type ();
    object_types[i++] = gtk_combo_get_type ();
    object_types[i++] = gtk_container_get_type ();
    object_types[i++] = gtk_ctree_get_type ();
    object_types[i++] = gtk_curve_get_type ();
    object_types[i++] = gtk_dialog_get_type ();
    object_types[i++] = gtk_drawing_area_get_type ();
    object_types[i++] = gtk_editable_get_type ();
    object_types[i++] = gtk_entry_completion_get_type ();
    object_types[i++] = gtk_entry_get_type ();
    object_types[i++] = gtk_event_box_get_type ();
    object_types[i++] = gtk_expander_get_type ();
    object_types[i++] = gtk_file_chooser_button_get_type ();
    object_types[i++] = gtk_file_chooser_dialog_get_type ();
    object_types[i++] = gtk_file_chooser_get_type ();
    object_types[i++] = gtk_file_chooser_widget_get_type ();
    object_types[i++] = gtk_file_filter_get_type ();
    object_types[i++] = gtk_file_selection_get_type ();
    object_types[i++] = gtk_fixed_get_type ();
    object_types[i++] = gtk_font_button_get_type ();
    object_types[i++] = gtk_font_selection_dialog_get_type ();
    object_types[i++] = gtk_font_selection_get_type ();
    object_types[i++] = gtk_frame_get_type ();
    object_types[i++] = gtk_gamma_curve_get_type ();
    object_types[i++] = gtk_handle_box_get_type ();
    object_types[i++] = gtk_hbox_get_type ();
    object_types[i++] = gtk_hbutton_box_get_type ();
    object_types[i++] = gtk_hpaned_get_type ();
    object_types[i++] = gtk_hruler_get_type ();
    object_types[i++] = gtk_hscale_get_type ();
    object_types[i++] = gtk_hscrollbar_get_type ();
    object_types[i++] = gtk_hseparator_get_type ();
    object_types[i++] = gtk_icon_factory_get_type ();
    object_types[i++] = gtk_icon_theme_get_type ();
    object_types[i++] = gtk_icon_view_get_type ();
    object_types[i++] = gtk_image_get_type ();
    object_types[i++] = gtk_image_menu_item_get_type ();
    object_types[i++] = gtk_im_context_get_type ();
    object_types[i++] = gtk_im_context_simple_get_type ();
    object_types[i++] = gtk_im_multicontext_get_type ();
    object_types[i++] = gtk_input_dialog_get_type ();
    object_types[i++] = gtk_invisible_get_type ();
    object_types[i++] = gtk_item_factory_get_type ();
    object_types[i++] = gtk_item_get_type ();
    object_types[i++] = gtk_label_get_type ();
    object_types[i++] = gtk_layout_get_type ();
    object_types[i++] = gtk_link_button_get_type ();
    object_types[i++] = gtk_list_get_type ();
    object_types[i++] = gtk_list_item_get_type ();
    object_types[i++] = gtk_list_store_get_type ();
    object_types[i++] = gtk_menu_bar_get_type ();
    object_types[i++] = gtk_menu_get_type ();
    object_types[i++] = gtk_menu_item_get_type ();
    object_types[i++] = gtk_menu_shell_get_type ();
    object_types[i++] = gtk_menu_tool_button_get_type ();
    object_types[i++] = gtk_message_dialog_get_type ();
    object_types[i++] = gtk_misc_get_type ();
    object_types[i++] = gtk_notebook_get_type ();
    object_types[i++] = gtk_object_get_type ();
    object_types[i++] = gtk_old_editable_get_type ();
    object_types[i++] = gtk_option_menu_get_type ();
    object_types[i++] = gtk_page_setup_get_type ();
    object_types[i++] = gtk_page_setup_unix_dialog_get_type ();
    object_types[i++] = gtk_paned_get_type ();
    object_types[i++] = gtk_paper_size_get_type ();
    object_types[i++] = gtk_pixmap_get_type ();
    object_types[i++] = gtk_plug_get_type ();
    object_types[i++] = gtk_preview_get_type ();
    object_types[i++] = gtk_printer_get_type ();
    object_types[i++] = gtk_print_context_get_type ();
    object_types[i++] = gtk_print_job_get_type ();
    object_types[i++] = gtk_print_operation_get_type ();
    object_types[i++] = gtk_print_settings_get_type ();
    object_types[i++] = gtk_print_unix_dialog_get_type ();
    object_types[i++] = gtk_progress_bar_get_type ();
    object_types[i++] = gtk_progress_get_type ();
    object_types[i++] = gtk_radio_action_get_type ();
    object_types[i++] = gtk_radio_button_get_type ();
    object_types[i++] = gtk_radio_menu_item_get_type ();
    object_types[i++] = gtk_radio_tool_button_get_type ();
    object_types[i++] = gtk_range_get_type ();
    object_types[i++] = gtk_rc_style_get_type ();
    object_types[i++] = gtk_recent_action_get_type ();
    object_types[i++] = gtk_recent_chooser_get_type ();
    object_types[i++] = gtk_recent_chooser_dialog_get_type ();
    object_types[i++] = gtk_recent_chooser_menu_get_type ();
    object_types[i++] = gtk_recent_chooser_widget_get_type ();
    object_types[i++] = gtk_recent_manager_get_type ();
    object_types[i++] = gtk_ruler_get_type ();
    object_types[i++] = gtk_scale_button_get_type ();
    object_types[i++] = gtk_scale_get_type ();
    object_types[i++] = gtk_scrollbar_get_type ();
    object_types[i++] = gtk_scrolled_window_get_type ();
    object_types[i++] = gtk_separator_get_type ();
    object_types[i++] = gtk_separator_menu_item_get_type ();
    object_types[i++] = gtk_separator_tool_item_get_type ();
    object_types[i++] = gtk_settings_get_type ();
    object_types[i++] = gtk_size_group_get_type ();
    object_types[i++] = gtk_socket_get_type ();
    object_types[i++] = gtk_spin_button_get_type ();
    object_types[i++] = gtk_statusbar_get_type ();
    object_types[i++] = gtk_status_icon_get_type ();
    object_types[i++] = gtk_style_get_type ();
    object_types[i++] = gtk_table_get_type ();
    object_types[i++] = gtk_tearoff_menu_item_get_type ();
    object_types[i++] = gtk_text_buffer_get_type ();
    object_types[i++] = gtk_text_child_anchor_get_type ();
    object_types[i++] = gtk_text_get_type ();
    object_types[i++] = gtk_text_iter_get_type ();
    object_types[i++] = gtk_text_mark_get_type ();
    object_types[i++] = gtk_text_tag_get_type ();
    object_types[i++] = gtk_text_tag_table_get_type ();
    object_types[i++] = gtk_text_view_get_type ();
    object_types[i++] = gtk_tips_query_get_type ();
    object_types[i++] = gtk_toggle_action_get_type ();
    object_types[i++] = gtk_toggle_button_get_type ();
    object_types[i++] = gtk_toggle_tool_button_get_type ();
    object_types[i++] = gtk_toolbar_get_type ();
    object_types[i++] = gtk_tool_button_get_type ();
    object_types[i++] = gtk_tool_item_get_type ();
    object_types[i++] = gtk_tooltips_get_type ();
    object_types[i++] = gtk_tree_drag_dest_get_type ();
    object_types[i++] = gtk_tree_drag_source_get_type ();
    object_types[i++] = gtk_tree_get_type ();
    object_types[i++] = gtk_tree_item_get_type ();
    object_types[i++] = gtk_tree_model_filter_get_type ();
    object_types[i++] = gtk_tree_model_get_type ();
    object_types[i++] = gtk_tree_model_sort_get_type ();
    object_types[i++] = gtk_tree_selection_get_type ();
    object_types[i++] = gtk_tree_sortable_get_type ();
    object_types[i++] = gtk_tree_store_get_type ();
    object_types[i++] = gtk_tree_view_column_get_type ();
    object_types[i++] = gtk_tree_view_get_type ();
    object_types[i++] = gtk_ui_manager_get_type ();
    object_types[i++] = gtk_vbox_get_type ();
    object_types[i++] = gtk_vbutton_box_get_type ();
    object_types[i++] = gtk_viewport_get_type ();
    object_types[i++] = gtk_volume_button_get_type ();
    object_types[i++] = gtk_vpaned_get_type ();
    object_types[i++] = gtk_vruler_get_type ();
    object_types[i++] = gtk_vscale_get_type ();
    object_types[i++] = gtk_vscrollbar_get_type ();
    object_types[i++] = gtk_vseparator_get_type ();
    object_types[i++] = gtk_widget_get_type ();
    object_types[i++] = gtk_window_get_type ();
    object_types[i++] = gtk_window_group_get_type ();
    object_types[i] = 0;

    /* Need to make sure all the types are loaded in and initialize
     * their signals and properties.
     */
    for (i=0; object_types[i]; i++)
      {
        if (G_TYPE_IS_CLASSED (object_types[i]))
          g_type_class_ref (object_types[i]);
        if (G_TYPE_IS_INTERFACE (object_types[i]))
          g_type_default_interface_ref (object_types[i]);
      }

    return object_types;
}

static void
dump_bindings (GType type)
{
	GtkBindingSet *set;
	GtkBindingEntry *entry;
	GtkBindingSignal *signal;
	GSignalQuery query;
	gint i;
	guint signal_id;
	glong longval;
	GTypeClass *class;
        
	if (!g_type_is_a (type, gtk_widget_get_type ()))
		return;

	if (G_TYPE_IS_INTERFACE (type))
		return;

	class = g_type_class_ref (type);

	set = gtk_binding_set_by_class (class);

	g_type_class_unref (class);

	if (!set || !set->entries)
		return;

	g_print ("binding \"%s-binding\" {\n", g_type_name (type));
	for (entry = set->entries; entry; entry = entry->set_next) {
		g_print ("  bind \"%s\" {\n", gtk_accelerator_name (entry->keyval, entry->modifiers));
		for (signal = entry->signals; signal; signal = signal->next) {
			signal_id = g_signal_lookup (signal->signal_name, GTK_TYPE_TEXT_VIEW);
			g_signal_query (signal_id, &query);
                        g_print ("    \"%s\" (", query.signal_name);
                        for (i = 0; i < signal->n_args; i++) {
				if (i > 0)
					g_print (", ");
				switch (G_TYPE_FUNDAMENTAL (signal->args[i].arg_type)) {
				case G_TYPE_LONG: 
					longval = signal->args[i].d.long_data;
					if (G_TYPE_FUNDAMENTAL (query.param_types[i]) == G_TYPE_ENUM) {
						GEnumClass *class = G_ENUM_CLASS (g_type_class_ref (query.param_types[i]));
						GEnumValue *value;

						value =	g_enum_get_value (class, longval);
						g_print ("%s", value->value_nick);
					}
					else if (G_TYPE_FUNDAMENTAL (query.param_types[i]) == G_TYPE_FLAGS) {
						GFlagsClass *class = G_FLAGS_CLASS (g_type_class_ref (query.param_types[i]));
						GFlagsValue *value;
	
						value = g_flags_get_first_value (class, longval);
						while (value) {
							g_print ("%s", value->value_nick);
							longval = longval & ~value->value;
							value = g_flags_get_first_value (class, longval);
							if (value)
								g_print ("|");
						}
					}
#if 0
					else if (G_TYPE_FUNDAMENTAL (query.param_types[i]) == G_TYPE_BOOLEAN) {
						g_print ("%s", longval ? "TRUE" : "FALSE");
					} 
#endif
					else {
						g_print ("%ld", longval);
					}
					break;
				case G_TYPE_DOUBLE:
					g_print ("%.2lf", signal->args[i].d.double_data);
					break;
				case G_TYPE_STRING:
					g_print ("\"%s\"", signal->args[i].d.string_data);
					break;
				}
			}
                        g_print (")\n");
		}
		g_print ("  }\n");
	}
	g_print ("}\nclass \"%s\" binding \"%s-binding\"\n", 
                 g_type_name (type), g_type_name (type));
}

int main (int argc, char *argv[])
{
	gint i;

	gtk_init (&argc, &argv);
	get_object_types ();

        for (i = 0; object_types[i]; i++)
		dump_bindings (object_types[i]);

	return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]