From: John Darrington Date: Tue, 31 Jan 2012 20:19:41 +0000 (+0100) Subject: Converted Sort dialog to a PsppireDialogAction object X-Git-Tag: v0.7.9~3 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24ab436df2f3f115c1cb949dbf0a932cda7667b2;p=pspp-builds.git Converted Sort dialog to a PsppireDialogAction object --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 630a8d99..770a5a9a 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -216,6 +216,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog-action-kmeans.h \ src/ui/gui/psppire-dialog-action-reliability.c \ src/ui/gui/psppire-dialog-action-reliability.h \ + src/ui/gui/psppire-dialog-action-sort.c \ + src/ui/gui/psppire-dialog-action-sort.h \ src/ui/gui/psppire-dialog-action-var-info.c \ src/ui/gui/psppire-dialog-action-var-info.h \ src/ui/gui/psppire-dialog-action-roc.c \ @@ -262,8 +264,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/runs-dialog.h \ src/ui/gui/select-cases-dialog.c \ src/ui/gui/select-cases-dialog.h \ - src/ui/gui/sort-cases-dialog.c \ - src/ui/gui/sort-cases-dialog.h \ src/ui/gui/split-file-dialog.c \ src/ui/gui/split-file-dialog.h \ src/ui/gui/text-data-import-dialog.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 46bb823b..88449fb7 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -238,9 +238,10 @@ - + _Sort Cases... data_sort-cases + uimanager1 gtk-sort-ascending Sort cases in the active dataset diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 13e9614c..1ca71f79 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -56,7 +56,6 @@ #include "ui/gui/recode-dialog.h" #include "ui/gui/regression-dialog.h" #include "ui/gui/select-cases-dialog.h" -#include "ui/gui/sort-cases-dialog.h" #include "ui/gui/split-file-dialog.h" #include "ui/gui/t-test-independent-samples-dialog.h" #include "ui/gui/t-test-one-sample.h" @@ -1064,8 +1063,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "data_select-cases", G_CALLBACK (select_cases_dialog)); - connect_action (de, "data_sort-cases", G_CALLBACK (sort_cases_dialog)); - connect_action (de, "data_aggregate", G_CALLBACK (aggregate_dialog)); connect_action (de, "transform_compute", G_CALLBACK (compute_dialog)); diff --git a/src/ui/gui/psppire-dialog-action-sort.c b/src/ui/gui/psppire-dialog-action-sort.c new file mode 100644 index 00000000..2a80a6e7 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-sort.c @@ -0,0 +1,128 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2012 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 "psppire-dialog-action-sort.h" + +#include "psppire-var-view.h" + +#include "psppire-dialog.h" +#include "builder-wrapper.h" + +static void psppire_dialog_action_sort_init (PsppireDialogActionSort *act); +static void psppire_dialog_action_sort_class_init (PsppireDialogActionSortClass *class); + +G_DEFINE_TYPE (PsppireDialogActionSort, psppire_dialog_action_sort, PSPPIRE_TYPE_DIALOG_ACTION); + +static char * +generate_syntax (PsppireDialogAction *act) +{ + PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act); + gchar *text; + GString *string = g_string_new ("SORT CASES BY "); + + gint n_vars = psppire_var_view_append_names (scd->variables, 0, string); + + if ( n_vars == 0 ) + { + g_string_assign (string, ""); + } + else + { + const char up_down = + gtk_toggle_button_get_active (scd->ascending) ? 'A' : 'D'; + g_string_append_printf (string, "(%c)", up_down); + g_string_append (string, "."); + } + + text = string->str; + + g_string_free (string, FALSE); + + return text; +} + +static void +reset (PsppireDialogAction *act) +{ + PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act); + + GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->variables)); + + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + + gtk_toggle_button_set_active (scd->ascending, TRUE); +} + + + + +static gboolean +dialog_state_valid (PsppireDialogAction *act) +{ + PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act); + GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->variables)); + + gint n_rows = gtk_tree_model_iter_n_children (model, NULL); + + if ( n_rows == 0 ) + return FALSE; + + return TRUE; +} + + +static void +psppire_dialog_action_sort_activate (GtkAction *a) +{ + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + PsppireDialogActionSort *act = PSPPIRE_DIALOG_ACTION_SORT (a); + + GtkBuilder *xml = builder_new ("sort.ui"); + pda->dialog = get_widget_assert (xml, "sort-cases-dialog"); + pda->source = get_widget_assert (xml, "sort-cases-treeview1"); + + act->variables = get_widget_assert (xml, "sort-cases-treeview2"); + act->ascending = get_widget_assert (xml, "sort-cases-radiobutton0"); + + psppire_dialog_action_set_refresh (pda, reset); + + psppire_dialog_action_set_valid_predicate (pda, + dialog_state_valid); + + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_sort_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_sort_parent_class)->activate (pda); +} + +static void +psppire_dialog_action_sort_class_init (PsppireDialogActionSortClass *class) +{ + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + PsppireDialogActionClass *pdac = PSPPIRE_DIALOG_ACTION_CLASS (class); + + action_class->activate = psppire_dialog_action_sort_activate; + + pdac->generate_syntax = generate_syntax; +} + + +static void +psppire_dialog_action_sort_init (PsppireDialogActionSort *act) +{ +} + diff --git a/src/ui/gui/psppire-dialog-action-sort.h b/src/ui/gui/psppire-dialog-action-sort.h new file mode 100644 index 00000000..3ab66990 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-sort.h @@ -0,0 +1,78 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2012 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 + +#include "psppire-dialog-action.h" + +#ifndef __PSPPIRE_DIALOG_ACTION_SORT_H__ +#define __PSPPIRE_DIALOG_ACTION_SORT_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_SORT (psppire_dialog_action_sort_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_SORT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_SORT, PsppireDialogActionSort)) + +#define PSPPIRE_DIALOG_ACTION_SORT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_SORT, \ + PsppireDialogActionSortClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_SORT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_SORT)) + +#define PSPPIRE_IS_DIALOG_ACTION_SORT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_SORT)) + + +#define PSPPIRE_DIALOG_ACTION_SORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_SORT, \ + PsppireDialogActionSortClass)) + +typedef struct _PsppireDialogActionSort PsppireDialogActionSort; +typedef struct _PsppireDialogActionSortClass PsppireDialogActionSortClass; + + +struct _PsppireDialogActionSort +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + GtkWidget *variables; + GtkWidget *ascending; +}; + + +struct _PsppireDialogActionSortClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_sort_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_SORT_H__ */ diff --git a/src/ui/gui/sort-cases-dialog.c b/src/ui/gui/sort-cases-dialog.c deleted file mode 100644 index 62d738c9..00000000 --- a/src/ui/gui/sort-cases-dialog.c +++ /dev/null @@ -1,143 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2010, 2011, 2012 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 -#include "sort-cases-dialog.h" -#include "executor.h" -#include "psppire-dialog.h" -#include "psppire-data-window.h" -#include "psppire-var-store.h" -#include "dialog-common.h" -#include "psppire-selector.h" -#include "dict-display.h" -#include "psppire-var-view.h" - -#include "builder-wrapper.h" -#include "helper.h" - - -static void -refresh (PsppireDialog *dialog, GtkTreeView *dest) -{ - GtkTreeModel *liststore = gtk_tree_view_get_model (dest); - - gtk_list_store_clear (GTK_LIST_STORE (liststore)); -} - - -struct sort_cases_dialog -{ - PsppireVarView *tv; - PsppireDict *dict; - GtkToggleButton *ascending; -}; - - -static gboolean -dialog_state_valid (gpointer data) -{ - struct sort_cases_dialog *scd = data; - GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->tv)); - - gint n_rows = gtk_tree_model_iter_n_children (model, NULL); - - if ( n_rows == 0 ) - return FALSE; - - return TRUE; -} - -static char * -generate_syntax (const struct sort_cases_dialog *scd) -{ - gchar *text; - GString *string = g_string_new ("SORT CASES BY "); - - gint n_vars = psppire_var_view_append_names (scd->tv, 0, string); - - if ( n_vars == 0 ) - g_string_assign (string, ""); - else - { - const char up_down = - gtk_toggle_button_get_active (scd->ascending) ? 'A' : 'D'; - g_string_append_printf (string, "(%c)", up_down); - g_string_append (string, "."); - } - - - text = string->str; - - g_string_free (string, FALSE); - - return text; -} - - -/* Pops up the Sort Cases dialog box */ -void -sort_cases_dialog (PsppireDataWindow *de) -{ - gint response; - - struct sort_cases_dialog scd; - - GtkBuilder *xml = builder_new ("sort.ui"); - - GtkWidget *dialog = get_widget_assert (xml, "sort-cases-dialog"); - - - GtkWidget *source = get_widget_assert (xml, "sort-cases-treeview1"); - GtkWidget *dest = get_widget_assert (xml, "sort-cases-treeview2"); - PsppireVarStore *vs = NULL; - - g_object_get (de->data_editor, "var-store", &vs, NULL); - - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - - g_object_get (vs, "dictionary", &scd.dict, NULL); - g_object_set (source, "model", scd.dict, NULL); - - g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), dest); - - scd.tv = PSPPIRE_VAR_VIEW (dest); - scd.ascending = - GTK_TOGGLE_BUTTON (get_widget_assert (xml, "sort-cases-radiobutton0")); - - - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &scd); - - - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); - - - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (de, generate_syntax (&scd))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&scd))); - break; - default: - break; - } - - g_object_unref (xml); -} - diff --git a/src/ui/gui/sort-cases-dialog.h b/src/ui/gui/sort-cases-dialog.h deleted file mode 100644 index 0c2814f1..00000000 --- a/src/ui/gui/sort-cases-dialog.h +++ /dev/null @@ -1,24 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007 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 __SORT_CASES_DIALOG_H -#define __SORT_CASES_DIALOG_H - -#include "psppire-data-window.h" - -void sort_cases_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 9ea17e9f..9f21486f 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -18,6 +18,7 @@ #include "psppire-dialog-action-kmeans.h" #include "psppire-dialog-action-reliability.h" #include "psppire-dialog-action-roc.h" +#include "psppire-dialog-action-sort.h" #include "psppire-dialog-action-var-info.h" @@ -43,4 +44,5 @@ preregister_widgets (void) psppire_dialog_action_var_info_get_type (); psppire_dialog_action_reliability_get_type (); psppire_dialog_action_roc_get_type (); + psppire_dialog_action_sort_get_type (); }