missing NULL terminator in set_config_x
[geda-gaf.git] / gschem / src / gschem_hotkey_dialog.c
blobba00ec579b450880e79b951e26e668ff7b06bb8b
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 /*! \todo STILL NEED to clean up line lengths in aa and tr */
21 #include <config.h>
23 #include <stdio.h>
24 #ifdef HAVE_STDLIB_H
25 #include <stdlib.h>
26 #endif
27 #ifdef HAVE_STRING_H
28 #include <string.h>
29 #endif
31 #include "gschem.h"
33 #define GLADE_HOOKUP_OBJECT(component,widget,name) \
34 g_object_set_data_full (G_OBJECT (component), name, \
35 gtk_widget_ref (widget), (GDestroyNotify) g_object_unref)
39 /***************** Start of help/keymapping dialog box **************/
41 /*! \brief Response function for the hotkey dialog
42 * \par Function Description
43 * This function destroys the hotkey dialog and does some cleanup.
45 void x_dialog_hotkeys_response(GtkWidget *w, gint response,
46 GschemToplevel *w_current)
48 switch(response) {
49 case GTK_RESPONSE_REJECT:
50 case GTK_RESPONSE_DELETE_EVENT:
51 /* void */
52 break;
53 default:
54 printf("x_dialog_hotkeys_response(): strange signal %d\n", response);
56 /* clean up */
57 gtk_widget_destroy(w_current->hkwindow);
58 w_current->hkwindow = NULL;
61 /*! \brief Fix up displaying icons in list of hotkeys.
62 * In gschem, we use both GTK's stock icons and also our own icons
63 * that we add to the icon theme search path. We identify each icon
64 * by a single icon name, which might either name a GTK stock icon or
65 * a theme icon. To determine which icon to show, we first check if
66 * there's a matching stock icon, and if one doesn't exist, we fall
67 * back to looking in the theme.
69 * The GtkCellRendererPixbuf doesn't provide this capability. If its
70 * "icon-name" property is set, it doesn't look at stock items, but if
71 * its "stock-id" property is set, it ignores the "icon-name" even if
72 * no matching stock item exists.
74 * This handler hooks into the "notify::stock-id" signal in order to
75 * implement the desired fallback behaviour.
77 static void
78 x_dialog_hotkeys_cell_stock_id_notify (GObject *gobject,
79 GParamSpec *pspec,
80 gpointer user_data)
82 gchar *stock_id = NULL;
83 const gchar *new_icon_name = NULL;
84 const gchar *new_stock_id = NULL;
85 GtkStockItem stock_info;
87 /* Decide whether the requested stock ID actually matches a stock
88 * item */
89 g_object_get (gobject,
90 "stock-id", &stock_id,
91 NULL);
92 new_stock_id = stock_id;
94 if (stock_id != NULL && !gtk_stock_lookup (stock_id, &stock_info)) {
95 new_icon_name = stock_id;
96 new_stock_id = NULL;
99 /* Fix up the cell renderer, making sure that this function doesn't
100 * get called recursively. */
101 g_signal_handlers_block_by_func (gobject,
102 x_dialog_hotkeys_cell_stock_id_notify,
103 NULL);
104 g_object_set (gobject,
105 "icon-name", new_icon_name,
106 "stock-id", new_stock_id,
107 NULL);
108 g_signal_handlers_unblock_by_func (gobject,
109 x_dialog_hotkeys_cell_stock_id_notify,
110 NULL);
112 g_free (stock_id);
115 /*! \brief Creates the hotkeys dialog
116 * \par Function Description
117 * This function creates the hotkey dialog and puts the list of hotkeys
118 * into it.
120 void x_dialog_hotkeys (GschemToplevel *w_current)
122 GtkWidget *vbox, *scrolled_win;
123 GtkTreeModel *store;
124 GtkWidget *treeview;
125 GtkCellRenderer *renderer;
126 GtkTreeViewColumn *column;
128 if (!w_current->hkwindow) {
129 w_current->hkwindow = gschem_dialog_new_with_buttons(_("Hotkeys"),
130 GTK_WINDOW(w_current->main_window),
131 0, /* not modal */
132 "hotkeys", w_current,
133 GTK_STOCK_CLOSE,
134 GTK_RESPONSE_REJECT,
135 NULL);
137 gtk_window_set_icon_name (GTK_WINDOW (w_current->hkwindow),
138 "preferences-desktop-keyboard-shortcuts");
140 gtk_window_set_position (GTK_WINDOW (w_current->hkwindow), GTK_WIN_POS_NONE);
142 g_signal_connect (G_OBJECT (w_current->hkwindow), "response",
143 G_CALLBACK (x_dialog_hotkeys_response),
144 w_current);
146 gtk_dialog_set_default_response(GTK_DIALOG(w_current->hkwindow),
147 GTK_RESPONSE_ACCEPT);
149 gtk_container_set_border_width (GTK_CONTAINER (w_current->hkwindow),
150 DIALOG_BORDER_SPACING);
151 gtk_widget_set_size_request (w_current->hkwindow, 300, 300);
153 vbox = GTK_DIALOG(w_current->hkwindow)->vbox;
154 gtk_box_set_spacing(GTK_BOX(vbox), DIALOG_V_SPACING);
156 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
157 gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
158 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
159 GTK_POLICY_AUTOMATIC,
160 GTK_POLICY_AUTOMATIC);
162 /* the model */
163 store = GTK_TREE_MODEL (gschem_hotkey_store_new ());
165 /* the tree view */
166 treeview = gtk_tree_view_new_with_model (store);
167 gtk_container_add(GTK_CONTAINER(scrolled_win), treeview);
169 /* the columns */
170 /* The first column contains the action's icon (if one was set)
171 * and its label. */
172 renderer = gtk_cell_renderer_pixbuf_new ();
173 column = gtk_tree_view_column_new_with_attributes (_("Action"),
174 renderer,
175 "stock-id",
176 GSCHEM_HOTKEY_STORE_COLUMN_ICON,
177 NULL);
178 /* Fix things up to show stock icons *and* theme icons. */
179 g_signal_connect (renderer, "notify::stock-id",
180 G_CALLBACK (x_dialog_hotkeys_cell_stock_id_notify),
181 NULL);
183 renderer = gtk_cell_renderer_text_new ();
184 gtk_tree_view_column_pack_start (column, renderer, FALSE);
185 gtk_tree_view_column_set_attributes (column, renderer,
186 "text", GSCHEM_HOTKEY_STORE_COLUMN_LABEL,
187 NULL);
189 /* The second column contains the action's keybinding */
190 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
191 column = gtk_tree_view_column_new_with_attributes (_("Keystroke(s)"),
192 renderer,
193 "text",
194 GSCHEM_HOTKEY_STORE_COLUMN_KEYS,
195 NULL);
196 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
198 /* show all recursively */
199 gtk_widget_show_all(w_current->hkwindow);
202 else { /* dialog already created */
203 gtk_window_present(GTK_WINDOW(w_current->hkwindow));
207 /***************** End of help/keymapping dialog box ****************/