[gnome-text-editor] document: add document actions to source view
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] document: add document actions to source view
- Date: Thu, 1 Jul 2021 21:55:39 +0000 (UTC)
commit d8aa44e5ab84f7b903eedddd540d317c0957817a
Author: Christian Hergert <chergert redhat com>
Date: Thu Jul 1 14:55:31 2021 -0700
document: add document actions to source view
This allows us to activate them from the menus we attach to the source
view such as spelling language.
src/editor-document-private.h | 2 ++
src/editor-document.c | 17 +++++++++++++++++
src/editor-source-view.c | 21 +++++++++++++++++++++
3 files changed, 40 insertions(+)
---
diff --git a/src/editor-document-private.h b/src/editor-document-private.h
index 3df284f..73fac11 100644
--- a/src/editor-document-private.h
+++ b/src/editor-document-private.h
@@ -74,5 +74,7 @@ void _editor_document_guess_language_async (EditorDocumen
gboolean _editor_document_guess_language_finish (EditorDocument *self,
GAsyncResult *result,
GError **error);
+void _editor_document_attach_actions (EditorDocument *self,
+ GtkWidget *widget);
G_END_DECLS
diff --git a/src/editor-document.c b/src/editor-document.c
index d825255..40f6a85 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -1782,3 +1782,20 @@ editor_document_set_spell_checker (EditorDocument *self,
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SPELL_CHECKER]);
}
}
+
+void
+_editor_document_attach_actions (EditorDocument *self,
+ GtkWidget *widget)
+{
+ g_autoptr(GPropertyAction) language = NULL;
+ g_autoptr(GSimpleActionGroup) group = NULL;
+
+ g_return_if_fail (EDITOR_IS_DOCUMENT (self));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ group = g_simple_action_group_new ();
+ language = g_property_action_new ("language", self->spell_adapter, "language");
+ g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (language));
+
+ gtk_widget_insert_action_group (widget, "spelling", G_ACTION_GROUP (group));
+}
diff --git a/src/editor-source-view.c b/src/editor-source-view.c
index 8687ac2..c7e83de 100644
--- a/src/editor-source-view.c
+++ b/src/editor-source-view.c
@@ -20,6 +20,7 @@
#include "config.h"
+#include "editor-document-private.h"
#include "editor-source-view.h"
#include "editor-joined-menu-private.h"
#include "editor-spell-menu.h"
@@ -97,6 +98,21 @@ tweak_gutter_spacing (GtkSourceView *view)
}
}
+static void
+on_notify_buffer_cb (EditorSourceView *self,
+ GParamSpec *pspec,
+ gpointer unused)
+{
+ GtkTextBuffer *buffer;
+
+ g_assert (EDITOR_IS_SOURCE_VIEW (self));
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
+
+ if (EDITOR_IS_DOCUMENT (buffer))
+ _editor_document_attach_actions (EDITOR_DOCUMENT (buffer), GTK_WIDGET (self));
+}
+
static void
editor_source_view_class_init (EditorSourceViewClass *klass)
{
@@ -110,6 +126,11 @@ editor_source_view_init (EditorSourceView *self)
GtkEventController *controller;
GMenuModel *extra_menu;
+ g_signal_connect (self,
+ "notify::buffer",
+ G_CALLBACK (on_notify_buffer_cb),
+ NULL);
+
controller = gtk_event_controller_key_new ();
g_signal_connect (controller,
"key-pressed",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]