X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-syntax-window.c;h=66838dd307172943d0a59fd26097013192d8e6c4;hb=a232eb40325b126daabcdf28ca54da794bd6a29f;hp=b5cf0d3345d27cc45474bcc24e3cbe53c6562c0c;hpb=fe8dc2171009e90d2335f159d05f7e6660e24780;p=pspp diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index b5cf0d3345..66838dd307 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, 2009, 2010, 2011 Free Software Foundation + Copyright (C) 2008, 2009, 2010, 2011, 2012, 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 @@ -24,7 +24,6 @@ #include #include - #include "language/lexer/lexer.h" #include "libpspp/encoding-guesser.h" #include "libpspp/i18n.h" @@ -32,13 +31,13 @@ #include "ui/gui/executor.h" #include "ui/gui/help-menu.h" #include "ui/gui/helper.h" +#include "ui/gui/builder-wrapper.h" #include "ui/gui/psppire-data-window.h" #include "ui/gui/psppire-encoding-selector.h" -#include "ui/gui/psppire-syntax-window.h" +#include "ui/gui/psppire-lex-reader.h" #include "ui/gui/psppire-syntax-window.h" #include "ui/gui/psppire-window-register.h" #include "ui/gui/psppire.h" -#include "ui/gui/psppire.h" #include "gl/localcharset.h" #include "gl/xalloc.h" @@ -251,10 +250,7 @@ editor_execute_syntax (const PsppireSyntaxWindow *sw, GtkTextIter start, GtkTextIter stop) { PsppireWindow *win = PSPPIRE_WINDOW (sw); - struct lex_reader *reader; - gchar *text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (sw->buffer), &start, &stop, FALSE); - reader = lex_reader_for_string (text); - g_free (text); + struct lex_reader *reader = lex_reader_for_gtk_text_buffer (GTK_TEXT_BUFFER (sw->buffer), start, stop); lex_reader_set_file_name (reader, psppire_window_get_filename (win)); @@ -300,7 +296,7 @@ clipboard_get_cb (GtkClipboard *clipboard, PsppireSyntaxWindow *sw = data; g_assert (info == SELECT_FMT_TEXT); - gtk_selection_data_set (selection_data, selection_data->target, + gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 8, (const guchar *) sw->cliptext, strlen (sw->cliptext)); @@ -373,30 +369,6 @@ on_edit_copy (PsppireSyntaxWindow *sw) set_clip (sw, &begin, &end); } - -/* A callback for when the clipboard contents have been received */ -static void -contents_received_callback (GtkClipboard *clipboard, - GtkSelectionData *sd, - gpointer data) -{ - gchar *c; - PsppireSyntaxWindow *syntax_window = data; - - if ( sd->length < 0 ) - return; - - if ( sd->type != gdk_atom_intern ("UTF8_STRING", FALSE)) - return; - - c = (gchar *) sd->data; - - gtk_text_buffer_insert_at_cursor (GTK_TEXT_BUFFER (syntax_window->buffer), - (gchar *) sd->data, - sd->length); - -} - static void on_edit_paste (PsppireSyntaxWindow *sw) { @@ -404,10 +376,7 @@ on_edit_paste (PsppireSyntaxWindow *sw) GtkClipboard *clipboard = gtk_clipboard_get_for_display (display, GDK_SELECTION_CLIPBOARD); - gtk_clipboard_request_contents (clipboard, - gdk_atom_intern ("UTF8_STRING", TRUE), - contents_received_callback, - sw); + gtk_text_buffer_paste_clipboard (GTK_TEXT_BUFFER (sw->buffer), clipboard, NULL, TRUE); } @@ -596,10 +565,12 @@ syntax_pick_filename (PsppireWindow *window) gtk_file_chooser_dialog_new (_("Save Syntax"), GTK_WINDOW (se), GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + _("Cancel"), GTK_RESPONSE_CANCEL, + _("Save"), GTK_RESPONSE_ACCEPT, NULL); + g_object_set (dialog, "local-only", FALSE, NULL); + filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) ")); gtk_file_filter_add_pattern (filter, "*.sps"); @@ -669,12 +640,13 @@ on_quit (GtkMenuItem *menuitem, gpointer user_data) static void -load_and_show_syntax_window (GtkWidget *se, const gchar *filename) +load_and_show_syntax_window (GtkWidget *se, const gchar *filename, + const gchar *encoding) { gboolean ok; gtk_source_buffer_begin_not_undoable_action (PSPPIRE_SYNTAX_WINDOW (se)->buffer); - ok = psppire_window_load (PSPPIRE_WINDOW (se), filename); + ok = psppire_window_load (PSPPIRE_WINDOW (se), filename, encoding, NULL); gtk_source_buffer_end_not_undoable_action (PSPPIRE_SYNTAX_WINDOW (se)->buffer); if (ok ) @@ -693,10 +665,10 @@ create_syntax_window (void) void open_syntax_window (const char *file_name, const gchar *encoding) { - GtkWidget *se = psppire_syntax_window_new (encoding); + GtkWidget *se = psppire_syntax_window_new (NULL); if ( file_name) - load_and_show_syntax_window (se, file_name); + load_and_show_syntax_window (se, file_name, encoding); } @@ -725,7 +697,7 @@ static void psppire_syntax_window_init (PsppireSyntaxWindow *window) { GtkBuilder *xml = builder_new ("syntax-editor.ui"); - GtkWidget *box = gtk_vbox_new (FALSE, 0); + GtkWidget *box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); GtkWidget *menubar = get_widget_assert (xml, "menubar"); GtkWidget *sw = get_widget_assert (xml, "scrolledwindow8"); @@ -892,16 +864,13 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window) G_CALLBACK (psppire_window_minimise_all), NULL); - - - { - GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (xml, "uimanager1", GTK_TYPE_UI_MANAGER)); + GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (xml, "uimanager1", GTK_TYPE_UI_MANAGER)); + GtkWidget *w = gtk_ui_manager_get_widget (uim,"/ui/menubar/windows/windows_minimise_all"); - merge_help_menu (uim); + gtk_menu_shell_append (GTK_MENU_SHELL (menubar), create_help_menu (GTK_WINDOW (window))); - PSPPIRE_WINDOW (window)->menu = - GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar/windows/windows_minimise_all")->parent); + PSPPIRE_WINDOW (window)->menu = GTK_MENU_SHELL (gtk_widget_get_parent (w)); } g_object_unref (xml); @@ -935,7 +904,7 @@ error_dialog (GtkWindow *w, const gchar *filename, GError *err) g_free (fn); - g_object_set (dialog, "icon-name", "psppicon", NULL); + g_object_set (dialog, "icon-name", "pspp", NULL); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", err->message); @@ -949,7 +918,8 @@ error_dialog (GtkWindow *w, const gchar *filename, GError *err) Loads the buffer from the file called FILENAME */ gboolean -syntax_load (PsppireWindow *window, const gchar *filename) +syntax_load (PsppireWindow *window, const gchar *filename, + const gchar *encoding, gpointer not_used) { GError *err = NULL; gchar *text_locale = NULL; @@ -959,8 +929,6 @@ syntax_load (PsppireWindow *window, const gchar *filename) GtkTextIter iter; PsppireSyntaxWindow *sw = PSPPIRE_SYNTAX_WINDOW (window); GtkTextBuffer *buffer = GTK_TEXT_BUFFER (sw->buffer); - gchar *encoding; - char *mime_type; /* FIXME: What if it's a very big file ? */ if ( ! g_file_get_contents (filename, &text_locale, &len_locale, &err) ) @@ -970,15 +938,26 @@ syntax_load (PsppireWindow *window, const gchar *filename) return FALSE; } - /* Determine the file's encoding and update sw->encoding. (The ordering is - important here because encoding_guess_whole_file() often returns its - argument instead of a copy of it.) */ - encoding = g_strdup (encoding_guess_whole_file (sw->encoding, text_locale, - len_locale)); - g_free (sw->encoding); - sw->encoding = encoding; + if (!encoding || !encoding[0]) + { + /* Determine the file's encoding and update sw->encoding. (The ordering + is important here because encoding_guess_whole_file() often returns + its argument instead of a copy of it.) */ + char *guessed_encoding; + + guessed_encoding = g_strdup (encoding_guess_whole_file (sw->encoding, + text_locale, + len_locale)); + g_free (sw->encoding); + sw->encoding = guessed_encoding; + } + else + { + g_free (sw->encoding); + sw->encoding = g_strdup (encoding); + } - text_utf8 = recode_substring_pool ("UTF-8", encoding, + text_utf8 = recode_substring_pool ("UTF-8", sw->encoding, ss_buffer (text_locale, len_locale), NULL).string; free (text_locale); @@ -998,9 +977,7 @@ syntax_load (PsppireWindow *window, const gchar *filename) free (text_utf8); - mime_type = xasprintf ("text/x-spss-syntax; charset=%s", sw->encoding); - add_most_recent (filename, mime_type); - free (mime_type); + add_most_recent (filename, "text/x-spss-syntax", sw->encoding); return TRUE; }