print-preview: add a print button to the preview toolbar, to immediately

print the previewed document.
This commit is contained in:
Michael Webster 2019-11-05 20:07:35 -05:00
parent 9d3d2acfd9
commit 8763fbf5df
5 changed files with 72 additions and 4 deletions

View File

@ -979,6 +979,17 @@ load_print_settings (XedApp *app)
}
}
static void
setup_actions (XedApp *app)
{
GSimpleAction *action;
action = g_simple_action_new ("print-now", NULL);
g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
g_object_unref (action);
}
static void
xed_app_init (XedApp *app)
{
@ -994,6 +1005,8 @@ xed_app_init (XedApp *app)
#endif
load_accels ();
setup_actions (app);
}
static gboolean

View File

@ -66,6 +66,6 @@ _xed_cmd_file_print (GtkAction *action,
if (tab == NULL)
return;
_xed_tab_print (tab);
_xed_tab_print (tab, TRUE);
}

View File

@ -57,6 +57,7 @@ struct _XedPrintPreviewPrivate
GtkWidget *zoom_fit;
GtkWidget *zoom_in;
GtkWidget *zoom_out;
GtkWidget *print_now;
/* real size of the page in inches */
double paper_w;
@ -534,6 +535,16 @@ zoom_out_button_clicked (GtkWidget *button,
zoom_out (preview);
}
static void
print_now_button_clicked (GtkWidget *button,
XedPrintPreview *preview)
{
GAction *action = g_action_map_lookup_action (G_ACTION_MAP (g_application_get_default ()),
"print-now");
g_action_activate (action, NULL);
}
static void
close_button_clicked (GtkWidget *button,
XedPrintPreview *preview)
@ -679,6 +690,23 @@ create_bar (XedPrintPreview *preview)
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (i), box);
priv->print_now = gtk_button_new_from_icon_name ("document-print-symbolic", GTK_ICON_SIZE_MENU);
gtk_box_pack_start (GTK_BOX (box), priv->print_now, FALSE, FALSE, 0);
gtk_widget_set_tooltip_text (priv->print_now, _("Print this document"));
g_signal_connect (priv->print_now, "clicked",
G_CALLBACK (print_now_button_clicked), preview);
gtk_widget_show_all (GTK_WIDGET (i));
i = gtk_separator_tool_item_new ();
gtk_widget_show (GTK_WIDGET (i));
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1);
i = gtk_tool_item_new ();
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (i), box);
close_button = gtk_button_new_with_mnemonic (_("_Close preview"));
gtk_box_pack_start (GTK_BOX (box), close_button, FALSE, FALSE, 0);
gtk_widget_set_tooltip_text (close_button, _("Close print preview"));

View File

@ -273,6 +273,11 @@ xed_tab_dispose (GObject *object)
clear_loading (tab);
GAction *action = g_action_map_lookup_action (G_ACTION_MAP (g_application_get_default ()),
"print-now");
g_signal_handlers_disconnect_by_data (action, tab);
G_OBJECT_CLASS (xed_tab_parent_class)->dispose (object);
}
@ -1147,6 +1152,14 @@ view_focused_in (GtkWidget *widget,
return GDK_EVENT_PROPAGATE;
}
static void
print_now_action_cb (XedTab *tab)
{
g_return_if_fail (XED_IS_TAB (tab));
_xed_tab_print (tab, FALSE);
}
static void
xed_tab_init (XedTab *tab)
{
@ -1198,6 +1211,12 @@ xed_tab_init (XedTab *tab)
G_CALLBACK (view_focused_in), tab);
g_signal_connect_after (view, "realize",
G_CALLBACK (view_realized), tab);
GAction *action = g_action_map_lookup_action (G_ACTION_MAP (g_application_get_default ()),
"print-now");
g_signal_connect_swapped (action, "activate",
G_CALLBACK (print_now_action_cb), tab);
}
GtkWidget *
@ -2811,7 +2830,8 @@ xed_tab_print_or_print_preview (XedTab *tab,
}
void
_xed_tab_print (XedTab *tab)
_xed_tab_print (XedTab *tab,
gboolean with_dialog)
{
g_return_if_fail (XED_IS_TAB (tab));
@ -2823,7 +2843,14 @@ _xed_tab_print (XedTab *tab)
gtk_widget_destroy (tab->priv->print_preview);
}
xed_tab_print_or_print_preview (tab, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
if (with_dialog)
{
xed_tab_print_or_print_preview (tab, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
}
else
{
xed_tab_print_or_print_preview (tab, GTK_PRINT_OPERATION_ACTION_PRINT);
}
}
void

View File

@ -153,7 +153,7 @@ void _xed_tab_save_as_async (XedTab *tab,
GAsyncReadyCallback callback,
gpointer user_data);
void _xed_tab_print (XedTab *tab);
void _xed_tab_print (XedTab *tab, gboolean show_dialog);
void _xed_tab_print_preview (XedTab *tab);
void _xed_tab_mark_for_closing (XedTab *tab);
gboolean _xed_tab_get_can_close (XedTab *tab);