X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-window.c;h=8e34c214be3db729a4b5f7fb9d99eb35214e7b2c;hb=76f722cdfd6475f8ae2d98139ea596adfcdb47be;hp=f6cdb7b24368f5686832569799a3beb522ec05a7;hpb=34bfbdd99ac80a84447cb8bbc46de726d0bdc7fc;p=pspp diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c index f6cdb7b243..8e34c214be 100644 --- a/src/ui/gui/psppire-window.c +++ b/src/ui/gui/psppire-window.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2009, 2010, 2011 Free Software Foundation + Copyright (C) 2009, 2010, 2011, 2013, 2014 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 @@ -15,8 +15,10 @@ along with this program. If not, see . */ #include +#include #include "psppire-window.h" +#include "psppire-window-base.h" #include @@ -28,15 +30,15 @@ #define N_(msgid) msgid #include "data/any-reader.h" +#include "data/file-handle-def.h" #include "data/dataset.h" +#include "libpspp/version.h" #include "helper.h" -#include "psppire-conf.h" #include "psppire-data-window.h" #include "psppire-encoding-selector.h" #include "psppire-syntax-window.h" #include "psppire-window-register.h" -#include "psppire.h" static void psppire_window_base_init (PsppireWindowClass *class); static void psppire_window_class_init (PsppireWindowClass *class); @@ -66,7 +68,7 @@ psppire_window_get_type (void) }; psppire_window_type = - g_type_register_static (GTK_TYPE_WINDOW, "PsppireWindow", + g_type_register_static (PSPPIRE_TYPE_WINDOW_BASE, "PsppireWindow", &psppire_window_info, G_TYPE_FLAG_ABSTRACT); } @@ -228,17 +230,6 @@ psppire_window_get_property (GObject *object, } -static void -on_realize (GtkWindow *window, gpointer data) -{ - PsppireConf *conf = psppire_conf_new (); - - const gchar *base = G_OBJECT_TYPE_NAME (window); - - psppire_conf_set_window_geometry (conf, base, window); -} - - static void psppire_window_finalize (GObject *object) { @@ -246,6 +237,8 @@ psppire_window_finalize (GObject *object) PsppireWindowRegister *reg = psppire_window_register_new (); + g_signal_handler_disconnect (reg, window->remove_handler); + g_signal_handler_disconnect (reg, window->insert_handler); psppire_window_register_remove (reg, window->list_name); g_free (window->filename); g_free (window->basename); @@ -253,12 +246,6 @@ psppire_window_finalize (GObject *object) g_free (window->description); g_free (window->list_name); - g_signal_handler_disconnect (psppire_window_register_new (), - window->remove_handler); - - g_signal_handler_disconnect (psppire_window_register_new (), - window->insert_handler); - g_hash_table_destroy (window->menuitem_table); if (G_OBJECT_CLASS (parent_class)->finalize) @@ -324,8 +311,10 @@ psppire_window_base_init (PsppireWindowClass *class) static void menu_toggled (GtkCheckMenuItem *mi, gpointer data) { +#if GTK3_TRANSITION /* Prohibit changes to the state */ mi->active = !mi->active; +#endif } @@ -350,11 +339,12 @@ insert_menuitem_into_menu (PsppireWindow *window, gpointer key) /* Add a separator before adding the first real item. If we add a separator at any other time, sometimes GtkUIManager removes it. */ - if (g_hash_table_size (window->menuitem_table) == 0) + if (!window->added_separator) { GtkWidget *separator = gtk_separator_menu_item_new (); gtk_widget_show (separator); gtk_menu_shell_append (window->menu, separator); + window->added_separator = TRUE; } filename = g_filename_display_name (key); @@ -368,9 +358,11 @@ insert_menuitem_into_menu (PsppireWindow *window, gpointer key) gtk_menu_shell_append (window->menu, item); +#if GTK3_TRANSITION /* Set the state without emitting a signal */ GTK_CHECK_MENU_ITEM (item)->active = (psppire_window_register_lookup (psppire_window_register_new (), key) == window); +#endif g_hash_table_insert (window->menuitem_table, key, item); } @@ -422,13 +414,6 @@ on_delete (PsppireWindow *w, GdkEvent *event, gpointer user_data) { PsppireWindowRegister *reg = psppire_window_register_new (); - const gchar *base = G_OBJECT_TYPE_NAME (w); - - PsppireConf *conf = psppire_conf_new (); - - psppire_conf_save_window_geometry (conf, base, GTK_WINDOW (w)); - - if ( w->dirty ) { gint response = psppire_window_query_save (w); @@ -484,14 +469,12 @@ psppire_window_init (PsppireWindow *window) G_CALLBACK (remove_menuitem), window); + window->added_separator = FALSE; window->dirty = FALSE; g_signal_connect_swapped (window, "delete-event", G_CALLBACK (on_delete), window); g_object_set (window, "icon-name", "pspp", NULL); - - g_signal_connect (window, "realize", - G_CALLBACK (on_realize), window); } /* @@ -537,11 +520,11 @@ psppire_window_query_save (PsppireWindow *se) GTK_RESPONSE_REJECT); cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_CANCEL, + _("Cancel"), GTK_RESPONSE_CANCEL); gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_SAVE, + _("Save"), GTK_RESPONSE_APPLY); gtk_widget_grab_focus (cancel_button); @@ -682,7 +665,8 @@ psppire_window_save_as (PsppireWindow *w) static void delete_recent (const char *file_name); gboolean -psppire_window_load (PsppireWindow *w, const gchar *file) +psppire_window_load (PsppireWindow *w, const gchar *file, + const gchar *encoding, gpointer hint) { gboolean ok; PsppireWindowIface *i = PSPPIRE_WINDOW_MODEL_GET_IFACE (w); @@ -693,7 +677,7 @@ psppire_window_load (PsppireWindow *w, const gchar *file) g_return_val_if_fail (i->load, FALSE); - ok = i->load (w, file); + ok = i->load (w, file, encoding, hint); if ( ok ) { @@ -706,6 +690,7 @@ psppire_window_load (PsppireWindow *w, const gchar *file) return ok; } + GtkWidget * psppire_window_file_chooser_dialog (PsppireWindow *toplevel) { @@ -714,8 +699,8 @@ psppire_window_file_chooser_dialog (PsppireWindow *toplevel) 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, + _("Cancel"), GTK_RESPONSE_CANCEL, + _("Open"), GTK_RESPONSE_ACCEPT, NULL); g_object_set (dialog, "local-only", FALSE, NULL); @@ -723,13 +708,15 @@ psppire_window_file_chooser_dialog (PsppireWindow *toplevel) gtk_file_filter_set_name (filter, _("Data and Syntax Files")); gtk_file_filter_add_mime_type (filter, "application/x-spss-sav"); gtk_file_filter_add_mime_type (filter, "application/x-spss-por"); + gtk_file_filter_add_pattern (filter, "*.zsav"); 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_set_name (filter, _("System Files (*.sav, *.zsav)")); gtk_file_filter_add_mime_type (filter, "application/x-spss-sav"); + gtk_file_filter_add_pattern (filter, "*.zsav"); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); filter = gtk_file_filter_new (); @@ -769,8 +756,9 @@ psppire_window_file_chooser_dialog (PsppireWindow *toplevel) free (dir_name); } - gtk_file_chooser_set_extra_widget ( - GTK_FILE_CHOOSER (dialog), psppire_encoding_selector_new ("Auto", true)); + gtk_file_chooser_set_extra_widget ( + GTK_FILE_CHOOSER (dialog), + psppire_encoding_selector_new ("Auto", true)); return dialog; } @@ -782,6 +770,8 @@ psppire_window_open (PsppireWindow *de) { GtkWidget *dialog = psppire_window_file_chooser_dialog (de); + gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), relocate (examples_dir), NULL); + switch (gtk_dialog_run (GTK_DIALOG (dialog))) { case GTK_RESPONSE_ACCEPT: @@ -789,18 +779,22 @@ psppire_window_open (PsppireWindow *de) gchar *name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - gchar *sysname = convert_glib_filename_to_system_filename (name, NULL); + const gchar **cs = NULL; + g_get_filename_charsets (&cs); gchar *encoding = psppire_encoding_selector_get_encoding ( gtk_file_chooser_get_extra_widget (GTK_FILE_CHOOSER (dialog))); - if (any_reader_may_open (sysname)) - open_data_window (de, name); - else + struct file_handle *fh = fh_create_file (NULL, name, cs[0], fh_default_properties ()); + + int retval = any_reader_detect (fh, NULL); + if (retval == 1) + open_data_window (de, name, encoding, NULL); + else if (retval == 0) open_syntax_window (name, encoding); g_free (encoding); - g_free (sysname); + fh_unref (fh); g_free (name); } break; @@ -816,17 +810,24 @@ psppire_window_open (PsppireWindow *de) with associated MIME_TYPE. If it's already in the list, it moves it to the top. */ void -add_most_recent (const char *file_name, const char *mime_type) +add_most_recent (const char *file_name, + const char *mime_type, const char *encoding) { gchar *uri = g_filename_to_uri (file_name, NULL, NULL); - if ( uri ) { GtkRecentData recent_data; + gchar *full_mime_type; + + if (encoding && encoding[0]) + full_mime_type = g_strdup_printf ("%s; charset=%s", + mime_type, encoding); + else + full_mime_type = g_strdup (mime_type); recent_data.display_name = NULL; recent_data.description = NULL; - recent_data.mime_type = CONST_CAST (gchar *, mime_type); + recent_data.mime_type = full_mime_type; recent_data.app_name = CONST_CAST (gchar *, g_get_application_name ()); recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL); recent_data.groups = NULL; @@ -836,6 +837,7 @@ add_most_recent (const char *file_name, const char *mime_type) uri, &recent_data); g_free (recent_data.app_exec); + g_free (full_mime_type); } g_free (uri);