2 PSPPIRE --- A Graphical User Interface for PSPP
3 Copyright (C) 2006, 2007 Free Software Foundation
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <glade/glade.h>
27 #include "window-manager.h"
28 #include <gtksheet/gtksheet.h>
32 #include "psppire-dialog.h"
33 #include "psppire-selector.h"
34 #include "weight-cases-dialog.h"
35 #include "transpose-dialog.h"
36 #include "dict-display.h"
38 #define _(msgid) gettext (msgid)
39 #define N_(msgid) msgid
41 #include "data-editor.h"
42 #include "syntax-editor.h"
43 #include <language/syntax-string-source.h>
44 #include "window-manager.h"
46 #include "psppire-data-store.h"
47 #include "psppire-var-store.h"
49 static void register_data_editor_actions (struct data_editor *de);
51 static void insert_variable (GtkCheckMenuItem *m, gpointer data);
54 /* Switch between the VAR SHEET and the DATA SHEET */
55 enum {PAGE_DATA_SHEET = 0, PAGE_VAR_SHEET};
57 static gboolean click2column (GtkWidget *w, gint col, gpointer data);
59 static gboolean click2row (GtkWidget *w, gint row, gpointer data);
62 static void select_sheet (struct data_editor *de, guint page_num);
65 /* Callback for when the dictionary changes properties*/
66 static void on_weight_change (GObject *, gint, gpointer);
67 static void on_filter_change (GObject *, gint, gpointer);
68 static void on_split_change (PsppireDict *, gpointer);
70 static void data_var_select (GtkNotebook *notebook,
71 GtkNotebookPage *page,
75 static void status_bar_activate (GtkCheckMenuItem *, gpointer);
77 static void grid_lines_activate (GtkCheckMenuItem *, gpointer);
79 static void data_sheet_activate (GtkCheckMenuItem *, gpointer);
81 static void variable_sheet_activate (GtkCheckMenuItem *, gpointer );
83 static void fonts_activate (GtkMenuItem *, gpointer);
85 static void value_labels_activate (GtkCheckMenuItem *, gpointer);
86 static void value_labels_toggled (GtkToggleToolButton *, gpointer);
89 static void file_quit (GtkCheckMenuItem *, gpointer );
91 static void on_clear_activate (GtkMenuItem *, gpointer);
94 enable_edit_clear (GtkWidget *w, gint row, gpointer data)
96 struct data_editor *de = data;
98 GtkWidget *menuitem = get_widget_assert (de->xml, "edit_clear");
100 gtk_widget_set_sensitive (menuitem, TRUE);
104 disable_edit_clear (GtkWidget *w, gint x, gint y, gpointer data)
106 struct data_editor *de = data;
108 GtkWidget *menuitem = get_widget_assert (de->xml, "edit_clear");
110 gtk_widget_set_sensitive (menuitem, FALSE);
117 Create a new data editor.
120 new_data_editor (void)
122 struct data_editor *de ;
123 struct editor_window *e;
124 GtkSheet *var_sheet ;
127 de = g_malloc0 (sizeof (*de));
129 e = (struct editor_window *) de;
131 de->xml = glade_xml_new (PKGDATADIR "/data-editor.glade", NULL, NULL);
134 var_sheet = GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
136 vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
138 g_assert(vs); /* Traps a possible bug in win32 build */
140 g_signal_connect (vs->dict, "weight-changed",
141 G_CALLBACK (on_weight_change),
144 g_signal_connect (vs->dict, "filter-changed",
145 G_CALLBACK (on_filter_change),
148 g_signal_connect (vs->dict, "split-changed",
149 G_CALLBACK (on_split_change),
152 connect_help (de->xml);
155 register_data_editor_actions (de);
157 de->invoke_weight_cases_dialog =
158 gtk_action_new ("weight-cases-dialog",
160 _("Weight cases by variable"),
161 "pspp-weight-cases");
163 g_signal_connect (de->invoke_weight_cases_dialog, "activate",
164 G_CALLBACK (weight_cases_dialog), de);
167 de->invoke_transpose_dialog =
168 gtk_action_new ("transpose-dialog",
170 _("Transpose the cases with the variables"),
174 g_signal_connect (de->invoke_transpose_dialog, "activate",
175 G_CALLBACK (transpose_dialog), de);
178 e->window = GTK_WINDOW (get_widget_assert (de->xml, "data_editor"));
180 g_signal_connect_swapped (get_widget_assert (de->xml,"file_new_data"),
182 G_CALLBACK (gtk_action_activate),
183 de->action_data_new);
185 g_signal_connect_swapped (get_widget_assert (de->xml,"file_open_data"),
187 G_CALLBACK (gtk_action_activate),
188 de->action_data_open);
190 g_signal_connect (get_widget_assert (de->xml,"file_new_syntax"),
192 G_CALLBACK (new_syntax_window),
195 g_signal_connect (get_widget_assert (de->xml,"file_open_syntax"),
197 G_CALLBACK (open_syntax_window),
200 g_signal_connect_swapped (get_widget_assert (de->xml,"file_save"),
202 G_CALLBACK (gtk_action_activate),
203 de->action_data_save);
205 g_signal_connect_swapped (get_widget_assert (de->xml,"file_save_as"),
207 G_CALLBACK (gtk_action_activate),
208 de->action_data_save_as);
211 g_signal_connect (get_widget_assert (de->xml,"edit_clear"),
213 G_CALLBACK (on_clear_activate),
217 g_signal_connect (get_widget_assert (de->xml,"data_insert-variable"),
219 G_CALLBACK (insert_variable),
222 gtk_action_connect_proxy (de->invoke_weight_cases_dialog,
223 get_widget_assert (de->xml, "data_weight-cases")
226 gtk_action_connect_proxy (de->invoke_transpose_dialog,
227 get_widget_assert (de->xml, "data_transpose")
230 g_signal_connect (get_widget_assert (de->xml,"help_about"),
232 G_CALLBACK (about_new),
236 g_signal_connect (get_widget_assert (de->xml,"help_reference"),
238 G_CALLBACK (reference_manual),
243 g_signal_connect (get_widget_assert (de->xml,"data_sheet"),
244 "double-click-column",
245 G_CALLBACK (click2column),
249 g_signal_connect (get_widget_assert (de->xml, "variable_sheet"),
251 GTK_SIGNAL_FUNC (click2row),
255 g_signal_connect (get_widget_assert (de->xml, "variable_sheet"),
257 GTK_SIGNAL_FUNC (enable_edit_clear),
260 g_signal_connect (get_widget_assert (de->xml, "variable_sheet"),
262 GTK_SIGNAL_FUNC (disable_edit_clear),
266 g_signal_connect (get_widget_assert (de->xml, "notebook"),
268 G_CALLBACK (data_var_select), de);
272 g_signal_connect (get_widget_assert (de->xml, "view_statusbar"),
274 G_CALLBACK (status_bar_activate), de);
277 g_signal_connect (get_widget_assert (de->xml, "view_gridlines"),
279 G_CALLBACK (grid_lines_activate), de);
283 g_signal_connect (get_widget_assert (de->xml, "view_data"),
285 G_CALLBACK (data_sheet_activate), de);
287 g_signal_connect (get_widget_assert (de->xml, "view_variables"),
289 G_CALLBACK (variable_sheet_activate), de);
293 g_signal_connect (get_widget_assert (de->xml, "view_fonts"),
295 G_CALLBACK (fonts_activate), de);
299 g_signal_connect (get_widget_assert (de->xml, "view_valuelabels"),
301 G_CALLBACK (value_labels_activate), de);
304 g_signal_connect (get_widget_assert (de->xml, "togglebutton-value-labels"),
306 G_CALLBACK (value_labels_toggled), de);
308 gtk_action_connect_proxy (de->action_data_open,
309 get_widget_assert (de->xml, "button-open")
312 gtk_action_connect_proxy (de->action_data_save,
313 get_widget_assert (de->xml, "button-save")
316 gtk_action_connect_proxy (de->invoke_weight_cases_dialog,
317 get_widget_assert (de->xml, "button-weight-cases")
320 g_signal_connect (get_widget_assert (de->xml, "file_quit"),
322 G_CALLBACK (file_quit), de);
325 g_signal_connect (get_widget_assert (de->xml, "windows_minimise_all"),
327 G_CALLBACK (minimise_all_windows), NULL);
330 select_sheet (de, PAGE_DATA_SHEET);
336 /* Callback which occurs when the var sheet's row title
337 button is double clicked */
339 click2row (GtkWidget *w, gint row, gpointer data)
341 struct data_editor *de = data;
343 gint current_row, current_column;
345 GtkWidget *data_sheet = get_widget_assert (de->xml, "data_sheet");
347 data_editor_select_sheet (de, PAGE_DATA_SHEET);
349 gtk_sheet_get_active_cell (GTK_SHEET (data_sheet),
350 ¤t_row, ¤t_column);
352 gtk_sheet_set_active_cell (GTK_SHEET (data_sheet), current_row, row);
358 /* Callback which occurs when the data sheet's column title
361 click2column (GtkWidget *w, gint col, gpointer data)
363 struct data_editor *de = data;
365 gint current_row, current_column;
367 GtkWidget *var_sheet = get_widget_assert (de->xml, "variable_sheet");
369 data_editor_select_sheet (de, PAGE_VAR_SHEET);
371 gtk_sheet_get_active_cell (GTK_SHEET (var_sheet),
372 ¤t_row, ¤t_column);
374 gtk_sheet_set_active_cell (GTK_SHEET (var_sheet), col, current_column);
381 new_data_window (GtkMenuItem *menuitem, gpointer parent)
383 window_create (WINDOW_DATA, NULL);
388 select_sheet (struct data_editor *de, guint page_num)
390 GtkWidget *insert_variable = get_widget_assert (de->xml, "data_insert-variable");
391 GtkWidget *insert_cases = get_widget_assert (de->xml, "insert-cases");
393 GtkWidget *view_data = get_widget_assert (de->xml, "view_data");
394 GtkWidget *view_variables = get_widget_assert (de->xml, "view_variables");
399 gtk_widget_hide (view_variables);
400 gtk_widget_show (view_data);
401 gtk_widget_set_sensitive (insert_variable, TRUE);
402 gtk_widget_set_sensitive (insert_cases, FALSE);
404 case PAGE_DATA_SHEET:
405 gtk_widget_show (view_variables);
406 gtk_widget_hide (view_data);
408 gtk_widget_set_sensitive (insert_cases, TRUE);
412 g_assert_not_reached ();
419 data_var_select (GtkNotebook *notebook,
420 GtkNotebookPage *page,
424 struct data_editor *de = user_data;
426 select_sheet (de, page_num);
433 data_editor_select_sheet (struct data_editor *de, gint page)
435 gtk_notebook_set_current_page
437 GTK_NOTEBOOK (get_widget_assert (de->xml,"notebook")), page
443 status_bar_activate (GtkCheckMenuItem *menuitem, gpointer data)
445 struct data_editor *de = data;
446 GtkWidget *statusbar = get_widget_assert (de->xml, "status-bar");
448 if ( gtk_check_menu_item_get_active (menuitem) )
449 gtk_widget_show (statusbar);
451 gtk_widget_hide (statusbar);
456 grid_lines_activate (GtkCheckMenuItem *menuitem, gpointer data)
458 struct data_editor *de = data;
459 const bool grid_visible = gtk_check_menu_item_get_active (menuitem);
461 gtk_sheet_show_grid (GTK_SHEET (get_widget_assert (de->xml,
465 gtk_sheet_show_grid (GTK_SHEET (get_widget_assert (de->xml, "data_sheet")),
472 data_sheet_activate (GtkCheckMenuItem *menuitem, gpointer data)
474 struct data_editor *de = data;
476 data_editor_select_sheet (de, PAGE_DATA_SHEET);
481 variable_sheet_activate (GtkCheckMenuItem *menuitem, gpointer data)
483 struct data_editor *de = data;
485 data_editor_select_sheet (de, PAGE_VAR_SHEET);
490 fonts_activate (GtkMenuItem *menuitem, gpointer data)
492 struct data_editor *de = data;
494 gtk_font_selection_dialog_new (_("Font Selection"));
496 gtk_window_set_transient_for (GTK_WINDOW (dialog),
497 GTK_WINDOW (get_widget_assert (de->xml,
499 if ( GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog)) )
501 GtkSheet *data_sheet =
502 GTK_SHEET (get_widget_assert (de->xml, "data_sheet"));
504 GtkSheet *var_sheet =
505 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
507 PsppireDataStore *ds = PSPPIRE_DATA_STORE (gtk_sheet_get_model (data_sheet));
508 PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
510 const gchar *font = gtk_font_selection_dialog_get_font_name
511 (GTK_FONT_SELECTION_DIALOG (dialog));
513 PangoFontDescription* font_desc =
514 pango_font_description_from_string (font);
516 psppire_var_store_set_font (vs, font_desc);
517 psppire_data_store_set_font (ds, font_desc);
520 gtk_widget_hide (dialog);
524 /* The next two callbacks are mutually co-operative */
526 /* Callback for the value labels menu item */
528 value_labels_activate (GtkCheckMenuItem *menuitem, gpointer data)
530 struct data_editor *de = data;
532 GtkSheet *data_sheet = GTK_SHEET (get_widget_assert (de->xml, "data_sheet"));
534 GtkToggleToolButton *tb =
535 GTK_TOGGLE_TOOL_BUTTON (get_widget_assert (de->xml,
536 "togglebutton-value-labels"));
538 PsppireDataStore *ds = PSPPIRE_DATA_STORE (gtk_sheet_get_model (data_sheet));
540 gboolean show_value_labels = gtk_check_menu_item_get_active (menuitem);
542 gtk_toggle_tool_button_set_active (tb, show_value_labels);
544 psppire_data_store_show_labels (ds, show_value_labels);
548 /* Callback for the value labels tooglebutton */
550 value_labels_toggled (GtkToggleToolButton *toggle_tool_button,
553 struct data_editor *de = data;
555 GtkSheet *data_sheet = GTK_SHEET (get_widget_assert (de->xml, "data_sheet"));
557 GtkCheckMenuItem *item =
558 GTK_CHECK_MENU_ITEM (get_widget_assert (de->xml, "view_valuelabels"));
560 PsppireDataStore *ds = PSPPIRE_DATA_STORE (gtk_sheet_get_model (data_sheet));
562 gboolean show_value_labels =
563 gtk_toggle_tool_button_get_active (toggle_tool_button);
565 gtk_check_menu_item_set_active (item, show_value_labels);
567 psppire_data_store_show_labels (ds, show_value_labels);
572 file_quit (GtkCheckMenuItem *menuitem, gpointer data)
574 /* FIXME: Need to be more intelligent here.
575 Give the user the opportunity to save any unsaved data.
582 /* Callback for when the Clear item in the edit menu is activated */
584 on_clear_activate (GtkMenuItem *menuitem, gpointer data)
586 struct data_editor *de = data;
588 GtkNotebook *notebook = GTK_NOTEBOOK (get_widget_assert (de->xml,
591 switch ( gtk_notebook_get_current_page (notebook) )
595 GtkSheet *var_sheet =
596 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
598 PsppireVarStore *vs = PSPPIRE_VAR_STORE
599 (gtk_sheet_get_model (var_sheet) );
601 /* This shouldn't be able to happen, because the menuitem
602 should be disabled */
603 g_return_if_fail (var_sheet->state == GTK_SHEET_ROW_SELECTED );
605 psppire_dict_delete_variables (vs->dict,
606 var_sheet->range.row0,
608 var_sheet->range.rowi -
609 var_sheet->range.row0 );
612 case PAGE_DATA_SHEET:
615 g_assert_not_reached ();
620 /* Insert a new variable before the current row in the variable sheet,
621 or before the current column in the data sheet, whichever is selected */
623 insert_variable (GtkCheckMenuItem *m, gpointer data)
625 struct data_editor *de = data;
628 GtkWidget *notebook = get_widget_assert (de->xml, "notebook");
630 GtkSheet *var_sheet =
631 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
633 PsppireVarStore *vs = PSPPIRE_VAR_STORE
634 (gtk_sheet_get_model (var_sheet) );
636 switch ( gtk_notebook_get_current_page ( GTK_NOTEBOOK (notebook)) )
639 posn = var_sheet->active_cell.row;
641 case PAGE_DATA_SHEET:
643 GtkSheet *data_sheet =
644 GTK_SHEET (get_widget_assert (de->xml, "data_sheet"));
646 if ( data_sheet->state == GTK_SHEET_COLUMN_SELECTED )
647 posn = data_sheet->range.col0;
649 posn = data_sheet->active_cell.col;
653 g_assert_not_reached ();
656 psppire_dict_insert_variable (vs->dict, posn, NULL);
659 /* Callback for when the dictionary changes its split variables */
661 on_split_change (PsppireDict *dict, gpointer data)
663 struct data_editor *de = data;
665 size_t n_split_vars = dict_get_split_cnt (dict->dict);
667 GtkWidget *split_status_area =
668 get_widget_assert (de->xml, "split-file-status-area");
670 if ( n_split_vars == 0 )
672 gtk_label_set_text (GTK_LABEL (split_status_area), _("No Split"));
678 struct variable *const * split_vars = dict_get_split_vars (dict->dict);
680 text = g_string_new (_("Split by "));
682 for (i = 0 ; i < n_split_vars - 1; ++i )
684 g_string_append_printf (text, "%s, ", var_get_name (split_vars[i]));
686 g_string_append (text, var_get_name (split_vars[i]));
688 gtk_label_set_text (GTK_LABEL (split_status_area), text->str);
690 g_string_free (text, TRUE);
695 /* Callback for when the dictionary changes its filter variable */
697 on_filter_change (GObject *o, gint filter_index, gpointer data)
699 struct data_editor *de = data;
700 GtkWidget *filter_status_area =
701 get_widget_assert (de->xml, "filter-use-status-area");
703 if ( filter_index == -1 )
705 gtk_label_set_text (GTK_LABEL (filter_status_area), _("Filter off"));
709 GtkSheet *var_sheet =
710 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
712 PsppireVarStore *vs = PSPPIRE_VAR_STORE
713 (gtk_sheet_get_model (var_sheet) );
715 struct variable *var = psppire_dict_get_variable (vs->dict,
718 gchar *text = g_strdup_printf (_("Filter by %s"), var_get_name (var));
720 gtk_label_set_text (GTK_LABEL (filter_status_area), text);
726 /* Callback for when the dictionary changes its weights */
728 on_weight_change (GObject *o, gint weight_index, gpointer data)
730 struct data_editor *de = data;
731 GtkWidget *weight_status_area =
732 get_widget_assert (de->xml, "weight-status-area");
734 if ( weight_index == -1 )
736 gtk_label_set_text (GTK_LABEL (weight_status_area), _("Weights off"));
740 GtkSheet *var_sheet =
741 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
743 PsppireVarStore *vs = PSPPIRE_VAR_STORE
744 (gtk_sheet_get_model (var_sheet) );
746 struct variable *var = psppire_dict_get_variable (vs->dict,
749 gchar *text = g_strdup_printf (_("Weight by %s"), var_get_name (var));
751 gtk_label_set_text (GTK_LABEL (weight_status_area), text);
760 static void data_save_as_dialog (GtkAction *, struct data_editor *de);
761 static void new_file (GtkAction *, struct editor_window *de);
762 static void open_data_dialog (GtkAction *, struct data_editor *de);
763 static void data_save (GtkAction *action, struct data_editor *e);
766 /* Create the GtkActions and connect to their signals */
768 register_data_editor_actions (struct data_editor *de)
770 de->action_data_open =
771 gtk_action_new ("data-open-dialog",
773 _("Open a data file"),
776 g_signal_connect (de->action_data_open, "activate",
777 G_CALLBACK (open_data_dialog), de);
780 de->action_data_save = gtk_action_new ("data-save",
782 _("Save data to file"),
785 g_signal_connect (de->action_data_save, "activate",
786 G_CALLBACK (data_save), de);
790 de->action_data_save_as = gtk_action_new ("data-save-as-dialog",
792 _("Save data to file"),
795 g_signal_connect (de->action_data_save_as, "activate",
796 G_CALLBACK (data_save_as_dialog), de);
798 de->action_data_new =
799 gtk_action_new ("data-new",
804 g_signal_connect (de->action_data_new, "activate",
805 G_CALLBACK (new_file), de);
808 /* Returns true if NAME has a suffix which might denote a PSPP file */
810 name_has_suffix (const gchar *name)
812 if ( g_str_has_suffix (name, ".sav"))
814 if ( g_str_has_suffix (name, ".SAV"))
816 if ( g_str_has_suffix (name, ".por"))
818 if ( g_str_has_suffix (name, ".POR"))
824 /* Append SUFFIX to the filename of DE */
826 append_filename_suffix (struct data_editor *de, const gchar *suffix)
828 if ( ! name_has_suffix (de->file_name))
830 gchar *s = de->file_name;
831 de->file_name = g_strconcat (de->file_name, suffix, NULL);
836 /* Save DE to file */
838 save_file (struct data_editor *de)
840 struct getl_interface *sss;
842 g_assert (de->file_name);
844 if ( de->save_as_portable )
846 append_filename_suffix (de, ".por");
847 sss = create_syntax_string_source ("EXPORT OUTFILE='%s'.",
852 append_filename_suffix (de, ".sav");
853 sss = create_syntax_string_source ("SAVE OUTFILE='%s'.",
857 execute_syntax (sss);
861 /* Callback for data_save action.
862 If there's an existing file name, then just save,
863 otherwise prompt for a file name, then save */
865 data_save (GtkAction *action, struct data_editor *de)
870 data_save_as_dialog (action, de);
874 /* Callback for data_save_as action. Prompt for a filename and save */
876 data_save_as_dialog (GtkAction *action, struct data_editor *de)
878 struct editor_window *e = (struct editor_window *) de;
880 GtkWidget *button_sys;
882 gtk_file_chooser_dialog_new (_("Save"),
883 GTK_WINDOW (e->window),
884 GTK_FILE_CHOOSER_ACTION_SAVE,
885 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
886 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
889 GtkFileFilter *filter = gtk_file_filter_new ();
890 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
891 gtk_file_filter_add_pattern (filter, "*.sav");
892 gtk_file_filter_add_pattern (filter, "*.SAV");
893 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
895 filter = gtk_file_filter_new ();
896 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
897 gtk_file_filter_add_pattern (filter, "*.por");
898 gtk_file_filter_add_pattern (filter, "*.POR");
899 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
901 filter = gtk_file_filter_new ();
902 gtk_file_filter_set_name (filter, _("All Files"));
903 gtk_file_filter_add_pattern (filter, "*");
904 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
907 GtkWidget *button_por;
908 GtkWidget *vbox = gtk_vbox_new (TRUE, 5);
910 gtk_radio_button_new_with_label (NULL, _("System File"));
913 gtk_radio_button_new_with_label
914 (gtk_radio_button_get_group (GTK_RADIO_BUTTON(button_sys)),
917 gtk_box_pack_start_defaults (GTK_BOX (vbox), button_sys);
918 gtk_box_pack_start_defaults (GTK_BOX (vbox), button_por);
920 gtk_widget_show_all (vbox);
922 gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(dialog), vbox);
925 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
927 case GTK_RESPONSE_ACCEPT:
929 g_free (de->file_name);
932 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
934 de->save_as_portable =
935 ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_sys));
939 window_set_name_from_filename (e, de->file_name);
946 gtk_widget_destroy (dialog);
950 /* Callback for data_new action.
951 Performs the NEW FILE command */
953 new_file (GtkAction *action, struct editor_window *e)
955 struct data_editor *de = (struct data_editor *) e;
957 struct getl_interface *sss =
958 create_syntax_string_source ("NEW FILE.");
960 execute_syntax (sss);
962 g_free (de->file_name);
963 de->file_name = NULL;
965 default_window_name (e);
969 /* Callback for the data_open action.
970 Prompts for a filename and opens it */
972 open_data_dialog (GtkAction *action, struct data_editor *de)
974 struct editor_window *e = (struct editor_window *) de;
977 gtk_file_chooser_dialog_new (_("Open"),
978 GTK_WINDOW (e->window),
979 GTK_FILE_CHOOSER_ACTION_OPEN,
980 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
981 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
984 GtkFileFilter *filter = gtk_file_filter_new ();
985 gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
986 gtk_file_filter_add_pattern (filter, "*.sav");
987 gtk_file_filter_add_pattern (filter, "*.SAV");
988 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
990 filter = gtk_file_filter_new ();
991 gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
992 gtk_file_filter_add_pattern (filter, "*.por");
993 gtk_file_filter_add_pattern (filter, "*.POR");
994 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
996 filter = gtk_file_filter_new ();
997 gtk_file_filter_set_name (filter, _("All Files"));
998 gtk_file_filter_add_pattern (filter, "*");
999 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
1001 switch (gtk_dialog_run (GTK_DIALOG (dialog)))
1003 case GTK_RESPONSE_ACCEPT:
1005 struct getl_interface *sss;
1006 g_free (de->file_name);
1008 gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1010 sss = create_syntax_string_source ("GET FILE='%s'.", de->file_name);
1012 execute_syntax (sss);
1014 window_set_name_from_filename (e, de->file_name);
1021 gtk_widget_destroy (dialog);