[gtksourceview] languagemanager: add append/prepend_search_path()



commit 0d2e771f808bdbdd5eec9a68d8f0202e46058171
Author: Martin Lund <martin lund keep-it-simple com>
Date:   Fri Jan 28 19:07:48 2022 +0100

    languagemanager: add append/prepend_search_path()

 gtksourceview/gtksourcelanguagemanager.c | 73 ++++++++++++++++++++++++++++++++
 gtksourceview/gtksourcelanguagemanager.h |  6 +++
 2 files changed, 79 insertions(+)
---
diff --git a/gtksourceview/gtksourcelanguagemanager.c b/gtksourceview/gtksourcelanguagemanager.c
index ebd0e5ad..f802401c 100644
--- a/gtksourceview/gtksourcelanguagemanager.c
+++ b/gtksourceview/gtksourcelanguagemanager.c
@@ -267,6 +267,79 @@ gtk_source_language_manager_set_search_path (GtkSourceLanguageManager *lm,
        notify_search_path (lm);
 }
 
+/**
+ * gtk_source_language_manager_append_search_path:
+ * @manager: a #GtkSourceLanguageManager.
+ * @path: a directory or a filename.
+ *
+ * Appends @path to the list of directories where the @manager looks for
+ * language files.
+ *
+ * See [method@LanguageManager.set_search_path] for details.
+ */
+void
+gtk_source_language_manager_append_search_path (GtkSourceLanguageManager *lm,
+                                                const gchar              *path)
+{
+       guint len = 0;
+
+       g_return_if_fail (GTK_SOURCE_IS_LANGUAGE_MANAGER (lm));
+       g_return_if_fail (path != NULL);
+
+       if (lm->lang_dirs == NULL)
+               lm->lang_dirs = _gtk_source_utils_get_default_dirs (LANGUAGE_DIR);
+
+       g_return_if_fail (lm->lang_dirs != NULL);
+
+       len = g_strv_length (lm->lang_dirs);
+
+       lm->lang_dirs = g_renew (gchar *,
+                                       lm->lang_dirs,
+                                       len + 2); /* old path + new entry + NULL */
+
+       lm->lang_dirs[len] = g_strdup (path);
+       lm->lang_dirs[len + 1] = NULL;
+
+       notify_search_path (lm);
+}
+
+/**
+ * gtk_source_language_manager_prepend_search_path:
+ * @manager: a #GtkSourceLanguageManager.
+ * @path: a directory or a filename.
+ *
+ * Prepends @path to the list of directories where the @manager looks
+ * for language files.
+ *
+ * See [method@LanguageManager.set_search_path] for details.
+ */
+void
+gtk_source_language_manager_prepend_search_path (GtkSourceLanguageManager *lm,
+                                                 const gchar              *path)
+{
+       guint len = 0;
+       gchar **new_lang_dirs;
+
+       g_return_if_fail (GTK_SOURCE_IS_LANGUAGE_MANAGER (lm));
+       g_return_if_fail (path != NULL);
+
+       if (lm->lang_dirs == NULL)
+               lm->lang_dirs = _gtk_source_utils_get_default_dirs (LANGUAGE_DIR);
+
+       g_return_if_fail (lm->lang_dirs != NULL);
+
+       len = g_strv_length (lm->lang_dirs);
+
+       new_lang_dirs = g_new (gchar *, len + 2);
+       new_lang_dirs[0] = g_strdup (path);
+       memcpy (new_lang_dirs + 1, lm->lang_dirs, (len + 1) * sizeof (gchar*));
+
+       g_free (lm->lang_dirs);
+       lm->lang_dirs = new_lang_dirs;
+
+       notify_search_path (lm);
+}
+
 /**
  * gtk_source_language_manager_get_search_path:
  * @lm: a #GtkSourceLanguageManager.
diff --git a/gtksourceview/gtksourcelanguagemanager.h b/gtksourceview/gtksourcelanguagemanager.h
index b3c7782c..e2cfbff0 100644
--- a/gtksourceview/gtksourcelanguagemanager.h
+++ b/gtksourceview/gtksourcelanguagemanager.h
@@ -44,6 +44,12 @@ GTK_SOURCE_AVAILABLE_IN_ALL
 void                      gtk_source_language_manager_set_search_path  (GtkSourceLanguageManager *lm,
                                                                         const gchar * const      *dirs);
 GTK_SOURCE_AVAILABLE_IN_ALL
+void                      gtk_source_language_manager_append_search_path  (GtkSourceLanguageManager *lm,
+                                                                           const gchar              *path);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void                      gtk_source_language_manager_prepend_search_path (GtkSourceLanguageManager *lm,
+                                                                           const gchar              *path);
+GTK_SOURCE_AVAILABLE_IN_ALL
 const gchar * const      *gtk_source_language_manager_get_language_ids (GtkSourceLanguageManager  *lm);
 GTK_SOURCE_AVAILABLE_IN_ALL
 GtkSourceLanguage        *gtk_source_language_manager_get_language     (GtkSourceLanguageManager  *lm,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]