#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_finalize (PsppireWindowClass *, gpointer);
static void psppire_window_base_init (PsppireWindowClass *class);
static void psppire_window_class_init (PsppireWindowClass *class);
static void psppire_window_init (PsppireWindow *window);
{
sizeof (PsppireWindowClass),
(GBaseInitFunc) psppire_window_base_init,
- (GBaseFinalizeFunc) psppire_window_base_finalize,
+ (GBaseFinalizeFunc) NULL,
(GClassInitFunc) psppire_window_class_init,
(GClassFinalizeFunc) NULL,
NULL,
};
-gchar *
-uniquify (const gchar *str, int *x)
-{
- return g_strdup_printf ("%s%d", str, (*x)++);
-}
-
static void
psppire_window_set_title (PsppireWindow *window)
{
-static void
-psppire_window_base_finalize (PsppireWindowClass *class,
- gpointer class_data)
-{
-}
-
static void
menu_toggled (GtkCheckMenuItem *mi, gpointer data)
{
g_signal_connect_swapped (window, "delete-event", G_CALLBACK (on_delete), window);
- g_object_set (window, "icon-name", "psppicon", NULL);
+ g_object_set (window, "icon-name", "pspp", NULL);
g_signal_connect (window, "realize",
G_CALLBACK (on_realize), window);
description);
g_free (description);
- g_object_set (dialog, "icon-name", "psppicon", NULL);
+ g_object_set (dialog, "icon-name", "pspp", NULL);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
_("If you don't save, changes from the last %ld seconds will be permanently lost."),
}
}
-
-static void add_most_recent (const char *file_name);
static void delete_recent (const char *file_name);
gboolean
if ( ok )
{
psppire_window_set_filename (w, file);
- add_most_recent (file);
w->dirty = FALSE;
}
else
return ok;
}
+
+static void
+on_selection_changed (GtkFileChooser *chooser, GtkWidget *encoding_selector)
+{
+ const gchar *sysname;
+
+ const gchar *name = gtk_file_chooser_get_filename (chooser);
+
+ if ( NULL == name )
+ return;
+
+ sysname = convert_glib_filename_to_system_filename (name, NULL);
+
+ gtk_widget_set_sensitive (encoding_selector, ! any_reader_may_open (sysname));
+}
+
GtkWidget *
psppire_window_file_chooser_dialog (PsppireWindow *toplevel)
{
+ GtkFileFilter *filter = gtk_file_filter_new ();
GtkWidget *dialog =
gtk_file_chooser_dialog_new (_("Open"),
GTK_WINDOW (toplevel),
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
- GtkFileFilter *filter;
+ g_object_set (dialog, "local-only", FALSE, NULL);
- 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_mime_type (filter, "application/x-spss-sav");
+ gtk_file_filter_add_mime_type (filter, "application/x-spss-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_filter_add_mime_type (filter, "application/x-spss-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_filter_add_mime_type (filter, "application/x-spss-por");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
filter = gtk_file_filter_new ();
free (dir_name);
}
+
+ {
+ GtkWidget *encoding_selector = psppire_encoding_selector_new ("Auto", true);
+ gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), encoding_selector);
+
+ g_signal_connect (dialog, "selection-changed", G_CALLBACK (on_selection_changed), encoding_selector);
+ }
+
return dialog;
}
gchar *sysname = convert_glib_filename_to_system_filename (name, NULL);
+ 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
- open_syntax_window (name);
+ open_syntax_window (name, encoding);
+ g_free (encoding);
g_free (sysname);
g_free (name);
}
}
-/* Puts FILE_NAME into the recent list.
- If it's already in the list, it moves it to the top
-*/
-static void
-add_most_recent (const char *file_name)
+/* Puts FILE_NAME (encoded in the glib file name encoding) into the recent list
+ 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)
{
gchar *uri = g_filename_to_uri (file_name, NULL, NULL);
if ( uri )
- gtk_recent_manager_add_item (gtk_recent_manager_get_default (), uri);
+ {
+ GtkRecentData recent_data;
+
+ recent_data.display_name = NULL;
+ recent_data.description = NULL;
+ recent_data.mime_type = CONST_CAST (gchar *, 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;
+ recent_data.is_private = FALSE;
+
+ gtk_recent_manager_add_full (gtk_recent_manager_get_default (),
+ uri, &recent_data);
+
+ g_free (recent_data.app_exec);
+ }
g_free (uri);
}