2020-06-17 22:08:17 +00:00
|
|
|
/* Entry/Undo and Redo
|
2019-11-01 18:20:02 +00:00
|
|
|
*
|
|
|
|
* GtkEntry can provide basic Undo/Redo support using standard keyboard
|
2020-06-17 22:08:17 +00:00
|
|
|
* accelerators such as Control+z to undo and Control+Shift+z to redo.
|
|
|
|
* Additionally, Control+y can be used to redo.
|
2019-11-01 18:20:02 +00:00
|
|
|
*
|
|
|
|
* Use gtk_entry_set_enable_undo() to enable undo/redo support.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_entry_undo (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *entry;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2019-11-01 18:20:02 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2020-06-17 22:08:17 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Undo and Redo");
|
2019-11-01 18:20:02 +00:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2019-11-01 18:20:02 +00:00
|
|
|
|
2020-11-02 17:01:11 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
|
|
|
gtk_widget_set_margin_start (vbox, 18);
|
|
|
|
gtk_widget_set_margin_end (vbox, 18);
|
|
|
|
gtk_widget_set_margin_top (vbox, 18);
|
|
|
|
gtk_widget_set_margin_bottom (vbox, 18);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), vbox);
|
2019-11-01 18:20:02 +00:00
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label),
|
2020-11-02 17:01:11 +00:00
|
|
|
"Use Control+z or Control+Shift+z to undo or redo changes");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), label);
|
2019-11-01 18:20:02 +00:00
|
|
|
|
|
|
|
/* Create our entry */
|
|
|
|
entry = gtk_entry_new ();
|
|
|
|
gtk_editable_set_enable_undo (GTK_EDITABLE (entry), TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), entry);
|
2023-06-17 16:19:05 +00:00
|
|
|
|
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (entry),
|
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
|
|
|
|
-1);
|
2019-11-01 18:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
2022-11-28 04:03:14 +00:00
|
|
|
gtk_widget_set_visible (window, TRUE);
|
2019-11-01 18:20:02 +00:00
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2019-11-01 18:20:02 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|