X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fmenu-actions.c;h=98d00f63af619c94c5c73504a024b3dce976ce6b;hb=57b436a22d9ae0e395fb2e3ce101c2b5c2e6939e;hp=c23beb49a872c5d02c55ec007384a4fd038045ed;hpb=b64685d06f8db1aff292ec409abe25f8a483d775;p=pspp diff --git a/src/ui/gui/menu-actions.c b/src/ui/gui/menu-actions.c index c23beb49a8..98d00f63af 100644 --- a/src/ui/gui/menu-actions.c +++ b/src/ui/gui/menu-actions.c @@ -1,6 +1,6 @@ /* PSPPIRE --- A Graphical User Interface for PSPP - Copyright (C) 2004, 2005 Free Software Foundation + Copyright (C) 2004, 2005, 2006 Free Software Foundation Written by John Darrington This program is free software; you can redistribute it and/or modify @@ -24,7 +24,9 @@ #define _(msgid) gettext (msgid) #define N_(msgid) msgid +#include +#include #include #include #include @@ -32,6 +34,8 @@ #include #include +#include + #include #include "helper.h" #include "menu-actions.h" @@ -44,14 +48,13 @@ #include "psppire-var-store.h" #include "psppire-data-store.h" +#include "sort-cases-dialog.h" extern GladeXML *xml; extern PsppireDict *the_dictionary ; -extern PsppireCaseArray *the_cases ; - static struct file_handle *psppire_handle = 0; @@ -75,20 +78,32 @@ psppire_set_window_title(const gchar *text) g_free(title); } - +/* Clear the active file and set the data and var sheets to + reflect this. + */ gboolean clear_file(void) { - GtkWidget *data_sheet = get_widget_assert(xml, "data_sheet"); - GtkWidget *var_sheet = get_widget_assert(xml, "variable_sheet"); - - gtk_sheet_set_active_cell(GTK_SHEET(data_sheet), -1, -1); + PsppireDataStore *data_store ; + GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet")); + GtkSheet *var_sheet = GTK_SHEET(get_widget_assert(xml, "variable_sheet")); - gtk_sheet_set_active_cell(GTK_SHEET(var_sheet), 0, 0); + gtk_sheet_set_active_cell(data_sheet, -1, -1); + gtk_sheet_set_active_cell(var_sheet, 0, 0); + + if ( GTK_WIDGET_REALIZED(GTK_WIDGET(data_sheet))) + gtk_sheet_unselect_range(data_sheet); + + if ( GTK_WIDGET_REALIZED(GTK_WIDGET(var_sheet))) + gtk_sheet_unselect_range(var_sheet); + + gtk_sheet_moveto(data_sheet, 0, 0, 0.0, 0.0); + gtk_sheet_moveto(var_sheet, 0, 0, 0.0, 0.0); + + data_store = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet)); + + psppire_data_store_clear(data_store); - psppire_dict_clear(the_dictionary); - psppire_case_array_clear(the_cases); - psppire_set_window_title(gettext(untitled)); if (psppire_handle) @@ -107,23 +122,13 @@ on_new1_activate (GtkMenuItem *menuitem, -static gboolean -populate_case_from_reader(struct ccase *c, gpointer aux) -{ - struct sfm_reader *reader = aux; - - return sfm_read_case(reader, c); -} - - /* Load a system file. Return TRUE if successfull */ gboolean load_system_file(const gchar *file_name) { - int ni ; - gint case_num; + int var_cnt ; PsppireVarStore *var_store ; PsppireDataStore *data_store ; @@ -134,12 +139,10 @@ load_system_file(const gchar *file_name) GtkWidget *data_sheet = get_widget_assert(xml, "data_sheet"); GtkWidget *var_sheet = get_widget_assert(xml, "variable_sheet"); - g_assert(data_sheet); g_assert(var_sheet); - if ( psppire_handle ) - fh_free(psppire_handle); + clear_file(); psppire_handle = fh_create_file (handle_name, file_name, fh_default_properties()); @@ -151,7 +154,6 @@ load_system_file(const gchar *file_name) return FALSE; } - reader = sfm_open_reader (psppire_handle, &new_dict, &ri); if ( ! reader ) @@ -172,25 +174,34 @@ load_system_file(const gchar *file_name) psppire_data_store_set_dictionary(data_store, the_dictionary); - psppire_case_array_clear(data_store->cases); - - psppire_set_window_title(basename(file_name)); - ni = dict_get_next_value_idx(the_dictionary->dict); - if ( ni == 0 ) + var_cnt = dict_get_next_value_idx(the_dictionary->dict); + if ( var_cnt == 0 ) return FALSE; - for(case_num=0;;case_num++) + + for(;;) { - if (!psppire_case_array_append_case(the_cases, - populate_case_from_reader, - reader)) - break; + struct ccase c; + case_create(&c, var_cnt); + if ( 0 == sfm_read_case (reader, &c) ) + { + case_destroy(&c); + break; + } + + if ( !psppire_case_file_append_case(data_store->case_file, &c) ) + { + g_warning("Cannot write case to casefile\n"); + break; + } + case_destroy(&c); } + + sfm_close_reader(reader); - - sfm_close_reader(reader); + psppire_case_file_get_case_count(data_store->case_file); return TRUE; } @@ -332,58 +343,61 @@ on_quit1_activate (GtkMenuItem *menuitem, void -on_cut1_activate (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -on_copy1_activate (GtkMenuItem *menuitem, - gpointer user_data) +on_clear_activate (GtkMenuItem *menuitem, + gpointer user_data) { + GtkNotebook *notebook = GTK_NOTEBOOK(get_widget_assert(xml, "notebook1")); + gint page = -1; -} - - -void -on_paste1_activate (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - -/* Fill a case with SYSMIS for numeric and whitespace for string - variables respectively */ -static gboolean -blank_case(struct ccase *cc, gpointer _dict) -{ - gint i; - PsppireDict *dict = _dict; + page = gtk_notebook_get_current_page(notebook); - for(i = 0 ; i < psppire_dict_get_var_cnt(dict); ++i ) + switch (page) { - union value *val ; - - const struct PsppireVariable *var = psppire_dict_get_variable(dict, i); - - gint idx = psppire_variable_get_index(var); - - val = case_data_rw(cc, idx) ; + case PAGE_DATA_SHEET: + { + GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet")); + PsppireDataStore *data_store = + PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet)); + - if ( psppire_variable_get_type(var) == ALPHA ) - memset(val->s, ' ', psppire_variable_get_width(var)); - else - val->f = SYSMIS; + switch ( data_sheet->state ) + { + case GTK_SHEET_ROW_SELECTED: + psppire_case_file_delete_cases(data_store->case_file, + data_sheet->range.rowi + - data_sheet->range.row0 + 1, + data_sheet->range.row0); + break; + case GTK_SHEET_COLUMN_SELECTED: + { + gint fv; + struct PsppireVariable *pv = + psppire_dict_get_variable(the_dictionary, + data_sheet->range.col0); + fv = psppire_variable_get_fv(pv); + + + psppire_dict_delete_variables(the_dictionary, + data_sheet->range.col0, + 1); + + psppire_case_file_insert_values(data_store->case_file, + -1, fv); + } + break; + default: + gtk_sheet_cell_clear(data_sheet, + data_sheet->active_cell.row, + data_sheet->active_cell.col); + break; + } - case_unshare(cc); + } + break; } - return TRUE; } - void on_insert1_activate (GtkMenuItem *menuitem, gpointer user_data) @@ -396,6 +410,7 @@ on_insert1_activate (GtkMenuItem *menuitem, switch (page) { case PAGE_DATA_SHEET: +#if 0 { GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet")); PsppireDataStore *data_store = @@ -406,6 +421,7 @@ on_insert1_activate (GtkMenuItem *menuitem, blank_case, the_dictionary); } break; +#endif case PAGE_VAR_SHEET: { GtkSheet *var_sheet = @@ -420,6 +436,7 @@ on_insert1_activate (GtkMenuItem *menuitem, } } +#if 0 void on_delete1_activate (GtkMenuItem *menuitem, gpointer user_data) @@ -430,6 +447,7 @@ on_delete1_activate (GtkMenuItem *menuitem, page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); switch ( page) { +#if 0 case PAGE_DATA_SHEET: { GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet")); @@ -442,6 +460,7 @@ on_delete1_activate (GtkMenuItem *menuitem, - data_sheet->range.row0 ); } break; +#endif case PAGE_VAR_SHEET: { GtkSheet *var_sheet = @@ -458,7 +477,7 @@ on_delete1_activate (GtkMenuItem *menuitem, break; } } - +#endif void on_about1_activate(GtkMenuItem *menuitem, @@ -478,25 +497,40 @@ on_about1_activate(GtkMenuItem *menuitem, } - +/* Set the value labels state from the toolbar's toggle button */ void -on_toolbars1_activate - (GtkMenuItem *menuitem, - gpointer user_data) +on_togglebutton_value_labels_toggled(GtkToggleToolButton *toggle_tool_button, + gpointer user_data) { + GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet")); + GtkCheckMenuItem *item = + GTK_CHECK_MENU_ITEM(get_widget_assert(xml, "menuitem-value-labels")); + PsppireDataStore *ds = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet)); + + gboolean show_value_labels = gtk_toggle_tool_button_get_active(toggle_tool_button); + + gtk_check_menu_item_set_active(item, show_value_labels); + psppire_data_store_show_labels(ds, show_value_labels); } +/* Set the value labels state from the view menu */ void -on_value_labels1_activate(GtkCheckMenuItem *menuitem, +on_value_labels_activate(GtkCheckMenuItem *menuitem, gpointer user_data) { GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet")); + GtkToggleToolButton *tb = + GTK_TOGGLE_TOOL_BUTTON(get_widget_assert(xml, "togglebutton-value-labels")); + PsppireDataStore *ds = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet)); - - psppire_data_store_show_labels(ds, - gtk_check_menu_item_get_active(menuitem)); + + gboolean show_value_labels = gtk_check_menu_item_get_active(menuitem); + + gtk_toggle_tool_button_set_active(tb, show_value_labels); + + psppire_data_store_show_labels(ds, show_value_labels); } void @@ -569,15 +603,22 @@ static GtkNotebook *notebook = 0; static void switch_menus(gint page) { + GtkWidget *insert_variable = get_widget_assert(xml, "insert-variable"); + GtkWidget *insert_cases = get_widget_assert(xml, "insert-cases"); + switch (page) { case PAGE_VAR_SHEET: gtk_widget_hide(menuitems[PAGE_VAR_SHEET]); gtk_widget_show(menuitems[PAGE_DATA_SHEET]); + gtk_widget_set_sensitive(insert_variable, TRUE); + gtk_widget_set_sensitive(insert_cases, FALSE); break; case PAGE_DATA_SHEET: gtk_widget_show(menuitems[PAGE_VAR_SHEET]); gtk_widget_hide(menuitems[PAGE_DATA_SHEET]); + gtk_widget_set_sensitive(insert_variable, FALSE); + gtk_widget_set_sensitive(insert_cases, TRUE); break; default: g_assert_not_reached(); @@ -639,3 +680,109 @@ on_variables1_activate(GtkMenuItem *menuitem, select_sheet(PAGE_VAR_SHEET); } + + +void +on_go_to_case_activate(GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkWidget *dialog = get_widget_assert(xml, "go_to_case_dialog"); + GtkEntry *entry = GTK_ENTRY(get_widget_assert(xml, "entry_go_to_case")); + GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet")); + + gint result = gtk_dialog_run(GTK_DIALOG(dialog)); + + + + switch (result) + { + case GTK_RESPONSE_OK: + { + gint row, column; + const gchar *text = gtk_entry_get_text(entry); + gint casenum = g_strtod(text, NULL); + + gtk_sheet_get_active_cell(data_sheet, &row, &column); + if ( column < 0 ) column = 0; + if ( row < 0 ) row = 0; + + gtk_sheet_set_active_cell(data_sheet, casenum, column); + } + break; + default: + break; + } + + gtk_widget_hide(dialog); + gtk_entry_set_text(entry, ""); +} + + + +void +on_sort_cases_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + gint response; + PsppireDataStore *data_store ; + + struct sort_criteria criteria; + static struct sort_cases_dialog *dialog ; + + GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet")); + + data_store = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet)); + + if ( NULL == dialog) + dialog = sort_cases_dialog_create(xml); + + response = sort_cases_dialog_run(dialog, the_dictionary, &criteria); + + switch ( response) + { + case GTK_RESPONSE_OK: + psppire_case_file_sort(data_store->case_file, &criteria); + break; + } +} + + +static void +insert_case(void) +{ + gint row, col; + PsppireDataStore *data_store ; + GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet")); + + data_store = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet)); + + gtk_sheet_get_active_cell(data_sheet, &row, &col); + + psppire_case_file_insert_case(data_store->case_file, row); +} + +void +on_insert_case_clicked (GtkButton *button, gpointer user_data) +{ + insert_case(); +} + +void +on_insert_cases (GtkMenuItem *menuitem, gpointer user_data) +{ + insert_case(); +} + + +void +on_insert_variable (GtkMenuItem *menuitem, gpointer user_data) +{ + gint row, col; + GtkSheet *var_sheet = GTK_SHEET(get_widget_assert(xml, "variable_sheet")); + + gtk_sheet_get_active_cell(var_sheet, &row, &col); + + psppire_dict_insert_variable(the_dictionary, row, NULL); +} + +