#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"
GtkWidget *se = psppire_syntax_window_new ();
- if ( psppire_syntax_window_load_from_file (PSPPIRE_SYNTAX_WINDOW (se), file_name, NULL) )
- ;
-
- 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);
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
window);
#endif
- g_signal_connect (get_action_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_action_assert (xml,"help_reference"),
"activate",
{
- GtkUIManager *uim = GTK_UI_MANAGER (get_action_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);
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;
}
psppire_syntax_window_iface_init (PsppireWindowIface *iface)
{
iface->save = syntax_save;
+ iface->load = syntax_load;
}