| 1 |
/* Shortcuts Window |
| 2 |
* |
| 3 |
* GtkShortcutsWindow is a window that provides a help overlay |
| 4 |
* for shortcuts and gestures in an application. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <gtk/gtk.h> |
| 8 |
|
| 9 |
static void |
| 10 |
show_shortcuts (GtkWidget *window, |
| 11 |
const gchar *id, |
| 12 |
const gchar *view) |
| 13 |
{ |
| 14 |
GtkBuilder *builder; |
| 15 |
GtkWidget *overlay; |
| 16 |
gchar *path; |
| 17 |
|
| 18 |
path = g_strdup_printf ("/shortcuts/%s.ui", id); |
| 19 |
builder = gtk_builder_new_from_resource (path); |
| 20 |
g_free (path); |
| 21 |
overlay = GTK_WIDGET (gtk_builder_get_object (builder, id)); |
| 22 |
gtk_window_set_transient_for (GTK_WINDOW (overlay), GTK_WINDOW (window)); |
| 23 |
g_object_set (overlay, "view-name", view, NULL); |
| 24 |
gtk_widget_show (overlay); |
| 25 |
g_object_unref (builder); |
| 26 |
} |
| 27 |
|
| 28 |
static void |
| 29 |
builder_shortcuts (GtkWidget *window) |
| 30 |
{ |
| 31 |
show_shortcuts (window, "shortcuts-builder", NULL); |
| 32 |
} |
| 33 |
|
| 34 |
static void |
| 35 |
gedit_shortcuts (GtkWidget *window) |
| 36 |
{ |
| 37 |
show_shortcuts (window, "shortcuts-gedit", NULL); |
| 38 |
} |
| 39 |
|
| 40 |
static void |
| 41 |
clocks_shortcuts (GtkWidget *window) |
| 42 |
{ |
| 43 |
show_shortcuts (window, "shortcuts-clocks", NULL); |
| 44 |
} |
| 45 |
|
| 46 |
static void |
| 47 |
clocks_shortcuts_stopwatch (GtkWidget *window) |
| 48 |
{ |
| 49 |
show_shortcuts (window, "shortcuts-clocks", "stopwatch"); |
| 50 |
} |
| 51 |
|
| 52 |
static void |
| 53 |
boxes_shortcuts (GtkWidget *window) |
| 54 |
{ |
| 55 |
show_shortcuts (window, "shortcuts-boxes", NULL); |
| 56 |
} |
| 57 |
|
| 58 |
static void |
| 59 |
boxes_shortcuts_wizard (GtkWidget *window) |
| 60 |
{ |
| 61 |
show_shortcuts (window, "shortcuts-boxes", "wizard"); |
| 62 |
} |
| 63 |
|
| 64 |
static void |
| 65 |
boxes_shortcuts_display (GtkWidget *window) |
| 66 |
{ |
| 67 |
show_shortcuts (window, "shortcuts-boxes", "display"); |
| 68 |
} |
| 69 |
|
| 70 |
GtkWidget * |
| 71 |
do_shortcuts (GtkWidget *do_widget) |
| 72 |
{ |
| 73 |
static GtkWidget *window = NULL; |
| 74 |
static gboolean icons_added = FALSE; |
| 75 |
|
| 76 |
if (!icons_added) |
| 77 |
{ |
| 78 |
icons_added = TRUE; |
| 79 |
gtk_icon_theme_add_resource_path (gtk_icon_theme_get_default (), "/icons"); |
| 80 |
} |
| 81 |
|
| 82 |
g_type_ensure (G_TYPE_FILE_ICON); |
| 83 |
|
| 84 |
if (!window) |
| 85 |
{ |
| 86 |
GtkBuilder *builder; |
| 87 |
|
| 88 |
builder = gtk_builder_new_from_resource ("/shortcuts/shortcuts.ui"); |
| 89 |
gtk_builder_add_callback_symbols (builder, |
| 90 |
"builder_shortcuts", G_CALLBACK (builder_shortcuts), |
| 91 |
"gedit_shortcuts", G_CALLBACK (gedit_shortcuts), |
| 92 |
"clocks_shortcuts", G_CALLBACK (clocks_shortcuts), |
| 93 |
"clocks_shortcuts_stopwatch", G_CALLBACK (clocks_shortcuts_stopwatch), |
| 94 |
"boxes_shortcuts", G_CALLBACK (boxes_shortcuts), |
| 95 |
"boxes_shortcuts_wizard", G_CALLBACK (boxes_shortcuts_wizard), |
| 96 |
"boxes_shortcuts_display", G_CALLBACK (boxes_shortcuts_display), |
| 97 |
NULL); |
| 98 |
gtk_builder_connect_signals (builder, NULL); |
| 99 |
window = GTK_WIDGET (gtk_builder_get_object (builder, "window1")); |
| 100 |
gtk_window_set_screen (GTK_WINDOW (window), |
| 101 |
gtk_widget_get_screen (do_widget)); |
| 102 |
g_signal_connect (window, "destroy", |
| 103 |
G_CALLBACK (gtk_widget_destroyed), &window); |
| 104 |
|
| 105 |
g_object_unref (builder); |
| 106 |
} |
| 107 |
|
| 108 |
if (!gtk_widget_get_visible (window)) |
| 109 |
gtk_widget_show_all (window); |
| 110 |
else |
| 111 |
gtk_widget_destroy (window); |
| 112 |
|
| 113 |
return window; |
| 114 |
} |