From: Ben Pfaff Date: Sun, 1 May 2011 04:08:01 +0000 (-0700) Subject: gui: New "entry-dialog" module for prompting for a text string. X-Git-Tag: v0.7.8~6 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aafb6add9344c71c4fed343e52e9a67aa6efdf91;p=pspp-builds.git gui: New "entry-dialog" module for prompting for a text string. 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. --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 5672b15e..8cefb9d9 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 00000000..148af744 --- /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 . */ + +#include + +#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 00000000..8f71acde --- /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 . */ + +#ifndef ENTRY_DIALOG_H +#define ENTRY_DIALOG_H 1 + +#include + +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 00000000..a0246cbe --- /dev/null +++ b/src/ui/gui/entry-dialog.ui @@ -0,0 +1,47 @@ + + + + + + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + Vertical + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + spread + PSPPIRE_BUTTON_OK_MASK | PSPPIRE_BUTTON_CANCEL_MASK + PSPPIRE_BUTTON_OK_MASK + + + False + False + end + 1 + + + + + +