[gnome-builder/wip/gtk4-port: 1085/1774] libide/code: add IdeLocation:title read-only property
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1085/1774] libide/code: add IdeLocation:title read-only property
- Date: Mon, 11 Jul 2022 22:31:34 +0000 (UTC)
commit de3f30cf6293b5217ca9021e06492272b1c58985
Author: Christian Hergert <chergert redhat com>
Date: Fri May 20 14:36:39 2022 -0700
libide/code: add IdeLocation:title read-only property
src/libide/code/ide-location.c | 45 ++++++++++++++++++++++++++++++++++++++++++
src/libide/code/ide-location.h | 2 ++
2 files changed, 47 insertions(+)
---
diff --git a/src/libide/code/ide-location.c b/src/libide/code/ide-location.c
index 1903399de..4de324d1a 100644
--- a/src/libide/code/ide-location.c
+++ b/src/libide/code/ide-location.c
@@ -38,6 +38,7 @@ enum {
PROP_LINE,
PROP_LINE_OFFSET,
PROP_OFFSET,
+ PROP_TITLE,
N_PROPS
};
@@ -126,6 +127,10 @@ ide_location_get_property (GObject *object,
g_value_set_int (value, ide_location_get_offset (self));
break;
+ case PROP_TITLE:
+ g_value_take_string (value, ide_location_dup_title (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -171,6 +176,13 @@ ide_location_class_init (IdeLocationClass *klass)
object_class->get_property = ide_location_get_property;
object_class->set_property = ide_location_set_property;
+ properties [PROP_TITLE] =
+ g_param_spec_string ("title",
+ "Title",
+ "The title of the location",
+ NULL,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
properties [PROP_FILE] =
g_param_spec_object ("file",
"File",
@@ -528,3 +540,36 @@ ide_location_equal (IdeLocation *a,
a_priv->line_offset == b_priv->line_offset &&
a_priv->offset == b_priv->offset;
}
+
+/**
+ * ide_location_dup_title:
+ * @self: a #IdeLocation
+ *
+ * Gets a title string for the location, usually in the form of
+ * shortname:line:column
+ *
+ * Returns: (transfer full) (nullable): A new string containing the
+ * something suitable to be used as a title for diagnostics.
+ */
+char *
+ide_location_dup_title (IdeLocation *self)
+{
+ IdeLocationPrivate *priv = ide_location_get_instance_private (self);
+ g_autofree char *name = NULL;
+
+ g_return_val_if_fail (IDE_IS_LOCATION (self), NULL);
+
+ if (priv->file == NULL)
+ return NULL;
+
+ if (!(name = g_file_get_basename (priv->file)))
+ return NULL;
+
+ if (priv->line >= 0 && priv->line_offset >= 0)
+ return g_strdup_printf ("%s:%d:%d", name, priv->line, priv->line_offset);
+
+ if (priv->line >= 0)
+ return g_strdup_printf ("%s:%d", name, priv->line);
+
+ return g_steal_pointer (&name);
+}
diff --git a/src/libide/code/ide-location.h b/src/libide/code/ide-location.h
index c462d3bae..655cb2652 100644
--- a/src/libide/code/ide-location.h
+++ b/src/libide/code/ide-location.h
@@ -74,5 +74,7 @@ guint ide_location_hash (IdeLocation *self);
IDE_AVAILABLE_IN_ALL
gboolean ide_location_equal (IdeLocation *a,
IdeLocation *b);
+IDE_AVAILABLE_IN_ALL
+char *ide_location_dup_title (IdeLocation *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]