[gnome-text-editor] page: export language name as a property
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] page: export language name as a property
- Date: Tue, 30 Nov 2021 19:07:20 +0000 (UTC)
commit 8ffc0b43475fc9173dc1f58852c646d89dbe495b
Author: Christian Hergert <chergert redhat com>
Date: Tue Nov 30 11:05:34 2021 -0800
page: export language name as a property
This makes it easier to track to update UI as we can just notify on the
property.
src/editor-page.c | 31 +++++++++++++++++++++++++++++++
src/editor-page.h | 1 +
2 files changed, 32 insertions(+)
---
diff --git a/src/editor-page.c b/src/editor-page.c
index 64fb1e6..9a0f1bc 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -39,6 +39,7 @@ enum {
PROP_CAN_SAVE,
PROP_DOCUMENT,
PROP_IS_MODIFIED,
+ PROP_LANGUAGE_NAME,
PROP_POSITION_LABEL,
PROP_SETTINGS,
PROP_SUBTITLE,
@@ -154,6 +155,8 @@ editor_page_document_notify_language_cb (EditorPage *self,
settings = editor_page_settings_new_for_document (document);
editor_page_set_settings (self, settings);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_LANGUAGE_NAME]);
}
static void
@@ -465,6 +468,23 @@ font_scale_changed_cb (EditorPage *self,
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM_LABEL]);
}
+const char *
+editor_page_get_language_name (EditorPage *self)
+{
+ GtkSourceLanguage *language;
+ EditorDocument *document;
+
+ g_return_val_if_fail (EDITOR_IS_PAGE (self), NULL);
+
+ document = editor_page_get_document (self);
+ language = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (document));
+
+ if (language != NULL)
+ return gtk_source_language_get_name (language);
+
+ return NULL;
+}
+
static void
editor_page_dispose (GObject *object)
{
@@ -516,6 +536,10 @@ editor_page_get_property (GObject *object,
g_value_set_boolean (value, editor_page_get_is_modified (self));
break;
+ case PROP_LANGUAGE_NAME:
+ g_value_set_string (value, editor_page_get_language_name (self));
+ break;
+
case PROP_TITLE:
g_value_take_string (value, editor_page_dup_title (self));
break;
@@ -593,6 +617,13 @@ editor_page_class_init (EditorPageClass *klass)
EDITOR_TYPE_DOCUMENT,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+ properties [PROP_LANGUAGE_NAME] =
+ g_param_spec_string ("language-name",
+ "Language Name",
+ "Language Name",
+ NULL,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
properties [PROP_TITLE] =
g_param_spec_string ("title",
"Title",
diff --git a/src/editor-page.h b/src/editor-page.h
index c3b8c28..52912a2 100644
--- a/src/editor-page.h
+++ b/src/editor-page.h
@@ -43,5 +43,6 @@ gchar *editor_page_dup_position_label (EditorPage *self);
void editor_page_get_visual_position (EditorPage *self,
guint *line,
guint *column);
+const char *editor_page_get_language_name (EditorPage *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]