X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-window.c;h=8e34c214be3db729a4b5f7fb9d99eb35214e7b2c;hb=870b099b7272c4440f9df2a0741902f035af3f51;hp=65842bdc623bccac6278809b2df6cb7404383e30;hpb=8284058a6ba9cf53dca2e53b7b9cccabd6205001;p=pspp
diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c
index 65842bdc62..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, 2013 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,6 +15,7 @@
along with this program. If not, see . */
#include
+#include
#include "psppire-window.h"
#include "psppire-window-base.h"
@@ -29,15 +30,15 @@
#define N_(msgid) msgid
#include "data/any-reader.h"
-#include "data/file-name.h"
+#include "data/file-handle-def.h"
#include "data/dataset.h"
+#include "libpspp/version.h"
#include "helper.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);
@@ -310,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
}
@@ -355,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);
}
@@ -515,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);
@@ -660,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, gpointer hint)
+psppire_window_load (PsppireWindow *w, const gchar *file,
+ const gchar *encoding, gpointer hint)
{
gboolean ok;
PsppireWindowIface *i = PSPPIRE_WINDOW_MODEL_GET_IFACE (w);
@@ -671,7 +677,7 @@ psppire_window_load (PsppireWindow *w, const gchar *file, gpointer hint)
g_return_val_if_fail (i->load, FALSE);
- ok = i->load (w, file, hint);
+ ok = i->load (w, file, encoding, hint);
if ( ok )
{
@@ -685,27 +691,6 @@ psppire_window_load (PsppireWindow *w, const gchar *file, gpointer hint)
}
-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);
-
- if ( ! fn_exists (sysname))
- {
- gtk_widget_set_sensitive (encoding_selector, FALSE);
- return;
- }
-
- gtk_widget_set_sensitive (encoding_selector, ! any_reader_may_open (sysname));
-}
-
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);
@@ -771,17 +756,9 @@ psppire_window_file_chooser_dialog (PsppireWindow *toplevel)
free (dir_name);
}
-
- {
- GtkWidget *encoding_selector = psppire_encoding_selector_new ("Auto", true);
-
- gtk_widget_set_sensitive (encoding_selector, FALSE);
-
- g_signal_connect (dialog, "selection-changed", G_CALLBACK (on_selection_changed),
- encoding_selector);
-
- gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), encoding_selector);
- }
+ gtk_file_chooser_set_extra_widget (
+ GTK_FILE_CHOOSER (dialog),
+ psppire_encoding_selector_new ("Auto", true));
return dialog;
}
@@ -793,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:
@@ -800,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, NULL);
- 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;
@@ -827,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;
@@ -847,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);