Updated Spanish translation
[anjuta-git-plugin.git] / plugins / sourceview / sourceview-print.c
blobbf6894bf7bae656eac4bdd5cb02ac8533859f3cd
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #include "sourceview-print.h"
18 #include "sourceview-private.h"
20 #include <libanjuta/anjuta-debug.h>
22 #include <libgnomeprintui/gnome-print-job-preview.h>
23 #include <libgnomeprintui/gnome-print-dialog.h>
25 #include <gtksourceview/gtksourceview.h>
26 #include <gtksourceview/gtksourcelanguage.h>
27 #include <gtksourceview/gtksourcelanguagesmanager.h>
28 #include <gtksourceview/gtksourceprintjob.h>
30 #include <libanjuta/interfaces/ianjuta-editor.h>
32 static GtkSourcePrintJob*
33 create_print_job(Sourceview* sv)
35 GtkSourcePrintJob *job;
36 GtkSourceView *view;
37 GtkSourceBuffer *buffer;
38 const gchar *filename;
40 g_return_val_if_fail (sv != NULL, NULL);
42 view = GTK_SOURCE_VIEW(sv->priv->view);
43 buffer = GTK_SOURCE_BUFFER (sv->priv->document);
45 job = gtk_source_print_job_new (NULL);
46 gtk_source_print_job_setup_from_view (job, view);
47 gtk_source_print_job_set_wrap_mode (job, GTK_WRAP_CHAR);
48 gtk_source_print_job_set_highlight (job, TRUE);
49 gtk_source_print_job_set_print_numbers (job, 1);
51 gtk_source_print_job_set_header_format (job,
52 "Printed on %A",
53 NULL,
54 "%F",
55 TRUE);
57 filename = ianjuta_editor_get_filename(IANJUTA_EDITOR(sv), NULL);
59 gtk_source_print_job_set_footer_format (job,
60 "%T",
61 filename,
62 "Page %N/%Q",
63 TRUE);
65 gtk_source_print_job_set_print_header (job, TRUE);
66 gtk_source_print_job_set_print_footer (job, TRUE);
68 return job;
71 static GtkWidget *
72 sourceview_print_dialog_new (GtkSourcePrintJob *job, GtkSourceBuffer* buffer)
74 GtkWidget *dialog;
75 gint selection_flag;
76 gint lines;
77 GnomePrintConfig *config;
79 if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), NULL, NULL))
80 selection_flag = GNOME_PRINT_RANGE_SELECTION_UNSENSITIVE;
81 else
82 selection_flag = GNOME_PRINT_RANGE_SELECTION;
84 config = gtk_source_print_job_get_config (GTK_SOURCE_PRINT_JOB (job));
86 dialog = g_object_new (GNOME_TYPE_PRINT_DIALOG, "print_config", config, NULL);
88 gnome_print_dialog_construct (GNOME_PRINT_DIALOG (dialog),
89 (const unsigned char *)_("Print"),
90 GNOME_PRINT_DIALOG_RANGE | GNOME_PRINT_DIALOG_COPIES);
92 lines = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (buffer));
94 gnome_print_dialog_construct_range_page (GNOME_PRINT_DIALOG (dialog),
95 GNOME_PRINT_RANGE_ALL |
96 GNOME_PRINT_RANGE_RANGE |
97 selection_flag,
98 1, lines, (const unsigned char *)"A",
99 (const unsigned char *)_("Lines"));
101 return dialog;
104 void
105 sourceview_print(Sourceview* sv)
107 GtkSourcePrintJob* job = create_print_job(sv);
108 GtkWidget* print= sourceview_print_dialog_new(job,
109 GTK_SOURCE_BUFFER(sv->priv->document));
110 GnomePrintButtons result = gtk_dialog_run(GTK_DIALOG(print));
112 switch (result)
114 case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
115 sourceview_print_preview(sv);
116 break;
117 case GNOME_PRINT_DIALOG_RESPONSE_PRINT:
119 GnomePrintJob* gjob = gtk_source_print_job_print (job);
120 gnome_print_job_print(gjob);
121 g_object_unref(gjob);
122 break;
124 case GNOME_PRINT_DIALOG_RESPONSE_CANCEL:
125 break;
126 default:
127 DEBUG_PRINT("Unknown print response");
129 gtk_widget_destroy(print);
130 g_object_unref(job);
133 void
134 sourceview_print_preview(Sourceview* sv)
136 GtkSourcePrintJob* job;
137 GnomePrintJob* gjob;
138 GtkWidget *preview;
140 job = create_print_job(sv);
142 gjob = gtk_source_print_job_print (job);
143 preview = gnome_print_job_preview_new (gjob,
144 (const guchar *)_("Print preview"));
146 gtk_widget_show(preview);
148 g_object_unref(job);
149 g_object_unref(gjob);