Commit 34f13278 authored by Johannes Schmid's avatar Johannes Schmid

sourceview: Moved print preferences to print dialog

parent 16508522
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkAdjustment" id="adjustment1">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">4</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="upper">200</property>
<property name="value">80</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkWindow" id="preferences_dialog">
<property name="title">window1</property>
<child>
......@@ -36,7 +23,6 @@
<child>
<object class="GtkVBox" id="vbox1111">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table15">
<property name="visible">True</property>
......@@ -172,7 +158,6 @@
<object class="GtkVBox" id="vbox1120">
<property name="visible">True</property>
<property name="border_width">5</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkCheckButton" id="preferences_toggle:bool:1:0:sourceview-syntax-highlight">
......@@ -265,7 +250,6 @@
<child>
<object class="GtkVBox" id="vbox32">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkFrame" id="frame2">
......@@ -277,7 +261,6 @@
<object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="border_width">5</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkCheckButton" id="preferences_toggle:bool:0:0:sourceview-currentline-highlight">
......@@ -515,7 +498,6 @@
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="border_width">5</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkComboBox" id="combo_styles">
<property name="visible">True</property>
......@@ -567,132 +549,20 @@
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="page3">
<property name="visible">True</property>
<property name="border_width">5</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkTable" id="table17">
<property name="visible">True</property>
<property name="border_width">10</property>
<property name="n_rows">6</property>
<property name="column_spacing">5</property>
<property name="row_spacing">5</property>
<child>
<object class="GtkCheckButton" id="preferences_toggle:bool:1:0:print-header">
<property name="label" translatable="yes">Print page header</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="preferences_toggle:bool:1:0:print-footer">
<property name="label" translatable="yes">Print page footer</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="preferences_toggle:bool:1:0:print-linenumbers">
<property name="label" translatable="yes">Print line numbers</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="preferences_toggle:bool:1:0:print-highlight">
<property name="label" translatable="yes">Highlight syntax</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="preferences_toggle:bool:1:0:print-linewrap">
<property name="label" translatable="yes">Wrap long lines to fit on paper</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label129">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="label" translatable="yes">Print options</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="label12352">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="label" translatable="yes">Printing</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="upper">200</property>
<property name="value">80</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment1">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">4</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
</interface>
......@@ -337,7 +337,14 @@ sourceview_prefs_init(Sourceview* sv)
void sourceview_prefs_destroy(Sourceview* sv)
{
g_object_unref (sv->priv->settings);
g_object_unref (sv->priv->msgman_settings);
g_object_unref (sv->priv->docman_settings);
if (sv->priv->settings)
g_object_unref (sv->priv->settings);
if (sv->priv->msgman_settings)
g_object_unref (sv->priv->msgman_settings);
if (sv->priv->docman_settings)
g_object_unref (sv->priv->docman_settings);
sv->priv->settings = NULL;
sv->priv->msgman_settings = NULL;
sv->priv->docman_settings = NULL;
}
......@@ -19,11 +19,11 @@
#include <gtksourceview/gtksourceprintcompositor.h>
#include <libanjuta/interfaces/ianjuta-document.h>
#define PRINT_LINEWRAP "print.linewrap"
#define PRINT_HEADER "print.header"
#define PRINT_FOOTER "print.footer"
#define PRINT_HIGHLIGHT "print.highlight"
#define PRINT_LINENUMBERS "print.linenumbers"
#define PRINT_LINEWRAP "sourceview-print-linewrap"
#define PRINT_HEADER "sourceview-print-header"
#define PRINT_FOOTER "sourceview-print-footer"
#define PRINT_HIGHLIGHT "sourceview-print-highlight"
#define PRINT_LINENUMBERS "sourceview-print-linenumbers"
typedef struct _SourceviewPrinting SourceviewPrinting;
......@@ -73,11 +73,78 @@ end_print (GtkPrintOperation *operation,
g_slice_free (SourceviewPrinting, printing);
}
static void
custom_widget_apply (GtkPrintOperation* operation,
GtkWidget* widget,
SourceviewPrinting* printing)
{
if (g_settings_get_boolean (printing->sv->priv->settings, PRINT_LINEWRAP))
{
gtk_source_print_compositor_set_wrap_mode (printing->compositor,
GTK_WRAP_WORD_CHAR);
}
else
gtk_source_print_compositor_set_wrap_mode (printing->compositor,
GTK_WRAP_NONE);
gtk_source_print_compositor_set_print_line_numbers (printing->compositor,
g_settings_get_boolean (printing->sv->priv->settings,
PRINT_LINENUMBERS));
gtk_source_print_compositor_set_print_header (printing->compositor,
g_settings_get_boolean (printing->sv->priv->settings,
PRINT_HEADER));
gtk_source_print_compositor_set_print_footer (printing->compositor,
g_settings_get_boolean (printing->sv->priv->settings,
PRINT_FOOTER));
gtk_source_print_compositor_set_highlight_syntax (printing->compositor,
g_settings_get_boolean (printing->sv->priv->settings,
PRINT_HIGHLIGHT));
}
static GObject*
create_custom_widget (GtkPrintOperation* operation,
Sourceview* sv)
{
GtkWidget* toggle_linewrap =
gtk_check_button_new_with_label (_("Wrap lines"));
GtkWidget* toggle_linenumbers =
gtk_check_button_new_with_label (_("Line numbers"));
GtkWidget* toggle_header =
gtk_check_button_new_with_label (_("Header"));
GtkWidget* toggle_footer =
gtk_check_button_new_with_label (_("Footer"));
GtkWidget* toggle_highlight =
gtk_check_button_new_with_label (_("Highlight source code"));
GtkWidget* vbox = gtk_vbox_new (TRUE, 5);
g_settings_bind (sv->priv->settings, PRINT_LINEWRAP,
toggle_linewrap, "active", G_SETTINGS_BIND_DEFAULT);
g_settings_bind (sv->priv->settings, PRINT_LINENUMBERS,
toggle_linenumbers, "active", G_SETTINGS_BIND_DEFAULT);
g_settings_bind (sv->priv->settings, PRINT_HEADER,
toggle_header, "active", G_SETTINGS_BIND_DEFAULT);
g_settings_bind (sv->priv->settings, PRINT_FOOTER,
toggle_footer, "active", G_SETTINGS_BIND_DEFAULT);
g_settings_bind (sv->priv->settings, PRINT_HIGHLIGHT,
toggle_highlight, "active", G_SETTINGS_BIND_DEFAULT);
gtk_box_pack_start (GTK_BOX (vbox), toggle_linewrap, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (vbox), toggle_linenumbers, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (vbox), toggle_header, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (vbox), toggle_footer, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (vbox), toggle_highlight, FALSE, FALSE, 5);
gtk_widget_show_all (vbox);
return G_OBJECT (vbox);
}
static GtkPrintOperation*
print_setup (Sourceview* sv)
{
/* FIXME */
#if 0
GtkSourceView *view = GTK_SOURCE_VIEW (sv->priv->view);
GtkSourcePrintCompositor *compositor;
GtkPrintOperation *operation;
......@@ -90,19 +157,6 @@ print_setup (Sourceview* sv)
compositor = gtk_source_print_compositor_new_from_view (view);
if (g_settings_get_int (sv->priv->settings, PRINT_LINEWRAP))
{
gtk_source_print_compositor_set_wrap_mode (compositor,
GTK_WRAP_WORD_CHAR);
}
else
gtk_source_print_compositor_set_wrap_mode (compositor,
GTK_WRAP_NONE);
gtk_source_print_compositor_set_print_line_numbers (compositor,
anjuta_preferences_get_bool (sv->priv->prefs,
PRINT_LINENUMBERS));
gtk_source_print_compositor_set_header_format (compositor,
TRUE,
"%x",
......@@ -114,25 +168,13 @@ print_setup (Sourceview* sv)
"%T",
basename,
"Page %N/%Q");
gtk_source_print_compositor_set_print_header (compositor,
anjuta_preferences_get_bool (sv->priv->prefs,
PRINT_HEADER));
gtk_source_print_compositor_set_print_footer (compositor,
anjuta_preferences_get_bool (sv->priv->prefs,
PRINT_FOOTER));
gtk_source_print_compositor_set_highlight_syntax (compositor,
anjuta_preferences_get_bool (sv->priv->prefs,
PRINT_HIGHLIGHT)),
operation = gtk_print_operation_new ();
gtk_print_operation_set_job_name (operation, basename);
gtk_print_operation_set_show_progress (operation, TRUE);
printing->compositor = compositor;
printing->sv = sv;
printing->status = anjuta_shell_get_status (sv->priv->plugin->shell, NULL);
......@@ -143,30 +185,33 @@ print_setup (Sourceview* sv)
G_CALLBACK (draw_page), printing);
g_signal_connect (G_OBJECT (operation), "end-print",
G_CALLBACK (end_print), printing);
g_signal_connect (G_OBJECT (operation), "create-custom-widget",
G_CALLBACK (create_custom_widget), sv);
g_signal_connect (G_OBJECT (operation), "custom-widget-apply",
G_CALLBACK (custom_widget_apply), printing);
anjuta_status_progress_reset (printing->status);
anjuta_status_progress_add_ticks (printing->status, 100);
g_free (basename);
return operation;
#endif
return NULL;
}
void
sourceview_print(Sourceview* sv)
{
GtkPrintOperation* operation = print_setup (sv);
gtk_print_operation_run (operation,
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
NULL, NULL);
g_object_unref (operation);
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
NULL, NULL);
g_object_unref (operation);
}
void
sourceview_print_preview(Sourceview* sv)
{
{
GtkPrintOperation* operation = print_setup (sv);
gtk_print_operation_run (operation,
GTK_PRINT_OPERATION_ACTION_PREVIEW,
......
<key name="sourceview-style" type="s">
<default>"tango"</default>
</key>
<key name="sourceview-print-linewrap" type="b">
<default>true</default>
</key>
<key name="sourceview-print-header" type="b">
<default>false</default>
</key>
<key name="sourceview-print-footer" type="b">
<default>false</default>
</key>
<key name="sourceview-print-highlight" type="b">
<default>true</default>
</key>
<key name="sourceview-print-linenumbers" type="b">
<default>false</default>
</key>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment