X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fcompute-dialog.c;h=6f9ec222eb001764105850369bd8a7b6835e5b7f;hb=724be9e4720784aafeac395b3f6df47a89fc5e07;hp=6a3b0aaa75cdccb1d380539b86a3893c36db7147;hpb=0085c7edf6d3b9c9ee2ce880893023c567886101;p=pspp
diff --git a/src/ui/gui/compute-dialog.c b/src/ui/gui/compute-dialog.c
index 6a3b0aaa75..6f9ec222eb 100644
--- a/src/ui/gui/compute-dialog.c
+++ b/src/ui/gui/compute-dialog.c
@@ -1,5 +1,5 @@
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007 Free Software Foundation
+ Copyright (C) 2007, 2010, 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
@@ -14,39 +14,40 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
-
+#include
#include
#include "compute-dialog.h"
#include "helper.h"
#include "psppire-dialog.h"
#include "psppire-keypad.h"
-#include "data-editor.h"
-#include
+#include "psppire-data-window.h"
#include "psppire-var-store.h"
+#include "psppire-selector.h"
#include "dialog-common.h"
-#include "dict-display.h"
+#include
#include
-#include
-#include "syntax-editor.h"
+#include "executor.h"
static void function_list_populate (GtkTreeView *tv);
static void insert_function_into_syntax_area (GtkTreeIter iter,
GtkWidget *text_view,
- GtkTreeModel *model
+ GtkTreeModel *model,
+ gpointer data
);
static void insert_source_row_into_text_view (GtkTreeIter iter,
GtkWidget *dest,
- GtkTreeModel *model
+ GtkTreeModel *model,
+ gpointer data
);
struct compute_dialog
{
- GladeXML *xml; /* The xml that generated the widgets */
+ GtkBuilder *xml; /* The xml that generated the widgets */
PsppireDict *dict;
gboolean use_type;
};
@@ -112,7 +113,7 @@ erase_selection (GtkTextBuffer *buffer)
static void
on_keypad_button (PsppireKeypad *kp, const gchar *syntax, gpointer data)
{
- GladeXML *xml = data;
+ GtkBuilder *xml = data;
GtkWidget *rhs = get_widget_assert (xml, "compute-textview1");
@@ -136,7 +137,7 @@ on_keypad_button (PsppireKeypad *kp, const gchar *syntax, gpointer data)
static void
erase (PsppireKeypad *kp, gpointer data)
{
- GladeXML *xml = data;
+ GtkBuilder *xml = data;
GtkWidget *rhs = get_widget_assert (xml, "compute-textview1");
@@ -151,7 +152,7 @@ generate_syntax (const struct compute_dialog *cd)
gchar *text;
GString *string ;
const gchar *target_name ;
- const gchar *expression;
+ gchar *expression;
const gchar *label;
GtkTextIter start, end;
GtkWidget *target = get_widget_assert (cd->xml, "compute-entry1");
@@ -176,7 +177,7 @@ generate_syntax (const struct compute_dialog *cd)
string = g_string_sized_new (64);
- if ( cd-> use_type &&
+ if ( cd-> use_type &&
NULL == psppire_dict_lookup_var (cd->dict, target_name ))
{
if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (string_toggle)))
@@ -199,11 +200,16 @@ generate_syntax (const struct compute_dialog *cd)
target_name,
label);
- g_string_append_printf (string, "COMPUTE %s = %s.",
+ g_string_append_printf (string, "COMPUTE %s = %s.\n",
target_name,
expression
);
+ g_string_append (string, "EXECUTE.\n");
+
+
+ g_free (expression);
+
text = string->str;
g_string_free (string, FALSE);
@@ -318,26 +324,52 @@ on_expression_toggle (GtkToggleButton *button, gpointer data)
(GTK_ENTRY (get_widget_assert (cd->xml, "compute-entry1")));
target_var = psppire_dict_lookup_var (cd->dict, target_name);
- label = var_get_label (target_var);
+ if ( target_var )
+ {
+ label = var_get_label (target_var);
- if ( label )
- gtk_entry_set_text (GTK_ENTRY (entry), label);
+ if ( label )
+ gtk_entry_set_text (GTK_ENTRY (entry), label);
+ }
+ else
+ gtk_entry_set_text (GTK_ENTRY (entry), "");
gtk_widget_set_sensitive (entry, TRUE);
}
}
+
+/* Return TRUE if the dialog box's widgets' state are such that clicking OK
+ might not result in erroneous syntax being generated */
+static gboolean
+contents_plausible (gpointer data)
+{
+ struct compute_dialog *cd = data;
+
+ GtkWidget *target = get_widget_assert (cd->xml, "compute-entry1");
+ GtkWidget *syntax_area = get_widget_assert (cd->xml, "compute-textview1");
+ GtkTextBuffer *buffer =
+ gtk_text_view_get_buffer (GTK_TEXT_VIEW (syntax_area));
+
+ if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (target))))
+ return FALSE;
+
+ if ( gtk_text_buffer_get_char_count (buffer) == 0 )
+ return FALSE;
+
+ return TRUE;
+}
+
/* Pops up the Compute dialog box */
void
-compute_dialog (GObject *o, gpointer data)
+compute_dialog (PsppireDataWindow *de)
{
gint response;
- struct data_editor *de = data;
- PsppireVarStore *vs;
+ PsppireVarStore *vs = NULL;
struct compute_dialog scd;
- GladeXML *xml = XML_NEW ("psppire.glade");
+ GtkBuilder *xml = builder_new ("compute.ui");
GtkWidget *dialog = get_widget_assert (xml, "compute-variable-dialog");
@@ -345,7 +377,6 @@ compute_dialog (GObject *o, gpointer data)
GtkWidget *functions = get_widget_assert (xml, "compute-treeview2");
GtkWidget *keypad = get_widget_assert (xml, "psppire-keypad1");
GtkWidget *target = get_widget_assert (xml, "compute-entry1");
- GtkWidget *syntax_area = get_widget_assert (xml, "compute-textview1");
GtkWidget *var_selector = get_widget_assert (xml, "compute-selector1");
GtkWidget *func_selector = get_widget_assert (xml, "compute-selector2");
GtkWidget *type_and_label = get_widget_assert (xml, "compute-button1");
@@ -354,41 +385,33 @@ compute_dialog (GObject *o, gpointer data)
get_widget_assert (xml, "radio-button-expression-label");
- GtkSheet *var_sheet =
- GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
-
- vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
-
- scd.dict = vs->dict;
+ g_object_get (de->data_editor, "var-store", &vs, NULL);
+ g_object_get (vs, "dictionary", &scd.dict, NULL);
scd.use_type = FALSE;
g_signal_connect (expression, "toggled",
G_CALLBACK(on_expression_toggle), &scd);
- gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window);
-
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
- attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view),
- vs->dict,
- GTK_SELECTION_SINGLE, NULL);
-
-
- psppire_selector_set_subjects (PSPPIRE_SELECTOR (var_selector),
- dict_view, syntax_area,
- insert_source_row_into_text_view,
- NULL);
+
+ g_object_set (dict_view, "model", scd.dict,
+ "selection-mode", GTK_SELECTION_SINGLE,
+ NULL);
+ psppire_selector_set_select_func (PSPPIRE_SELECTOR (var_selector),
+ insert_source_row_into_text_view, NULL);
function_list_populate (GTK_TREE_VIEW (functions));
- psppire_selector_set_subjects (PSPPIRE_SELECTOR (func_selector),
- functions, syntax_area,
- insert_function_into_syntax_area,
- NULL);
-
+ psppire_selector_set_select_func (PSPPIRE_SELECTOR (func_selector),
+ insert_function_into_syntax_area, NULL);
scd.xml = xml;
+ psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
+ contents_plausible, &scd);
+
g_signal_connect (target, "changed", G_CALLBACK (on_target_change), &scd);
g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &scd);
@@ -411,25 +434,10 @@ compute_dialog (GObject *o, gpointer data)
switch (response)
{
case GTK_RESPONSE_OK:
- {
- gchar *syntax = generate_syntax (&scd);
- struct getl_interface *sss = create_syntax_string_source (syntax);
- execute_syntax (sss);
-
- g_free (syntax);
- }
+ g_free (execute_syntax_string (de, generate_syntax (&scd)));
break;
case PSPPIRE_RESPONSE_PASTE:
- {
- gchar *syntax = generate_syntax (&scd);
-
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
-
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
-
- g_free (syntax);
- }
+ g_free (paste_syntax_to_window (generate_syntax (&scd)));
break;
default:
break;
@@ -440,9 +448,9 @@ compute_dialog (GObject *o, gpointer data)
enum {
- COL_NAME,
- COL_USAGE,
- COL_ARITY
+ COMPUTE_COL_NAME,
+ COMPUTE_COL_USAGE,
+ COMPUTE_COL_ARITY
};
@@ -464,9 +472,9 @@ function_list_populate (GtkTreeView *tv)
gtk_list_store_append (liststore, &iter);
gtk_list_store_set (liststore, &iter,
- COL_NAME, expr_operation_get_name (op),
- COL_USAGE, expr_operation_get_prototype (op),
- COL_ARITY, expr_operation_get_arg_cnt (op),
+ COMPUTE_COL_NAME, expr_operation_get_name (op),
+ COMPUTE_COL_USAGE, expr_operation_get_prototype (op),
+ COMPUTE_COL_ARITY, expr_operation_get_arg_cnt (op),
-1);
}
@@ -487,7 +495,7 @@ function_list_populate (GtkTreeView *tv)
gtk_tree_view_column_pack_start (col, renderer, TRUE);
- gtk_tree_view_column_add_attribute (col, renderer, "text", COL_USAGE);
+ gtk_tree_view_column_add_attribute (col, renderer, "text", COMPUTE_COL_USAGE);
}
gtk_tree_view_set_model (tv, GTK_TREE_MODEL (liststore));
@@ -499,7 +507,8 @@ function_list_populate (GtkTreeView *tv)
static void
insert_function_into_syntax_area (GtkTreeIter iter,
GtkWidget *text_view,
- GtkTreeModel *model
+ GtkTreeModel *model,
+ gpointer data
)
{
GString *string;
@@ -514,8 +523,8 @@ insert_function_into_syntax_area (GtkTreeIter iter,
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
- gtk_tree_model_get_value (model, &iter, COL_NAME, &name_value);
- gtk_tree_model_get_value (model, &iter, COL_ARITY, &arity_value);
+ gtk_tree_model_get_value (model, &iter, COMPUTE_COL_NAME, &name_value);
+ gtk_tree_model_get_value (model, &iter, COMPUTE_COL_ARITY, &arity_value);
arity = g_value_get_int (&arity_value);
@@ -562,7 +571,8 @@ insert_function_into_syntax_area (GtkTreeIter iter,
static void
insert_source_row_into_text_view (GtkTreeIter iter,
GtkWidget *dest,
- GtkTreeModel *model
+ GtkTreeModel *model,
+ gpointer data
)
{
GtkTreePath *path;
@@ -570,7 +580,6 @@ insert_source_row_into_text_view (GtkTreeIter iter,
gint *idx;
struct variable *var;
GtkTreeIter dict_iter;
- gchar *name;
GtkTextBuffer *buffer;
g_return_if_fail (GTK_IS_TEXT_VIEW (dest));
@@ -598,13 +607,10 @@ insert_source_row_into_text_view (GtkTreeIter iter,
gtk_tree_path_free (path);
- name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL);
-
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dest));
erase_selection (buffer);
- gtk_text_buffer_insert_at_cursor (buffer, name, -1);
+ gtk_text_buffer_insert_at_cursor (buffer, var_get_name (var), -1);
- g_free (name);
}