X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-syntax-window.c;h=03b4093bbba6eb930b3c5e3f27efc7b44b7e6e3e;hb=5dd7174d3acde86cfd7e929dabcafe71894a2a3f;hp=2a09c71c027b8a68380866e0011f84f31decbb57;hpb=ca259adce7a069f58545de7511e17d73c9e0a868;p=pspp diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index 2a09c71c02..03b4093bbb 100644 --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -28,6 +28,7 @@ #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" @@ -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); @@ -562,34 +556,22 @@ psppire_syntax_window_new (void) /* 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) { 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) ) - { - g_free (glibfilename); - return FALSE; - } - g_free (glibfilename); - - gtk_text_buffer_get_iter_at_line (se->buffer, &iter, 0); + if ( ! g_file_get_contents (filename, &text, NULL, NULL) ) + return FALSE; - 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 +582,5 @@ static void psppire_syntax_window_iface_init (PsppireWindowIface *iface) { iface->save = syntax_save; + iface->load = syntax_load; }