From: Ben Pfaff Date: Fri, 29 Apr 2011 04:12:27 +0000 (-0700) Subject: gui: Fix File|Open in syntax editor. X-Git-Tag: v0.7.8~9 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df8e125c0969d3b6e043b7069d52f069c9e7ee78;p=pspp-builds.git gui: Fix File|Open in syntax editor. It didn't do anything. --- diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 7e248f8e..51b853c1 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -19,7 +19,6 @@ #include #include -#include "data/any-reader.h" #include "data/dataset.h" #include "language/lexer/lexer.h" #include "libpspp/message.h" @@ -359,108 +358,6 @@ load_file (PsppireWindow *de, const gchar *file_name) return ok; } -static GtkWidget * -sysfile_chooser_dialog (PsppireWindow *toplevel) -{ - GtkWidget *dialog = - gtk_file_chooser_dialog_new (_("Open"), - GTK_WINDOW (toplevel), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - GtkFileFilter *filter; - - filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("Data and Syntax Files")); - gtk_file_filter_add_pattern (filter, "*.sav"); - gtk_file_filter_add_pattern (filter, "*.SAV"); - gtk_file_filter_add_pattern (filter, "*.por"); - gtk_file_filter_add_pattern (filter, "*.POR"); - gtk_file_filter_add_pattern (filter, "*.sps"); - gtk_file_filter_add_pattern (filter, "*.SPS"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); - - filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("System Files (*.sav)")); - gtk_file_filter_add_pattern (filter, "*.sav"); - gtk_file_filter_add_pattern (filter, "*.SAV"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); - - filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("Portable Files (*.por) ")); - gtk_file_filter_add_pattern (filter, "*.por"); - gtk_file_filter_add_pattern (filter, "*.POR"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); - - filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) ")); - gtk_file_filter_add_pattern (filter, "*.sps"); - gtk_file_filter_add_pattern (filter, "*.SPS"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); - - filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("All Files")); - gtk_file_filter_add_pattern (filter, "*"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); - - { - gchar *dir_name; - gchar *filename = NULL; - g_object_get (toplevel, "filename", &filename, NULL); - - if ( ! g_path_is_absolute (filename)) - { - gchar *path = - g_build_filename (g_get_current_dir (), filename, NULL); - dir_name = g_path_get_dirname (path); - g_free (path); - } - else - { - dir_name = g_path_get_dirname (filename); - } - gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), - dir_name); - free (dir_name); - } - - return dialog; -} - -/* Callback for the data_open action. - Prompts for a filename and opens it */ -static void -open_window (PsppireWindow *de) -{ - GtkWidget *dialog = sysfile_chooser_dialog (de); - - switch (gtk_dialog_run (GTK_DIALOG (dialog))) - { - case GTK_RESPONSE_ACCEPT: - { - gchar *name = - gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - - gchar *sysname = convert_glib_filename_to_system_filename (name, NULL); - - if (any_reader_may_open (sysname)) - psppire_window_load (de, name); - else - open_syntax_window (name); - - g_free (sysname); - g_free (name); - } - break; - default: - break; - } - - gtk_widget_destroy (dialog); -} - /* Returns true if NAME has a suffix which might denote a PSPP file */ static gboolean name_has_suffix (const gchar *name) @@ -542,7 +439,7 @@ display_dict (PsppireDataWindow *de) static void sysfile_info (PsppireDataWindow *de) { - GtkWidget *dialog = sysfile_chooser_dialog (PSPPIRE_WINDOW (de)); + GtkWidget *dialog = psppire_window_file_chooser_dialog (PSPPIRE_WINDOW (de)); if ( GTK_RESPONSE_ACCEPT == gtk_dialog_run (GTK_DIALOG (dialog))) { @@ -1028,7 +925,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "file_save", G_CALLBACK (data_save)); - connect_action (de, "file_open", G_CALLBACK (open_window)); + connect_action (de, "file_open", G_CALLBACK (psppire_window_open)); connect_action (de, "file_save_as", G_CALLBACK (data_save_as_dialog)); diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index 45b65212..2e90ba76 100644 --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2008, 2009, 2010 Free Software Foundation + Copyright (C) 2008, 2009, 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 @@ -659,6 +659,11 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window) window); #endif + g_signal_connect_swapped (get_action_assert (xml, "file_open"), + "activate", + G_CALLBACK (psppire_window_open), + window); + g_signal_connect_swapped (get_action_assert (xml, "file_save"), "activate", G_CALLBACK (syntax_save), diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c index 369ece50..a3339ec8 100644 --- a/src/ui/gui/psppire-window.c +++ b/src/ui/gui/psppire-window.c @@ -16,6 +16,7 @@ #include +#include "psppire-window.h" #include @@ -26,9 +27,15 @@ #define _(msgid) gettext (msgid) #define N_(msgid) msgid -#include "psppire-window.h" -#include "psppire-window-register.h" +#include "data/any-reader.h" +#include "data/dataset.h" + +#include "helper.h" #include "psppire-conf.h" +#include "psppire-data-window.h" +#include "psppire-syntax-window.h" +#include "psppire-window-register.h" +#include "psppire.h" static void psppire_window_base_finalize (PsppireWindowClass *, gpointer); static void psppire_window_base_init (PsppireWindowClass *class); @@ -434,7 +441,6 @@ psppire_window_init (PsppireWindow *window) g_signal_connect (window, "realize", G_CALLBACK (on_realize), window); - } /* @@ -636,6 +642,123 @@ psppire_window_load (PsppireWindow *w, const gchar *file) return ok; } +GtkWidget * +psppire_window_file_chooser_dialog (PsppireWindow *toplevel) +{ + GtkWidget *dialog = + gtk_file_chooser_dialog_new (_("Open"), + GTK_WINDOW (toplevel), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + GtkFileFilter *filter; + + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("Data and Syntax Files")); + gtk_file_filter_add_pattern (filter, "*.sav"); + gtk_file_filter_add_pattern (filter, "*.SAV"); + gtk_file_filter_add_pattern (filter, "*.por"); + gtk_file_filter_add_pattern (filter, "*.POR"); + gtk_file_filter_add_pattern (filter, "*.sps"); + gtk_file_filter_add_pattern (filter, "*.SPS"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("System Files (*.sav)")); + gtk_file_filter_add_pattern (filter, "*.sav"); + gtk_file_filter_add_pattern (filter, "*.SAV"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("Portable Files (*.por) ")); + gtk_file_filter_add_pattern (filter, "*.por"); + gtk_file_filter_add_pattern (filter, "*.POR"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) ")); + gtk_file_filter_add_pattern (filter, "*.sps"); + gtk_file_filter_add_pattern (filter, "*.SPS"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("All Files")); + gtk_file_filter_add_pattern (filter, "*"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + + { + gchar *dir_name; + gchar *filename = NULL; + g_object_get (toplevel, "filename", &filename, NULL); + + if ( ! g_path_is_absolute (filename)) + { + gchar *path = + g_build_filename (g_get_current_dir (), filename, NULL); + dir_name = g_path_get_dirname (path); + g_free (path); + } + else + { + dir_name = g_path_get_dirname (filename); + } + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), + dir_name); + free (dir_name); + } + + return dialog; +} + +/* Callback for the file_open action. + Prompts for a filename and opens it */ +void +psppire_window_open (PsppireWindow *de) +{ + GtkWidget *dialog = psppire_window_file_chooser_dialog (de); + + switch (gtk_dialog_run (GTK_DIALOG (dialog))) + { + case GTK_RESPONSE_ACCEPT: + { + gchar *name = + gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + + gchar *sysname = convert_glib_filename_to_system_filename (name, NULL); + + if (any_reader_may_open (sysname)) + { + PsppireWindow *window; + +#if 0 + if (PSPPIRE_IS_DATA_WINDOW (de) + && psppire_data_window_is_empty (PSPPIRE_DATA_WINDOW (de))) + window = de; + else + window = PSPPIRE_WINDOW (psppire_data_window_new (NULL)); +#else + window = PSPPIRE_WINDOW (psppire_default_data_window ()); +#endif + + psppire_window_load (window, name); + gtk_widget_show (GTK_WIDGET (window)); + } + else + open_syntax_window (name); + + g_free (sysname); + g_free (name); + } + break; + default: + break; + } + + gtk_widget_destroy (dialog); +} + /* Puts FILE_NAME into the recent list. If it's already in the list, it moves it to the top diff --git a/src/ui/gui/psppire-window.h b/src/ui/gui/psppire-window.h index 19ed97ec..f65e9e3c 100644 --- a/src/ui/gui/psppire-window.h +++ b/src/ui/gui/psppire-window.h @@ -107,6 +107,8 @@ gint psppire_window_query_save (PsppireWindow *); void psppire_window_save (PsppireWindow *w); gboolean psppire_window_load (PsppireWindow *w, const gchar *file); +void psppire_window_open (PsppireWindow *de); +GtkWidget *psppire_window_file_chooser_dialog (PsppireWindow *toplevel); G_END_DECLS diff --git a/src/ui/gui/syntax-editor.ui b/src/ui/gui/syntax-editor.ui index c9436629..e65eef66 100644 --- a/src/ui/gui/syntax-editor.ui +++ b/src/ui/gui/syntax-editor.ui @@ -29,21 +29,9 @@ - + gtk-open - open2 - - - - - file_open_syntax - _Syntax - - - - - file_open_data - _Data + file_open @@ -150,10 +138,7 @@ - - - - +