gui: New "entry-dialog" module for prompting for a text string.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 1 May 2011 04:08:01 +0000 (21:08 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 4 May 2011 03:18:05 +0000 (20:18 -0700)
This will be used in an upcoming commit to implement File|Rename
Dataset.  It is made general-purpose, rather than specifically
for that purpose, because it is not any harder to do so and might
be useful somewhere else in the future.

src/ui/gui/automake.mk
src/ui/gui/entry-dialog.c [new file with mode: 0644]
src/ui/gui/entry-dialog.h [new file with mode: 0644]
src/ui/gui/entry-dialog.ui [new file with mode: 0644]

index 5672b15ef59e20feb721bf330b2cdf6738feb826..8cefb9d915e6867357ff96edc200e0bc632d2288 100644 (file)
@@ -10,6 +10,7 @@ UI_FILES = \
        src/ui/gui/crosstabs.ui \
        src/ui/gui/chi-square.ui \
        src/ui/gui/descriptives.ui \
+       src/ui/gui/entry-dialog.ui \
        src/ui/gui/examine.ui \
        src/ui/gui/goto-case.ui \
        src/ui/gui/factor.ui \
@@ -144,6 +145,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/dialog-common.h \
        src/ui/gui/dict-display.h \
        src/ui/gui/dict-display.c \
+       src/ui/gui/entry-dialog.c \
+       src/ui/gui/entry-dialog.h \
        src/ui/gui/examine-dialog.c \
        src/ui/gui/examine-dialog.h \
        src/ui/gui/executor.c \
diff --git a/src/ui/gui/entry-dialog.c b/src/ui/gui/entry-dialog.c
new file mode 100644 (file)
index 0000000..148af74
--- /dev/null
@@ -0,0 +1,62 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2011 Free Software Foundation
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "ui/gui/entry-dialog.h"
+
+#include "ui/gui/helper.h"
+#include "ui/gui/psppire-dialog.h"
+
+#include "gl/xalloc.h"
+
+/* Creates a modal dialog with PARENT as its parent (this should be the
+   application window that the dialog is associated with), with TITLE as its
+   title, that prompts for a text string with PROMPT as the explanation and
+   DEFAULT_VALUE as the default value.
+
+   Returns a malloc()'d string owned by the caller if the user clicks on OK or
+   otherwise accepts a value, or NULL if the user cancels. */
+char *
+entry_dialog_run (GtkWindow *parent,
+                  const char *title,
+                  const char *prompt,
+                  const char *default_value)
+{
+  GtkBuilder *xml = builder_new ("entry-dialog.ui");
+  GtkWidget *dialog;
+  GtkWidget *label;
+  GtkWidget *entry;
+  char *result;
+
+  dialog = get_widget_assert (xml, "entry-dialog");
+  gtk_window_set_title (GTK_WINDOW (dialog), title);
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+
+  label = get_widget_assert (xml, "label");
+  gtk_label_set_text (GTK_LABEL (label), prompt);
+
+  entry = get_widget_assert (xml, "entry");
+  gtk_entry_set_text (GTK_ENTRY (entry), default_value);
+
+  result = (psppire_dialog_run (PSPPIRE_DIALOG (dialog)) == GTK_RESPONSE_OK
+            ? xstrdup (gtk_entry_get_text (GTK_ENTRY (entry)))
+            : NULL);
+
+  g_object_unref (xml);
+
+  return result;
+}
diff --git a/src/ui/gui/entry-dialog.h b/src/ui/gui/entry-dialog.h
new file mode 100644 (file)
index 0000000..8f71acd
--- /dev/null
@@ -0,0 +1,27 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2011 Free Software Foundation
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef ENTRY_DIALOG_H
+#define ENTRY_DIALOG_H 1
+
+#include <gtk/gtk.h>
+
+char *entry_dialog_run (GtkWindow *parent,
+                        const char *title,
+                        const char *prompt,
+                        const char *default_value);
+
+#endif /* ui/gui/entry-dialog.h */
diff --git a/src/ui/gui/entry-dialog.ui b/src/ui/gui/entry-dialog.ui
new file mode 100644 (file)
index 0000000..a0246cb
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="psppire" version="2054.17080"/>
+  <!-- interface-requires gtk+ 2.12 -->
+  <!-- interface-naming-policy project-wide -->
+  <object class="PsppireDialog" id="entry-dialog">
+    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+    <property name="modal">True</property>
+    <property name="orientation">Vertical</property>
+    <child internal-child="hbox">
+      <object class="GtkVBox" id="dialog-hbox8">
+        <property name="visible">True</property>
+        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+        <property name="spacing">5</property>
+       <child>
+         <object class="GtkLabel" id="label">
+            <property name="visible">True</property>
+            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+         </object>
+       </child>
+       <child>
+         <object class="GtkEntry" id="entry">
+            <property name="visible">True</property>
+            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+           <property name="activates-default">True</property>
+         </object>
+       </child>
+        <child>
+          <object class="PsppireHButtonBox" id="psppire-hbuttonbox5">
+            <property name="visible">True</property>
+            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+            <property name="border_width">5</property>
+            <property name="layout_style">spread</property>
+            <property name="buttons">PSPPIRE_BUTTON_OK_MASK | PSPPIRE_BUTTON_CANCEL_MASK</property>
+            <property name="default">PSPPIRE_BUTTON_OK_MASK</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>