[gtk/wip/chergert/textundo: 5/8] gtk-demo: add an undo demo for GtkEntry
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/textundo: 5/8] gtk-demo: add an undo demo for GtkEntry
- Date: Tue, 5 Nov 2019 18:28:25 +0000 (UTC)
commit e93408e96285c0d91d0c288b2077d70eb6723b95
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 1 11:20:02 2019 -0700
gtk-demo: add an undo demo for GtkEntry
demos/gtk-demo/demo.gresource.xml | 1 +
demos/gtk-demo/entry_undo.c | 52 +++++++++++++++++++++++++++++++++++++++
demos/gtk-demo/meson.build | 1 +
3 files changed, 54 insertions(+)
---
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index 625ecac18a..a299fe9101 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -169,6 +169,7 @@
<file>editable_cells.c</file>
<file>entry_buffer.c</file>
<file>entry_completion.c</file>
+ <file>entry_undo.c</file>
<file>expander.c</file>
<file>filtermodel.c</file>
<file>fishbowl.c</file>
diff --git a/demos/gtk-demo/entry_undo.c b/demos/gtk-demo/entry_undo.c
new file mode 100644
index 0000000000..e94aefd529
--- /dev/null
+++ b/demos/gtk-demo/entry_undo.c
@@ -0,0 +1,52 @@
+/* Entry/Entry Undo
+ *
+ * GtkEntry can provide basic Undo/Redo support using standard keyboard
+ * accelerators such as Primary+z to undo and Primary+Shift+z to redo.
+ * Additionally, Primary+y can be used to redo.
+ *
+ * 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)
+ {
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_display (GTK_WINDOW (window),
+ gtk_widget_get_display (do_widget));
+ gtk_window_set_title (GTK_WINDOW (window), "Entry Undo");
+ gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &window);
+
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
+ g_object_set (vbox, "margin", 5, NULL);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ label = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (label),
+ "Use Primary+z or Primary+Shift+z to undo or redo changes");
+ gtk_container_add (GTK_CONTAINER (vbox), label);
+
+ /* Create our entry */
+ entry = gtk_entry_new ();
+ gtk_editable_set_enable_undo (GTK_EDITABLE (entry), TRUE);
+ gtk_container_add (GTK_CONTAINER (vbox), entry);
+ }
+
+ if (!gtk_widget_get_visible (window))
+ gtk_widget_show (window);
+ else
+ gtk_widget_destroy (window);
+
+ return window;
+}
diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build
index c021f9f60a..a107d52b58 100644
--- a/demos/gtk-demo/meson.build
+++ b/demos/gtk-demo/meson.build
@@ -24,6 +24,7 @@ demos = files([
'editable_cells.c',
'entry_buffer.c',
'entry_completion.c',
+ 'entry_undo.c',
'expander.c',
'filtermodel.c',
'fishbowl.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]