[gnome-builder/wip/chergert/layout: 107/118] editor: bring back the print operation
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/layout: 107/118] editor: bring back the print operation
- Date: Wed, 5 Jul 2017 11:57:03 +0000 (UTC)
commit 29b1475efff2b57374a17e10df45c30965dce925
Author: Christian Hergert <chergert redhat com>
Date: Wed Jul 5 00:32:07 2017 -0700
editor: bring back the print operation
This brings back the print operation from our main branch and
ensures it is wired up correctly from the stack menu.
data/gtk/menus.ui | 1 +
libide/editor/ide-editor-view-actions.c | 68 +++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/data/gtk/menus.ui b/data/gtk/menus.ui
index 6c3db9b..37c815d 100644
--- a/data/gtk/menus.ui
+++ b/data/gtk/menus.ui
@@ -254,6 +254,7 @@
</item>
<item>
<attribute name="label" translatable="yes">Print…</attribute>
+ <attribute name="action">editor-view.print</attribute>
</item>
</section>
<section id="editor-document-preferences-section">
diff --git a/libide/editor/ide-editor-view-actions.c b/libide/editor/ide-editor-view-actions.c
index cd8e000..1d39843 100644
--- a/libide/editor/ide-editor-view-actions.c
+++ b/libide/editor/ide-editor-view-actions.c
@@ -24,10 +24,77 @@
#include "buffers/ide-buffer.h"
#include "buffers/ide-buffer-manager.h"
#include "editor/ide-editor-private.h"
+#include "editor/ide-editor-print-operation.h"
#include "util/ide-progress.h"
#include "vcs/ide-vcs.h"
static void
+handle_print_result (IdeEditorView *self,
+ GtkPrintOperation *operation,
+ GtkPrintOperationResult result)
+{
+ if (result == GTK_PRINT_OPERATION_RESULT_ERROR)
+ {
+ g_autoptr(GError) error = NULL;
+
+ gtk_print_operation_get_error (operation, &error);
+
+ /* info bar */
+ g_warning ("%s", error->message);
+ // ide_layout_view_add_error (...);
+ }
+}
+
+static void
+print_done (GtkPrintOperation *operation,
+ GtkPrintOperationResult result,
+ gpointer user_data)
+{
+ IdeEditorView *self = user_data;
+
+ g_assert (GTK_IS_PRINT_OPERATION (operation));
+ g_assert (IDE_IS_EDITOR_VIEW (self));
+
+ handle_print_result (self, operation, result);
+
+ g_object_unref (operation);
+ g_object_unref (self);
+}
+
+static void
+ide_editor_view_actions_print (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ g_autoptr(IdeEditorPrintOperation) operation = NULL;
+ IdeEditorView *self = user_data;
+ IdeSourceView *source_view;
+ GtkWidget *toplevel;
+ GtkPrintOperationResult result;
+
+ g_assert (IDE_IS_EDITOR_VIEW (self));
+
+ toplevel = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_WINDOW);
+
+ source_view = ide_editor_view_get_view (self);
+ operation = ide_editor_print_operation_new (source_view);
+
+ /* keep a ref until "done" is emitted */
+ g_object_ref (operation);
+ g_signal_connect_after (g_object_ref (operation),
+ "done",
+ G_CALLBACK (print_done),
+ g_object_ref (self));
+
+ result = gtk_print_operation_run (GTK_PRINT_OPERATION (operation),
+ GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+ GTK_WINDOW (toplevel),
+ NULL);
+
+ handle_print_result (self, GTK_PRINT_OPERATION (operation), result);
+}
+
+static void
ide_editor_view_actions_save_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
@@ -139,6 +206,7 @@ ide_editor_view_actions_save (GSimpleAction *action,
static const GActionEntry editor_view_entries[] = {
{ "save", ide_editor_view_actions_save },
+ { "print", ide_editor_view_actions_print },
};
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]