pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[entry-dialog 2/2] gui: New "entry-dialog" module for prompting for a te


From: Ben Pfaff
Subject: [entry-dialog 2/2] gui: New "entry-dialog" module for prompting for a text string.
Date: Tue, 3 May 2011 07:57:39 -0700

This will be used in an upcoming commit to implement File|Rename
Dataset.
---
 src/ui/gui/automake.mk     |    3 ++
 src/ui/gui/entry-dialog.c  |   62 ++++++++++++++++++++++++++++++++++++++++++++
 src/ui/gui/entry-dialog.h  |   27 +++++++++++++++++++
 src/ui/gui/entry-dialog.ui |   47 +++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+), 0 deletions(-)
 create mode 100644 src/ui/gui/entry-dialog.c
 create mode 100644 src/ui/gui/entry-dialog.h
 create mode 100644 src/ui/gui/entry-dialog.ui

diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk
index 5672b15..8cefb9d 100644
--- a/src/ui/gui/automake.mk
+++ b/src/ui/gui/automake.mk
@@ -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
index 0000000..148af74
--- /dev/null
+++ b/src/ui/gui/entry-dialog.c
@@ -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
index 0000000..8f71acd
--- /dev/null
+++ b/src/ui/gui/entry-dialog.h
@@ -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
index 0000000..a0246cb
--- /dev/null
+++ b/src/ui/gui/entry-dialog.ui
@@ -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>
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]