X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-syntax-window.c;h=48a77fc03ec21a7fa3f9cfc4a3ddc6cceedb3c4f;hb=3d8d78ad9ca206b6489cc3944c985c8ba89e4b1e;hp=2a09c71c027b8a68380866e0011f84f31decbb57;hpb=ca259adce7a069f58545de7511e17d73c9e0a868;p=pspp-builds.git diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index 2a09c71c..48a77fc0 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 Free Software Foundation + Copyright (C) 2008, 2009 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 @@ -18,6 +18,7 @@ #include #include +#include "executor.h" #include "helper.h" #include @@ -28,11 +29,14 @@ #include "psppire-data-window.h" #include "psppire-window-register.h" +#include "psppire.h" #include "about.h" #include "psppire-syntax-window.h" #include "syntax-editor-source.h" #include +#include "xalloc.h" + #include #define _(msgid) gettext (msgid) #define N_(msgid) msgid @@ -223,12 +227,13 @@ append_suffix (const gchar *filename) return g_strdup_printf ("%s.sps", filename); } - return strdup (filename); + return xstrdup (filename); } /* Save BUFFER to the file called FILENAME. - If successful, clears the buffer's modified flag + FILENAME must be encoded in Glib filename encoding. + If successful, clears the buffer's modified flag. */ static gboolean save_editor_to_file (PsppireSyntaxWindow *se, @@ -241,28 +246,24 @@ save_editor_to_file (PsppireSyntaxWindow *se, gchar *text; gchar *suffixedname; - gchar *glibfilename; g_assert (filename); suffixedname = append_suffix (filename); - glibfilename = g_filename_from_utf8 (suffixedname, -1, 0, 0, err); - - g_free ( suffixedname); - - if ( ! glibfilename ) - return FALSE; - gtk_text_buffer_get_iter_at_line (buffer, &start, 0); gtk_text_buffer_get_iter_at_offset (buffer, &stop, -1); text = gtk_text_buffer_get_text (buffer, &start, &stop, FALSE); - result = g_file_set_contents (glibfilename, text, -1, err); + result = g_file_set_contents (suffixedname, text, -1, err); + + g_free (suffixedname); if ( result ) { - gchar *msg = g_strdup_printf (_("Saved file \"%s\""), filename); + char *fn = g_filename_display_name (filename); + gchar *msg = g_strdup_printf (_("Saved file \"%s\""), fn); + g_free (fn); gtk_statusbar_push (GTK_STATUSBAR (se->sb), se->text_context, msg); gtk_text_buffer_set_modified (buffer, FALSE); g_free (msg); @@ -394,22 +395,10 @@ open_syntax_window (GtkMenuItem *menuitem, gpointer parent) GtkWidget *se = psppire_syntax_window_new (); - if ( psppire_syntax_window_load_from_file (PSPPIRE_SYNTAX_WINDOW (se), file_name, NULL) ) -#if RECENT_LISTS_AVAILABLE - { - GtkRecentManager *manager = gtk_recent_manager_get_default(); - gchar *uri = g_filename_to_uri (file_name, NULL, NULL); - - gtk_recent_manager_remove_item (manager, uri, NULL); - if ( ! gtk_recent_manager_add_item (manager, uri)) - g_warning ("Could not add item %s to recent list\n",uri); - - g_free (uri); - } -#else - ; -#endif - gtk_widget_show (se); + if ( psppire_window_load (PSPPIRE_WINDOW (se), file_name) ) + gtk_widget_show (se); + else + gtk_widget_destroy (se); } gtk_widget_destroy (dialog); @@ -425,10 +414,10 @@ on_text_changed (GtkTextBuffer *buffer, PsppireSyntaxWindow *window) static void on_modified_changed (GtkTextBuffer *buffer, PsppireWindow *window) { - psppire_window_set_unsaved (window, gtk_text_buffer_get_modified (buffer)); + if (gtk_text_buffer_get_modified (buffer)) + psppire_window_set_unsaved (window); } - extern struct source_stream *the_source_stream ; static void @@ -470,76 +459,81 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window) gtk_widget_show_all (box); - g_signal_connect (get_object_assert (xml,"file_new_syntax"), + g_signal_connect (get_action_assert (xml,"file_new_syntax"), "activate", G_CALLBACK (create_syntax_window), NULL); - g_signal_connect (get_object_assert (xml,"file_open_syntax"), + g_signal_connect (get_action_assert (xml,"file_open_syntax"), "activate", G_CALLBACK (open_syntax_window), window); #if 0 - g_signal_connect (get_object_assert (xml,"file_new_data"), + g_signal_connect (get_action_assert (xml,"file_new_data"), "activate", G_CALLBACK (create_data_window), window); #endif - g_signal_connect (get_object_assert (xml,"help_about"), - "activate", - G_CALLBACK (about_new), - window); + { + GtkAction *abt = get_action_assert (xml, "help_about"); + g_object_set (abt, "stock-id", "gtk-about", NULL); + + g_signal_connect (abt, + "activate", + G_CALLBACK (about_new), + window); + } - g_signal_connect (get_object_assert (xml,"help_reference"), + g_signal_connect (get_action_assert (xml,"help_reference"), "activate", G_CALLBACK (reference_manual), NULL); - g_signal_connect_swapped (get_object_assert (xml, "file_save"), + g_signal_connect_swapped (get_action_assert (xml, "file_save"), "activate", G_CALLBACK (syntax_save), window); - g_signal_connect_swapped (get_object_assert (xml, "file_save_as"), + g_signal_connect_swapped (get_action_assert (xml, "file_save_as"), "activate", G_CALLBACK (syntax_save_as), window); - g_signal_connect (get_object_assert (xml,"file_quit"), + g_signal_connect (get_action_assert (xml,"file_quit"), "activate", G_CALLBACK (on_quit), window); - g_signal_connect (get_object_assert (xml,"run_all"), + g_signal_connect (get_action_assert (xml,"run_all"), "activate", G_CALLBACK (on_run_all), window); - g_signal_connect (get_object_assert (xml,"run_selection"), + g_signal_connect (get_action_assert (xml,"run_selection"), "activate", G_CALLBACK (on_run_selection), window); - g_signal_connect (get_object_assert (xml,"run_current_line"), + g_signal_connect (get_action_assert (xml,"run_current_line"), "activate", G_CALLBACK (on_run_current_line), window); - g_signal_connect (get_object_assert (xml,"run_to_end"), + g_signal_connect (get_action_assert (xml,"run_to_end"), "activate", G_CALLBACK (on_run_to_end), window); - g_signal_connect (get_object_assert (xml,"windows_minimise_all"), + g_signal_connect (get_action_assert (xml,"windows_minimise_all"), "activate", G_CALLBACK (psppire_window_minimise_all), NULL); { - GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (xml, "uimanager1")); + GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (xml, "uimanager1", GTK_TYPE_UI_MANAGER)); PSPPIRE_WINDOW (window)->menu = GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar2/windows/windows_minimise_all")->parent); @@ -558,38 +552,55 @@ psppire_syntax_window_new (void) NULL)); } +static void +error_dialog (GtkWindow *w, const gchar *filename, GError *err) +{ + gchar *fn = g_filename_display_basename (filename); + + GtkWidget *dialog = + gtk_message_dialog_new (w, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("Cannot load syntax file '%s'"), + fn); + + g_free (fn); + + g_object_set (dialog, "icon-name", "psppicon", NULL); + + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + err->message); + + gtk_dialog_run (GTK_DIALOG (dialog)); + + gtk_widget_destroy (dialog); +} /* Loads the buffer from the file called FILENAME */ -gboolean -psppire_syntax_window_load_from_file (PsppireSyntaxWindow *se, - const gchar *filename, - GError **err) +static gboolean +syntax_load (PsppireWindow *window, const gchar *filename) { + GError *err = NULL; gchar *text; GtkTextIter iter; - - gchar *glibfilename = g_filename_from_utf8 (filename, -1, 0, 0, err); - - if ( ! glibfilename ) - return FALSE; + PsppireSyntaxWindow *sw = PSPPIRE_SYNTAX_WINDOW (window); /* FIXME: What if it's a very big file ? */ - if ( ! g_file_get_contents (glibfilename, &text, NULL, err) ) + if ( ! g_file_get_contents (filename, &text, NULL, &err) ) { - g_free (glibfilename); + error_dialog (GTK_WINDOW (window), filename, err); + g_clear_error (&err); return FALSE; } - g_free (glibfilename); - - gtk_text_buffer_get_iter_at_line (se->buffer, &iter, 0); - gtk_text_buffer_insert (se->buffer, &iter, text, -1); + gtk_text_buffer_get_iter_at_line (sw->buffer, &iter, 0); - psppire_window_set_filename (PSPPIRE_WINDOW (se), filename); + gtk_text_buffer_insert (sw->buffer, &iter, text, -1); - gtk_text_buffer_set_modified (se->buffer, FALSE); + gtk_text_buffer_set_modified (sw->buffer, FALSE); return TRUE; } @@ -600,4 +611,5 @@ static void psppire_syntax_window_iface_init (PsppireWindowIface *iface) { iface->save = syntax_save; + iface->load = syntax_load; }