static void gtk_source_mark_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GtkSourceMarkPrivate *priv; g_return_if_fail (GTK_IS_SOURCE_MARK (object)); priv = GTK_SOURCE_MARK (object)->priv; switch (prop_id) { case PROP_CATEGORY: g_return_if_fail (g_value_get_string (value) != NULL); g_free (priv->category); priv->category = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } }
static GtkSourceMark * get_bookmark_and_iter (GtkSourceBuffer *buffer, GtkTextIter *iter, GtkTextIter *start) { GSList *marks; GtkSourceMark *ret = NULL; if (!iter) { gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), start, gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer))); } else { *start = *iter; } gtk_text_iter_set_line_offset (start, 0); marks = gtk_source_buffer_get_source_marks_at_iter (buffer, start, BOOKMARK_CATEGORY); if (marks != NULL) { ret = GTK_SOURCE_MARK (marks->data); } g_slist_free (marks); return ret; }
static void gtk_source_mark_finalize (GObject *object) { GtkSourceMark *mark = GTK_SOURCE_MARK (object); g_free (mark->priv->category); G_OBJECT_CLASS (gtk_source_mark_parent_class)->finalize (object); }
static gint sort_marks_by_priority (gconstpointer m1, gconstpointer m2, gpointer data) { GtkSourceMark *mark1 = GTK_SOURCE_MARK (m1); GtkSourceMark *mark2 = GTK_SOURCE_MARK (m2); GtkSourceView *view = GTK_SOURCE_VIEW (data); GtkTextIter iter1, iter2; gint line1; gint line2; gtk_text_buffer_get_iter_at_mark (gtk_text_mark_get_buffer (GTK_TEXT_MARK (mark1)), &iter1, GTK_TEXT_MARK (mark1)); gtk_text_buffer_get_iter_at_mark (gtk_text_mark_get_buffer (GTK_TEXT_MARK (mark2)), &iter2, GTK_TEXT_MARK (mark2)); line1 = gtk_text_iter_get_line (&iter1); line2 = gtk_text_iter_get_line (&iter2); if (line1 == line2) { gint priority1 = -1; gint priority2 = -1; gtk_source_view_get_mark_attributes (view, gtk_source_mark_get_category (mark1), &priority1); gtk_source_view_get_mark_attributes (view, gtk_source_mark_get_category (mark2), &priority2); return priority1 - priority2; } else { return line2 - line1; } }
/** * gtk_source_mark_new: * @name: Name of the #GtkSourceMark, can be NULL when not using a name * @category: is used to classify marks according to common characteristics * (e.g. all the marks representing a bookmark could belong to the "bookmark" * category, or all the marks representing a compilation error could belong to * "error" category). * * Creates a text mark. Add it to a buffer using gtk_text_buffer_add_mark(). * If name is NULL, the mark is anonymous; otherwise, the mark can be retrieved * by name using gtk_text_buffer_get_mark(). * Normally marks are created using the utility function * gtk_source_buffer_create_mark(). * * Returns: a new #GtkSourceMark that can be added using gtk_text_buffer_add_mark() * * Since: 2.2 */ GtkSourceMark * gtk_source_mark_new (const gchar *name, const gchar *category) { g_return_val_if_fail (category != NULL, NULL); return GTK_SOURCE_MARK (g_object_new (GTK_TYPE_SOURCE_MARK, "category", category, "name", name, "left-gravity", TRUE, NULL)); }
static void gtk_source_mark_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GtkSourceMark *mark; g_return_if_fail (GTK_IS_SOURCE_MARK (object)); mark = GTK_SOURCE_MARK (object); switch (prop_id) { case PROP_CATEGORY: g_value_set_string (value, gtk_source_mark_get_category (mark)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } }