/* 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
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
+#include <gl/relocatable.h>
#include "psppire-window.h"
#include "psppire-window-base.h"
#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);
if (window->basename)
g_string_append_printf (title, "%s ", window->basename);
- if (window->id != '\0')
+ if (window->id)
g_string_append_printf (title, "[%s] ", window->id);
g_string_append_unichar (title, 0x2014); /* em dash */
g_string_append_printf (title, "PSPPIRE %s", window->description);
+ int minor = 1;
+ sscanf (bare_version, "%*d.%d.%*d", &minor);
+ if (minor % 2)
+ g_string_append_printf (title, " - Test version! Please report bugs to %s", PACKAGE_BUGREPORT);
+
gtk_window_set_title (GTK_WINDOW (window), title->str);
g_string_free (title, TRUE);
: NULL);
psppire_window_name_changed (window);
break;
- break;
case PROP_ID:
g_free (window->id);
window->id = g_value_dup_string (value);
-static void
-menu_toggled (GtkCheckMenuItem *mi, gpointer data)
-{
- /* Prohibit changes to the state */
- mi->active = !mi->active;
-}
-
-
-/* Look up the window associated with this menuitem and present it to the user */
-static void
-menu_activate (GtkMenuItem *mi, gpointer data)
-{
- const gchar *key = data;
-
- PsppireWindowRegister *reg = psppire_window_register_new ();
-
- PsppireWindow *window = psppire_window_register_lookup (reg, key);
-
- gtk_window_present (GTK_WINDOW (window));
-}
-
static void
insert_menuitem_into_menu (PsppireWindow *window, gpointer key)
{
gchar *filename;
GtkWidget *item;
-
- /* Add a separator before adding the first real item. If we add a separator
- at any other time, sometimes GtkUIManager removes it. */
- 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);
item = gtk_check_menu_item_new_with_label (filename);
g_free (filename);
- g_signal_connect (item, "toggled", G_CALLBACK (menu_toggled), NULL);
- g_signal_connect (item, "activate", G_CALLBACK (menu_activate), key);
-
- gtk_widget_show (item);
-
- gtk_menu_shell_append (window->menu, item);
-
- /* Set the state without emitting a signal */
- GTK_CHECK_MENU_ITEM (item)->active =
- (psppire_window_register_lookup (psppire_window_register_new (), key) == window);
-
g_hash_table_insert (window->menuitem_table, key, item);
}
insert_menuitem (GObject *reg, const gchar *key, gpointer data)
{
PsppireWindow *window = PSPPIRE_WINDOW (data);
-
+
insert_menuitem_into_menu (window, (gpointer) key);
}
remove_menuitem (PsppireWindowRegister *reg, const gchar *key, gpointer data)
{
PsppireWindow *window = PSPPIRE_WINDOW (data);
- GtkWidget *item ;
-
- item = g_hash_table_lookup (window->menuitem_table, key);
-
g_hash_table_remove (window->menuitem_table, key);
-
- if (GTK_IS_CONTAINER (window->menu))
- gtk_container_remove (GTK_CONTAINER (window->menu), item);
}
static void
static void
psppire_window_init (PsppireWindow *window)
{
- window->menu = NULL;
window->filename = NULL;
window->basename = NULL;
window->id = NULL;
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);
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);
g_return_val_if_fail (i->load, FALSE);
- ok = i->load (w, file, hint);
+ ok = i->load (w, file, encoding, hint);
if ( 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);
-
- 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)
{
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);
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;
}
{
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:
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;
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;
uri, &recent_data);
g_free (recent_data.app_exec);
+ g_free (full_mime_type);
}
g_free (uri);