From: John Darrington Date: Sun, 17 Oct 2010 19:04:28 +0000 (+0200) Subject: Merge commit 'origin/master' into sso X-Git-Tag: v0.7.9~159^2~1 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a258e53c63a08b0ec48aea8f03808eb651729424;p=pspp-builds.git Merge commit 'origin/master' into sso Conflicts: src/ui/gui/psppire-syntax-window.c --- a258e53c63a08b0ec48aea8f03808eb651729424 diff --cc src/ui/gui/psppire-syntax-window.c index c162e219,ccf94e7b..c7251a1a --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@@ -108,27 -129,11 +135,33 @@@ psppire_syntax_window_dispose (GObject static void psppire_syntax_window_class_init (PsppireSyntaxWindowClass *class) { + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + + GtkSourceLanguageManager *lm = gtk_source_language_manager_get_default (); + + const gchar * const *existing_paths = gtk_source_language_manager_get_search_path (lm); + gchar **new_paths = g_strdupv ((gchar **)existing_paths); + int n = g_strv_length ((gchar **) existing_paths); + + new_paths = g_realloc (new_paths, (n + 2) * sizeof (*new_paths)); + new_paths[n] = g_strdup (relocate (PKGDATADIR)); + new_paths[n+1] = NULL; + + lm = gtk_source_language_manager_new (); + gtk_source_language_manager_set_search_path (lm, new_paths); + + class->lan = gtk_source_language_manager_get_language (lm, "pspp"); + + if (class->lan == NULL) + g_warning ("pspp.lang file not found. Syntax highlighting will not be available."); + + parent_class = g_type_class_peek_parent (class); + + g_strfreev (new_paths); ++ + parent_class = g_type_class_peek_parent (class); + + gobject_class->dispose = psppire_syntax_window_dispose; } @@@ -624,34 -610,8 +661,32 @@@ psppire_syntax_window_init (PsppireSynt GtkClipboard *clip_selection = gtk_widget_get_clipboard (GTK_WIDGET (window), GDK_SELECTION_CLIPBOARD); GtkClipboard *clip_primary = gtk_widget_get_clipboard (GTK_WIDGET (window), GDK_SELECTION_PRIMARY); ++ + window->print_settings = NULL; + window->undo_menuitem = get_action_assert (xml, "edit_undo"); + window->redo_menuitem = get_action_assert (xml, "edit_redo"); + + if (class->lan) + window->buffer = gtk_source_buffer_new_with_language (class->lan); + else + window->buffer = gtk_source_buffer_new (NULL); + + gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), GTK_TEXT_BUFFER (window->buffer)); + + g_object_set (window->buffer, + "highlight-matching-brackets", TRUE, + NULL); + + g_object_set (text_view, + "show-line-numbers", TRUE, + "show-line-marks", TRUE, + "auto-indent", TRUE, + "indent-width", 4, + "highlight-current-line", TRUE, + NULL); + - g_signal_connect_swapped (clip_primary, "owner-change", G_CALLBACK (selection_changed), window); - - g_signal_connect (clip_selection, "owner-change", G_CALLBACK (on_owner_change), window); - window->cliptext = NULL; + window->dispose_has_run = FALSE; window->edit_delete = get_action_assert (xml, "edit_delete"); window->edit_copy = get_action_assert (xml, "edit_copy"); @@@ -663,27 -624,18 +698,34 @@@ window->sb = get_widget_assert (xml, "statusbar2"); window->text_context = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->sb), "Text Context"); - g_signal_connect (window->buffer, "changed", G_CALLBACK (on_text_changed), window); + g_signal_connect (window->buffer, "changed", + G_CALLBACK (on_text_changed), window); - g_signal_connect (window->buffer, "modified-changed", + g_signal_connect (window->buffer, "modified-changed", G_CALLBACK (on_modified_changed), window); + g_signal_connect_swapped (get_action_assert (xml, "file_print"), "activate", + G_CALLBACK (psppire_syntax_window_print), window); + + + g_signal_connect_swapped (window->undo_menuitem, + "activate", + G_CALLBACK (undo_last_edit), + window); + + g_signal_connect_swapped (window->redo_menuitem, + "activate", + G_CALLBACK (redo_last_edit), + window); + + undo_redo_update (window); + + window->sel_handler = g_signal_connect_swapped (clip_primary, "owner-change", + G_CALLBACK (selection_changed), window); + + window->ps_handler = g_signal_connect (clip_selection, "owner-change", + G_CALLBACK (set_paste_sensitivity), window); + connect_help (xml); gtk_container_add (GTK_CONTAINER (window), box); @@@ -876,112 -825,3 +918,113 @@@ psppire_syntax_window_iface_init (Psppi iface->load = syntax_load; } ++ + + +static void +undo_redo_update (PsppireSyntaxWindow *window) +{ + gtk_action_set_sensitive (window->undo_menuitem, + gtk_source_buffer_can_undo (window->buffer)); + + gtk_action_set_sensitive (window->redo_menuitem, + gtk_source_buffer_can_redo (window->buffer)); +} + +static void +undo_last_edit (PsppireSyntaxWindow *window) +{ + gtk_source_buffer_undo (window->buffer); + undo_redo_update (window); +} + +static void +redo_last_edit (PsppireSyntaxWindow *window) +{ + gtk_source_buffer_redo (window->buffer); + undo_redo_update (window); +} + + + +/* Printing related stuff */ + + +static void +begin_print (GtkPrintOperation *operation, + GtkPrintContext *context, + PsppireSyntaxWindow *window) +{ + window->compositor = + gtk_source_print_compositor_new (window->buffer); +} + + +static void +end_print (GtkPrintOperation *operation, + GtkPrintContext *context, + PsppireSyntaxWindow *window) +{ + g_object_unref (window->compositor); + window->compositor = NULL; +} + + + +static gboolean +paginate (GtkPrintOperation *operation, + GtkPrintContext *context, + PsppireSyntaxWindow *window) +{ + if (gtk_source_print_compositor_paginate (window->compositor, context)) + { + gint n_pages = gtk_source_print_compositor_get_n_pages (window->compositor); + gtk_print_operation_set_n_pages (operation, n_pages); + + return TRUE; + } + + return FALSE; +} + +static void +draw_page (GtkPrintOperation *operation, + GtkPrintContext *context, + gint page_nr, + PsppireSyntaxWindow *window) +{ + gtk_source_print_compositor_draw_page (window->compositor, + context, + page_nr); +} + + + +static void +psppire_syntax_window_print (PsppireSyntaxWindow *window) +{ + GtkPrintOperationResult res; + + GtkPrintOperation *print = gtk_print_operation_new (); + + if (window->print_settings != NULL) + gtk_print_operation_set_print_settings (print, window->print_settings); + + + g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), window); + g_signal_connect (print, "end_print", G_CALLBACK (end_print), window); + g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), window); + g_signal_connect (print, "paginate", G_CALLBACK (paginate), window); + + res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, + GTK_WINDOW (window), NULL); + + if (res == GTK_PRINT_OPERATION_RESULT_APPLY) + { + if (window->print_settings != NULL) + g_object_unref (window->print_settings); + window->print_settings = g_object_ref (gtk_print_operation_get_print_settings (print)); + } + + g_object_unref (print); +}