2015-10-11 20:48:08 +00:00
|
|
|
/* Shortcuts Window
|
|
|
|
*
|
|
|
|
* GtkShortcutsWindow is a window that provides a help overlay
|
|
|
|
* for shortcuts and gestures in an application.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_shortcuts (GtkWidget *window,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *id,
|
|
|
|
const char *view)
|
2015-10-11 20:48:08 +00:00
|
|
|
{
|
|
|
|
GtkBuilder *builder;
|
|
|
|
GtkWidget *overlay;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *path;
|
2015-10-11 20:48:08 +00:00
|
|
|
|
|
|
|
path = g_strdup_printf ("/shortcuts/%s.ui", id);
|
|
|
|
builder = gtk_builder_new_from_resource (path);
|
|
|
|
g_free (path);
|
|
|
|
overlay = GTK_WIDGET (gtk_builder_get_object (builder, id));
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (overlay), GTK_WINDOW (window));
|
|
|
|
g_object_set (overlay, "view-name", view, NULL);
|
|
|
|
gtk_widget_show (overlay);
|
2015-12-05 18:50:26 +00:00
|
|
|
g_object_unref (builder);
|
2015-10-11 20:48:08 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 07:48:48 +00:00
|
|
|
void
|
|
|
|
shortcuts_builder_shortcuts (GtkWidget *window)
|
2015-10-11 20:48:08 +00:00
|
|
|
{
|
|
|
|
show_shortcuts (window, "shortcuts-builder", NULL);
|
|
|
|
}
|
|
|
|
|
2019-11-29 07:48:48 +00:00
|
|
|
void
|
|
|
|
shortcuts_gedit_shortcuts (GtkWidget *window)
|
2015-10-11 20:48:08 +00:00
|
|
|
{
|
|
|
|
show_shortcuts (window, "shortcuts-gedit", NULL);
|
|
|
|
}
|
|
|
|
|
2019-11-29 07:48:48 +00:00
|
|
|
void
|
|
|
|
shortcuts_clocks_shortcuts (GtkWidget *window)
|
2015-10-11 20:48:08 +00:00
|
|
|
{
|
|
|
|
show_shortcuts (window, "shortcuts-clocks", NULL);
|
|
|
|
}
|
|
|
|
|
2019-11-29 07:48:48 +00:00
|
|
|
void
|
|
|
|
shortcuts_clocks_shortcuts_stopwatch (GtkWidget *window)
|
2015-10-11 20:48:08 +00:00
|
|
|
{
|
|
|
|
show_shortcuts (window, "shortcuts-clocks", "stopwatch");
|
|
|
|
}
|
|
|
|
|
2019-11-29 07:48:48 +00:00
|
|
|
void
|
|
|
|
shortcuts_boxes_shortcuts (GtkWidget *window)
|
2015-12-15 23:39:39 +00:00
|
|
|
{
|
|
|
|
show_shortcuts (window, "shortcuts-boxes", NULL);
|
|
|
|
}
|
|
|
|
|
2019-11-29 07:48:48 +00:00
|
|
|
void
|
|
|
|
shortcuts_boxes_shortcuts_wizard (GtkWidget *window)
|
2015-12-15 23:39:39 +00:00
|
|
|
{
|
|
|
|
show_shortcuts (window, "shortcuts-boxes", "wizard");
|
|
|
|
}
|
|
|
|
|
2019-11-29 07:48:48 +00:00
|
|
|
void
|
|
|
|
shortcuts_boxes_shortcuts_display (GtkWidget *window)
|
2015-12-15 23:39:39 +00:00
|
|
|
{
|
|
|
|
show_shortcuts (window, "shortcuts-boxes", "display");
|
|
|
|
}
|
|
|
|
|
2015-10-11 20:48:08 +00:00
|
|
|
GtkWidget *
|
|
|
|
do_shortcuts (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
static gboolean icons_added = FALSE;
|
|
|
|
|
|
|
|
if (!icons_added)
|
|
|
|
{
|
|
|
|
icons_added = TRUE;
|
2020-02-01 22:38:49 +00:00
|
|
|
gtk_icon_theme_add_resource_path (gtk_icon_theme_get_for_display (gtk_widget_get_display (do_widget)), "/icons");
|
2015-10-11 20:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_type_ensure (G_TYPE_FILE_ICON);
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
GtkBuilder *builder;
|
|
|
|
|
2019-11-29 07:48:48 +00:00
|
|
|
builder = gtk_builder_new_from_resource ("/shortcuts/shortcuts.ui");
|
2015-10-11 20:48:08 +00:00
|
|
|
window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2015-10-11 20:48:08 +00:00
|
|
|
|
|
|
|
g_object_unref (builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2015-10-11 20:48:08 +00:00
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2015-10-11 20:48:08 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|